CC-2175: Overbooking: Cut off shows when they are done

-fixed
This commit is contained in:
martin 2011-04-14 00:20:19 -04:00
parent 7e6ce1514f
commit 33b24b581c
3 changed files with 37 additions and 31 deletions

View file

@ -101,7 +101,7 @@ class PypoFetch(Thread):
"""
def process_schedule(self, schedule_data, export_source):
logger = logging.getLogger('fetch')
self.schedule = schedule_data["playlists"]
playlists = schedule_data["playlists"]
self.check_matching_timezones(schedule_data["server_timezone"])
@ -121,13 +121,13 @@ class PypoFetch(Thread):
# Download all the media and put playlists in liquidsoap format
try:
playlists = self.prepare_playlists()
liquidsoap_playlists = self.prepare_playlists(playlists)
except Exception, e: logger.error("%s", e)
# Send the data to pypo-push
scheduled_data = dict()
scheduled_data['playlists'] = playlists
scheduled_data['schedule'] = self.schedule
scheduled_data['liquidsoap_playlists'] = liquidsoap_playlists
scheduled_data['schedule'] = playlists
scheduled_data['stream_metadata'] = schedule_data["stream_metadata"]
self.queue.put(scheduled_data)
@ -141,23 +141,22 @@ class PypoFetch(Thread):
and stored in a playlist folder.
file is e.g. 2010-06-23-15-00-00/17_cue_10.132-123.321.mp3
"""
def prepare_playlists(self):
def prepare_playlists(self, playlists):
logger = logging.getLogger('fetch')
schedule = self.schedule
playlists = dict()
liquidsoap_playlists = dict()
# Dont do anything if schedule is empty
if not schedule:
# Dont do anything if playlists is empty
if not playlists:
logger.debug("Schedule is empty.")
return playlists
return liquidsoap_playlists
scheduleKeys = sorted(schedule.iterkeys())
scheduleKeys = sorted(playlists.iterkeys())
try:
for pkey in scheduleKeys:
logger.info("Playlist starting at %s", pkey)
playlist = schedule[pkey]
playlist = playlists[pkey]
# create playlist directory
try:
@ -181,10 +180,10 @@ class PypoFetch(Thread):
elif int(playlist['subtype']) > 0 and int(playlist['subtype']) < 5:
ls_playlist = self.handle_media_file(playlist, pkey)
playlists[pkey] = ls_playlist
liquidsoap_playlists[pkey] = ls_playlist
except Exception, e:
logger.info("%s", e)
return playlists
return liquidsoap_playlists
"""

View file

@ -48,6 +48,10 @@ class PypoPush(Thread):
self.push_ahead = 10
self.push_ahead2 = self.push_ahead -5
#toggle between "stop" and "play". Keeps track of the state of
#liquidsoap
self.liquidsoap_state_play = True
def set_export_source(self, export_source):
self.export_source = export_source
self.cache_dir = config["cache_dir"] + self.export_source + '/'
@ -67,14 +71,13 @@ class PypoPush(Thread):
scheduled_data = self.queue.get()
logger.debug("Received data from pypo-fetch")
self.schedule = scheduled_data['schedule']
self.playlists = scheduled_data['playlists']
self.playlists = scheduled_data['liquidsoap_playlists']
self.stream_metadata = scheduled_data['stream_metadata']
logger.debug('schedule %s' % json.dumps(self.schedule))
logger.debug('playlists %s' % json.dumps(self.playlists))
schedule = self.schedule
playlists = self.playlists
logger.debug('schedule %s' % json.dumps(schedule))
logger.debug('playlists %s' % json.dumps(playlists))
currently_on_air = False
if schedule:
@ -92,9 +95,7 @@ class PypoPush(Thread):
for pkey in schedule:
plstart = pkey[0:19]
start = schedule[pkey]['start']
end = schedule[pkey]['end']
playedFlag = (pkey in playedItems) and playedItems[pkey].get("played", 0)
if plstart == str_tcoming_s or (plstart < str_tcoming_s and plstart > str_tcoming2_s and not playedFlag):
@ -120,21 +121,23 @@ class PypoPush(Thread):
# Call API to update schedule states
logger.debug("Doing callback to server to update 'played' status.")
self.api_client.notify_scheduled_item_start_playing(pkey, schedule)
start = schedule[pkey]['start']
end = schedule[pkey]['end']
if start <= str_tnow_s and str_tnow_s < end:
show_start = schedule[pkey]['show_start']
show_end = schedule[pkey]['show_end']
if show_start <= str_tnow_s and str_tnow_s < show_end:
currently_on_air = True
else:
pass
#logger.debug('Empty schedule')
if not currently_on_air:
if not currently_on_air and self.liquidsoap_state_play:
logger.debug('Notifying Liquidsoap to stop playback.')
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
tn.write('source.skip\n')
tn.write('exit\n')
tn.read_all()
self.liquidsoap_state_play = False
def push_liquidsoap(self, pkey, schedule, playlists):
logger = logging.getLogger('push')
@ -185,6 +188,8 @@ class PypoPush(Thread):
tn.write("exit\n")
logger.debug(tn.read_all())
self.liquidsoap_state_play = True
status = 1
except Exception, e:
logger.error('%s', e)