Commit 2799ae80 authored by fred's avatar fred

rename file to have date/artist/title

parent 49517623
......@@ -174,14 +174,23 @@ class UploadTracksView(FormView):
return self.form_invalid(form)
for f in tracks:
metadata = metadatas[f.name]
artist_name = metadata.get('artist')[0]
track_title = metadata.get('title')[0]
monthdir = datetime.datetime.today().strftime('%Y-%m')
filepath = '%s/%s' % (monthdir, f.name)
filepath = '%s/%s - %s - %s%s' % (monthdir,
datetime.datetime.today().strftime('%y%m%d'),
artist_name[:50].replace('/', ' ').strip(),
track_title[:80].replace('/', ' ').strip(),
os.path.splitext(f.name)[-1])
default_storage.save(os.path.join('nonstop', 'tracks', filepath), content=f)
nonstop_file = NonstopFile()
nonstop_file.set_track_filepath(filepath)
metadata = metadatas[f.name]
artist, created = Artist.objects.get_or_create(name=metadata.get('artist')[0])
track, created = Track.objects.get_or_create(title=metadata.get('title')[0], artist=artist)
artist, created = Artist.objects.get_or_create(name=artist_name)
track, created = Track.objects.get_or_create(title=track_title, artist=artist)
nonstop_file.track = track
nonstop_file.save()
if request.POST.get('nonstop_zone'):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment