fix tracer in streamer

This commit is contained in:
bkfox 2017-08-30 15:08:42 +02:00
parent 66bee810eb
commit 4525e4952b

View File

@ -64,7 +64,7 @@ class Monitor:
def get_last_log(self, *args, **kwargs): def get_last_log(self, *args, **kwargs):
return Log.objects.station(self.station, *args, **kwargs) \ return Log.objects.station(self.station, *args, **kwargs) \
.select_related('diffusion', 'sound') \ .select_related('diffusion', 'sound') \
.order_by('date').last() .order_by('pk').last()
@property @property
def last_log(self): def last_log(self):
@ -137,23 +137,29 @@ class Monitor:
print('no source / no sound', current_sound, current_source) print('no source / no sound', current_sound, current_source)
return return
log = self.get_last_log(models.Q(diffusion__isnull = False) | log = self.get_last_log(sound__isnull = False)
models.Q(sound__isnull = False))
on_air = None
if log: if log:
# check if sound on air changed compared to logged one # we always check difference in sound
is_diff = log.source != current_source.id or \
(log.sound and log.sound.path != current_sound)
# check if sound 'on air' time has changed compared to logged one.
# in some cases, there can be a gap between liquidsoap on_air and
# log's date; to avoid duplicate we allow a difference of 5 seconds
if not is_diff:
try: try:
# FIXME: liquidsoap does not have timezone # FIXME: liquidsoap does not have timezone
on_air = current_source.metadata and \ on_air = current_source.metadata and \
current_source.metadata.get('on_air') current_source.metadata.get('on_air')
on_air = tz.datetime.strptime(on_air, "%Y/%m/%d %H:%M:%S") on_air = tz.datetime.strptime(on_air, "%Y/%m/%d %H:%M:%S")
on_air = local_tz.localize(on_air) on_air = local_tz.localize(on_air)
on_air = on_air.astimezone(pytz.utc)
is_diff = log.date != on_air is_diff = is_diff or ((log.date - on_air).total_seconds() > 5)
except: except:
on_air = None pass
is_diff = log.source != current_source.id or \
(log.sound and log.sound.path != current_sound)
else: else:
# no log: sound is different # no log: sound is different
is_diff = True is_diff = True