use liquidsoap's metadata.on_air to detect sound change

This commit is contained in:
bkfox 2017-07-24 19:23:18 +02:00
parent 97e5945b7d
commit 280864768b
2 changed files with 23 additions and 4 deletions

View File

@ -101,6 +101,7 @@ class Streamer:
if source.rid == rid), if source.rid == rid),
self.current_source self.current_source
) )
self.current_source.metadata = data
def push(self, config = True): def push(self, config = True):
""" """
@ -233,6 +234,11 @@ class Source:
""" """
Connector to Liquidsoap server Connector to Liquidsoap server
""" """
metadata = None
"""
Dict of file's metadata given by Liquidsoap. Set by Stream when
fetch()ing
"""
@property @property
def id(self): def id(self):
@ -344,6 +350,8 @@ class Source:
self.rid = data.get('rid') self.rid = data.get('rid')
self.current_sound = data.get('initial_uri') self.current_sound = data.get('initial_uri')
# TODO: get metadata
def push(self): def push(self):
""" """
Update data relative to the source on the external program. Update data relative to the source on the external program.

View File

@ -136,9 +136,19 @@ class Monitor:
log = self.get_last_log(models.Q(diffusion__isnull = False) | log = self.get_last_log(models.Q(diffusion__isnull = False) |
models.Q(sound__isnull = False)) models.Q(sound__isnull = False))
# sound on air changed # check if sound on air changed
if log.source != current_source.id or \ try:
(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 = 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() sound = Sound.objects.filter(path = current_sound).first()
# find an eventual diff # find an eventual diff
@ -149,11 +159,12 @@ class Monitor:
if archives.filter(pk = sound.pk).exists(): if archives.filter(pk = sound.pk).exists():
diff = last_diff.diffusion diff = last_diff.diffusion
# log sound on air # log sound on air
log = self.log( log = self.log(
type = Log.Type.on_air, type = Log.Type.on_air,
source = current_source.id, source = current_source.id,
date = tz.now(), date = on_air or tz.now(),
sound = sound, sound = sound,
diffusion = diff, diffusion = diff,
# if sound is removed, we keep sound path info # if sound is removed, we keep sound path info