Commit 7603eaa5 authored by fred's avatar fred

fill nonstop zone from filepath

parent 55db83d6
......@@ -2,17 +2,37 @@ import mutagen
import os
from import BaseCommand, CommandError
from django.utils.text import slugify
from ...models import NonstopFile, Track, Artist
from emissions.models import Nonstop
LOCAL_BASE_PATH = '/media/nonstop/'
REMOTE_BASE_PATH = '/srv/soma/nonstop/'
tranche_slug_mapping = {
'Acouphene': 'acouphene',
'Biodiversite': 'biodiversite',
'Heure_de_pointe': 'l-heure-de-pointe',
'Hop_Bop_and_co': 'hop-bop-co',
'la_panique': 'la-panique',
'Mange_Disque': 'le-mange-disque',
'Matins_tranquilles': 'matin-tranquille',
'Reveries': 'reveries',
'Up_Beat_Tempo': 'up-beat-tempo'
class Command(BaseCommand):
def handle(self, verbosity, **kwargs):
self.verbose = (int(verbosity) > 1)
kwargs = {'track__isnull': True}
#kwargs = {}
for tranche_key, tranche_value in tranche_slug_mapping.items():
tranche_slug_mapping[tranche_key] = Nonstop.objects.get(slug=tranche_value)
except Nonstop.DoesNotExist:
for nonstopfile in NonstopFile.objects.filter(**kwargs):
filepath = nonstopfile.filepath.replace(REMOTE_BASE_PATH, LOCAL_BASE_PATH)
if self.verbose:
......@@ -31,6 +51,12 @@ class Command(BaseCommand):
artist, created = Artist.objects.get_or_create(name=metadata.get('artist')[0])
track, created = Track.objects.get_or_create(title=metadata.get('title')[0],
if '/Tranches/' in filepath:
tranche_name = filepath[filepath.find('Tranches/'):].split('/')[1]
track.nonstop_zones = [tranche_slug_mapping[tranche_name]]
except KeyError:
if ' FR' in filepath:
track.language = 'fr'
track.cfwb = (' CFWB' in filepath)
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