forked from rc/aircox
fix tracer in streamer
This commit is contained in:
parent
66bee810eb
commit
4525e4952b
|
@ -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
|
||||||
try:
|
is_diff = log.source != current_source.id or \
|
||||||
# FIXME: liquidsoap does not have timezone
|
(log.sound and log.sound.path != current_sound)
|
||||||
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 = local_tz.localize(on_air)
|
|
||||||
|
|
||||||
is_diff = log.date != on_air
|
# check if sound 'on air' time has changed compared to logged one.
|
||||||
except:
|
# in some cases, there can be a gap between liquidsoap on_air and
|
||||||
on_air = None
|
# log's date; to avoid duplicate we allow a difference of 5 seconds
|
||||||
is_diff = log.source != current_source.id or \
|
if not is_diff:
|
||||||
(log.sound and log.sound.path != current_sound)
|
try:
|
||||||
|
# FIXME: liquidsoap does not have timezone
|
||||||
|
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 = local_tz.localize(on_air)
|
||||||
|
on_air = on_air.astimezone(pytz.utc)
|
||||||
|
|
||||||
|
is_diff = is_diff or ((log.date - on_air).total_seconds() > 5)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
# no log: sound is different
|
# no log: sound is different
|
||||||
is_diff = True
|
is_diff = True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user