Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

Conflicts:
	python_apps/pypo/pypopush.py
This commit is contained in:
Martin Konecny 2012-03-28 22:49:57 -04:00
commit 29afb6e191
29 changed files with 496 additions and 266 deletions

View file

@ -87,10 +87,10 @@ class PypoFetch(Thread):
self.update_liquidsoap_transition_fade(m['transition_fade'])
elif command == 'switch_source':
self.logger.info("switch_on_source show command received...")
self.switch_source(m['sourcename'], m['status'])
self.switch_source(self.logger, self.telnet_lock, m['sourcename'], m['status'])
elif command == 'disconnect_source':
self.logger.info("disconnect_on_source show command received...")
self.disconnect_source(m['sourcename'])
self.disconnect_source(self.logger, self.telnet.lock, m['sourcename'])
except Exception, e:
import traceback
top = traceback.format_exc()
@ -98,27 +98,29 @@ class PypoFetch(Thread):
self.logger.error("traceback: %s", top)
self.logger.error("Exception in handling Message Handler message: %s", e)
def disconnect_source(self,sourcename):
self.logger.debug('Disconnecting source: %s', sourcename)
@staticmethod
def disconnect_source(logger, lock, sourcename):
logger.debug('Disconnecting source: %s', sourcename)
command = ""
if(sourcename == "master_dj"):
command += "master_harbor.kick\n"
elif(sourcename == "live_dj"):
command += "live_dj_harbor.kick\n"
self.telnet_lock.acquire()
lock.acquire()
try:
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
tn.write(command)
tn.write('exit\n')
tn.read_all()
except Exception, e:
self.logger.error(str(e))
logger.error(str(e))
finally:
self.telnet_lock.release()
def switch_source(self, sourcename, status):
self.logger.debug('Switching source: %s to "%s" status', sourcename, status)
lock.release()
@staticmethod
def switch_source(logger, lock, sourcename, status):
logger.debug('Switching source: %s to "%s" status', sourcename, status)
command = "streams."
if(sourcename == "master_dj"):
command += "master_dj_"
@ -132,16 +134,16 @@ class PypoFetch(Thread):
else:
command += "stop\n"
self.telnet_lock.acquire()
lock.acquire()
try:
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
tn.write(command)
tn.write('exit\n')
tn.read_all()
except Exception, e:
self.logger.error(str(e))
logger.error(str(e))
finally:
self.telnet_lock.release()
lock.release()
"""
grabs some information that are needed to be set on bootstrap time
@ -156,7 +158,7 @@ class PypoFetch(Thread):
else:
self.logger.debug('info:%s',info)
for k, v in info['switch_status'].iteritems():
self.switch_source(k, v)
self.switch_source(self.logger, self.telnet_lock, k, v)
self.update_liquidsoap_stream_format(info['stream_label'])
self.update_liquidsoap_station_name(info['station_name'])
self.update_liquidsoap_transition_fade(info['transition_fade'])
@ -374,6 +376,7 @@ class PypoFetch(Thread):
def process_schedule(self, schedule_data):
self.logger.debug(schedule_data)
media = schedule_data["media"]
media_filtered = {}
# Download all the media and put playlists in liquidsoap "annotate" format
try:
@ -389,13 +392,14 @@ class PypoFetch(Thread):
for key in media:
media_item = media[key]
fileExt = os.path.splitext(media_item['uri'])[1]
dst = os.path.join(download_dir, media_item['id']+fileExt)
media_item['dst'] = dst
if(media_item['type'] == 'file'):
fileExt = os.path.splitext(media_item['uri'])[1]
dst = os.path.join(download_dir, media_item['id']+fileExt)
media_item['dst'] = dst
media_filtered[key] = media_item
self.media_prepare_queue.put(copy.copy(media))
self.prepare_media(media)
self.media_prepare_queue.put(copy.copy(media_filtered))
self.prepare_media(media_filtered)
except Exception, e: self.logger.error("%s", e)
# Send the data to pypo-push

View file

@ -9,6 +9,7 @@ import telnetlib
import calendar
import json
import math
from pypofetch import PypoFetch
from Queue import Empty
@ -204,7 +205,9 @@ class PypoPush(Thread):
for mkey in sorted_keys:
media_item = media_schedule[mkey]
if len(current_chain) == 0:
if media_item['type'] == "event":
chains.append([media_item])
elif len(current_chain) == 0:
current_chain.append(media_item)
elif media_item['start'] == current_chain[-1]['end']:
current_chain.append(media_item)
@ -240,7 +243,6 @@ class PypoPush(Thread):
tnow = datetime.utcnow()
current_chain = []
for chain in chains:
iteration = 0
for link in chain:
@ -284,7 +286,13 @@ class PypoPush(Thread):
try:
for media_item in media_item_chain:
self.telnet_to_liquidsoap(media_item)
if media_item['type'] == "file":
self.telnet_to_liquidsoap(media_item)
elif media_item['type'] == "event":
if media_item['event_type'] == "kick_out":
PypoFetch.disconnect_source(self.logger, self.telnet_lock, "live_dj")
elif media_item['event_type'] == "switch_off":
PypoFetch.switch_source(self.logger, self.telnet_lock, "live_dj", "off")
except Exception, e:
self.logger.error('Pypo Push Exception: %s', e)