fix minor errors

This commit is contained in:
bkfox 2015-11-23 15:05:37 +01:00
parent 201353367d
commit 4291eea67e
4 changed files with 30 additions and 14 deletions

View File

@ -41,7 +41,7 @@ class Connector:
self.__socket.connect(self.address) self.__socket.connect(self.address)
self.__available = True self.__available = True
except: except:
print('can not connect to liquidsoap socket {}'.format(self.address)) # print('can not connect to liquidsoap socket {}'.format(self.address))
self.__available = False self.__available = False
return -1 return -1
@ -167,7 +167,7 @@ class Source:
@property @property
def current_sound (self): def current_sound (self):
self.update() self.update()
self.metadata.get('initial_uri') return self.metadata.get('initial_uri') if self.metadata else {}
def stream_info (self): def stream_info (self):
""" """
@ -308,15 +308,14 @@ class Dealer (Source):
# run the diff # run the diff
if self.playlist == diff.playlist and diff.date <= now: if self.playlist == diff.playlist and diff.date <= now:
self.on = True self.on = True
for source in self.controller.source: for source in self.controller.streams.values():
source.skip() source.skip()
self.controller.log( self.controller.log(
source = self.id, source = self.id,
diffusion = diff, diffusion = diff,
date = now, date = now,
comment = 'trigger the scheduled diffusion to liquidsoap; ' comment = 'trigger the scheduled diffusion to liquidsoap; '
'skip all other sources', 'skip all other streams',
) )
@ -325,7 +324,7 @@ class Controller:
station = None # the related station station = None # the related station
master = None # master source (station's source) master = None # master source (station's source)
dealer = None # dealer source dealer = None # dealer source
streams = None # streams sources streams = None # streams streams
@property @property
def on_air (self): def on_air (self):
@ -379,7 +378,7 @@ class Controller:
def update_all (self): def update_all (self):
""" """
Fetch and update all sources metadata. Fetch and update all streams metadata.
""" """
self.master.update() self.master.update()
self.dealer.update() self.dealer.update()
@ -389,26 +388,34 @@ class Controller:
def __change_log (self, source): def __change_log (self, source):
last_log = models.Log.objects.filter( last_log = models.Log.objects.filter(
source = source.id, source = source.id,
).prefetch_related('sound').order('-date') ).prefetch_related('sound').order_by('-date')
on_air = source.current_sound on_air = source.current_sound
if on_air == last_log.sound.path: if not on_air:
return
if last_log:
last_log = last_log[0]
if last_log.sound and on_air == last_log.sound.path:
return return
self.log( self.log(
source = source.id, source = source.id,
sound = models.Sound.objects.get(path = on_air), sound = models.Sound.objects.get(path = on_air),
start = tz.make_aware(tz.datetime.now()), date = tz.make_aware(tz.datetime.now()),
comment = 'sound has changed' comment = 'sound has changed'
) )
def monitor (self): def monitor (self):
""" """
Log changes in the sources, and call dealer.monitor. Log changes in the streams, and call dealer.monitor.
""" """
if not self.connector.available and self.connector.open():
return
self.dealer.monitor() self.dealer.monitor()
self.__change_log(self.dealer) self.__change_log(self.dealer)
for source in self.sources: for source in self.streams.values():
self.__change_log(source) self.__change_log(source)

View File

@ -113,6 +113,7 @@ class DiffusionAdmin (admin.ModelAdmin):
return qs.exclude(type = Diffusion.Type['unconfirmed']) return qs.exclude(type = Diffusion.Type['unconfirmed'])
admin.site.register(Log)
admin.site.register(Track) admin.site.register(Track)
admin.site.register(Schedule) admin.site.register(Schedule)

View File

@ -8,6 +8,7 @@ from django.utils.html import strip_tags
from taggit.managers import TaggableManager from taggit.managers import TaggableManager
import aircox_programs.utils as utils
import aircox_programs.settings as settings import aircox_programs.settings as settings
@ -541,7 +542,7 @@ class Diffusion (models.Model):
r = [ sound.duration r = [ sound.duration
for sound in self.sounds.filter(type = Sound.Type['archive']) for sound in self.sounds.filter(type = Sound.Type['archive'])
if sound.duration ] if sound.duration ]
return sum(r) or self.duration return utils.time_sum(r) if r else self.duration
def get_archives (self): def get_archives (self):
""" """

View File

@ -11,7 +11,6 @@ def to_timedelta (time):
seconds = time.second seconds = time.second
) )
def seconds_to_time (seconds): def seconds_to_time (seconds):
""" """
Seconds to datetime.time Seconds to datetime.time
@ -20,4 +19,12 @@ def seconds_to_time (seconds):
hours, minutes = divmod(minutes, 60) hours, minutes = divmod(minutes, 60)
return datetime.time(hour = hours, minute = minutes, second = seconds) return datetime.time(hour = hours, minute = minutes, second = seconds)
def time_sum (times):
"""
Sum up a list of time elements
"""
seconds = sum([ time.hour * 3600 + time.minute * 60 + time.second
for time in times ])
return seconds_to_time(seconds)