From 280864768b94a09ed5f18690f0dd949eba3ce0ac Mon Sep 17 00:00:00 2001 From: bkfox Date: Mon, 24 Jul 2017 19:23:18 +0200 Subject: [PATCH] use liquidsoap's metadata.on_air to detect sound change --- aircox/controllers.py | 8 ++++++++ aircox/management/commands/streamer.py | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/aircox/controllers.py b/aircox/controllers.py index bbda4f3..93ec7e4 100755 --- a/aircox/controllers.py +++ b/aircox/controllers.py @@ -101,6 +101,7 @@ class Streamer: if source.rid == rid), self.current_source ) + self.current_source.metadata = data def push(self, config = True): """ @@ -233,6 +234,11 @@ class Source: """ Connector to Liquidsoap server """ + metadata = None + """ + Dict of file's metadata given by Liquidsoap. Set by Stream when + fetch()ing + """ @property def id(self): @@ -344,6 +350,8 @@ class Source: self.rid = data.get('rid') self.current_sound = data.get('initial_uri') + # TODO: get metadata + def push(self): """ Update data relative to the source on the external program. diff --git a/aircox/management/commands/streamer.py b/aircox/management/commands/streamer.py index dbb4b9c..c7f552a 100755 --- a/aircox/management/commands/streamer.py +++ b/aircox/management/commands/streamer.py @@ -136,9 +136,19 @@ class Monitor: log = self.get_last_log(models.Q(diffusion__isnull = False) | models.Q(sound__isnull = False)) - # sound on air changed - if log.source != current_source.id or \ - (log.sound and log.sound.path != current_sound): + # check if sound on air changed + try: + on_air = current_source.metadata and \ + current_source.metadata.get('on_air') + on_air = tz.datetime.strptime(on_air, "%Y/%m/%d %H:%M:%S") + on_air = tz.make_aware(on_air) + + is_diff = log.date != on_air + except: + is_diff = log.source != current_source.id or \ + (log.sound and log.sound.path != current_sound) + + if is_diff: sound = Sound.objects.filter(path = current_sound).first() # find an eventual diff @@ -149,11 +159,12 @@ class Monitor: if archives.filter(pk = sound.pk).exists(): diff = last_diff.diffusion + # log sound on air log = self.log( type = Log.Type.on_air, source = current_source.id, - date = tz.now(), + date = on_air or tz.now(), sound = sound, diffusion = diff, # if sound is removed, we keep sound path info