Commit 657fb216 authored by fred's avatar fred

add management command to create tracks object from nonstop files metadata

parent d116486a
import mutagen
from django.core.management.base import BaseCommand, CommandError
from ...models import NonstopFile, Track, Artist
LOCAL_BASE_PATH = '/media/nonstop/'
REMOTE_BASE_PATH = '/srv/soma/nonstop/'
class Command(BaseCommand):
def handle(self, verbosity, **kwargs):
self.verbose = (int(verbosity) > 1)
kwargs = {'track__isnull': True}
#kwargs = {}
for nonstopfile in NonstopFile.objects.filter(**kwargs):
filepath = nonstopfile.filepath.replace(REMOTE_BASE_PATH, LOCAL_BASE_PATH)
if self.verbose:
print filepath[len(LOCAL_BASE_PATH):]
if 'SPOTS/' in filepath:
continue
metadata = mutagen.File(filepath, easy=True)
if not metadata or not metadata.get('artist') or not metadata.get('title'):
print 'skipping', filepath
continue
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)
if ' FR' in filepath:
track.language = 'fr'
track.cfwb = (' CFWB' in filepath)
track.instru = (' INSTRU' in filepath)
for needle in (' CC', '(CC', 'DOM PUB'):
if needle in filepath:
track.sabam = False
break
nonstopfile.track = track
nonstopfile.save()
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