diff --git a/aircox/management/commands/sounds_monitor.py b/aircox/management/commands/sounds_monitor.py index b63bd64..327a3d4 100755 --- a/aircox/management/commands/sounds_monitor.py +++ b/aircox/management/commands/sounds_monitor.py @@ -47,6 +47,8 @@ class SoundInfo: year = None month = None day = None + hour = None + minute = None n = None duration = None @@ -65,6 +67,7 @@ class SoundInfo: r = re.search('^(?P[0-9]{4})' '(?P[0-9]{2})' '(?P[0-9]{2})' + '(_(?P[0-9]{2})h(?P[0-9]{2}))?' '(_(?P[0-9]+))?' '_?(?P.*)$', file_name) @@ -80,11 +83,14 @@ class SoundInfo: self.year = int(r.get('year')) if 'year' in r else None self.month = int(r.get('month')) if 'month' in r else None self.day = int(r.get('day')) if 'day' in r else None + self.hour = int(r.get('hour')) if 'hour' in r else None + self.minute = int(r.get('minute')) if 'minute' in r else None self.n = r.get('n') return r - def __init__(self, path = ''): + def __init__(self, path = '', sound = None): self.path = path + self.sound = sound def get_duration(self): p = subprocess.Popen(['soxi', '-D', self.path], @@ -161,9 +167,16 @@ class SoundInfo: start__month = self.month, start__day = self.day, ) + + if self.hour is not None: + diffusion = diffusion.filter( + hour = self.hour, + minute = self.minute + ) + + diffusion = diffusion.first() if not diffusion: return - diffusion = diffusion[0] logger.info('diffusion %s mathes to sound -> %s', str(diffusion), self.sound.path) @@ -203,8 +216,9 @@ class MonitorHandler(PatternMatchingEventHandler): si = SoundInfo(event.src_path) self.sound_kwargs['program'] = program si.get_sound(save = True, **self.sound_kwargs) - if si.year != None: + if si.year is not None: si.find_diffusion(program) + si.sound.save(True) def on_deleted(self, event): logger.info('sound deleted: %s', event.src_path) @@ -225,6 +239,12 @@ class MonitorHandler(PatternMatchingEventHandler): sound = sound[0] sound.path = event.dest_path + if not sound.diffusion: + program = Program.get_from_path(event.src_path) + if program: + si = SoundInfo(sound.path, sound = sound) + if si.year is not None: + si.find_diffusion(program) sound.save() @@ -321,7 +341,7 @@ class Command(BaseCommand): si = SoundInfo(path) sound_kwargs['program'] = program si.get_sound(save = True, **sound_kwargs) - si.find_diffusion(program) + si.find_diffusion(program, save = True) si.find_playlist(si.sound) sounds.append(si.sound.pk) diff --git a/aircox/management/commands/streamer.py b/aircox/management/commands/streamer.py index 9b9746a..7bc581a 100755 --- a/aircox/management/commands/streamer.py +++ b/aircox/management/commands/streamer.py @@ -137,11 +137,15 @@ class Monitor: print('no source / no sound', current_sound, current_source) return - log = self.get_last_log(sound__isnull = False) + log = self.get_last_log( + models.Q(sound__isnull = False) | + models.Q(diffusion__isnull = False), + type = Log.Type.on_air + ) on_air = None if log: - # we always check difference in sound + # we always check difference in sound info is_diff = log.source != current_source.id or \ (log.sound and log.sound.path != current_sound) diff --git a/aircox/views.py b/aircox/views.py index bf8fd0b..adf8a5e 100755 --- a/aircox/views.py +++ b/aircox/views.py @@ -44,7 +44,7 @@ def on_air(request): # FIXME: by name??? station = stations.stations.filter(name = station) if not station.count(): - return HttpResponse('') + return HttpResponse('{}') else: station = stations.stations diff --git a/aircox_cms/static/aircox_cms/js/player.js b/aircox_cms/static/aircox_cms/js/player.js index aacba19..4e86c5f 100755 --- a/aircox_cms/static/aircox_cms/js/player.js +++ b/aircox_cms/static/aircox_cms/js/player.js @@ -348,7 +348,7 @@ Player.prototype = { var self = this; window.setTimeout(function() { self.update_on_air(); - }, 60*2000); + }, 60*5000); if(!this.playlist.on_air) return; @@ -360,6 +360,9 @@ Player.prototype = { req.status != 0)) return; + if(!req.responseText.length) + return; + var data = JSON.parse(req.responseText) if(data.type == 'track') data = {