Merge branch 'master' of dev.sourcefabric.org:airtime
This commit is contained in:
commit
4dba722272
21 changed files with 283 additions and 84 deletions
|
@ -44,6 +44,10 @@ try:
|
|||
# load config file
|
||||
try:
|
||||
config = ConfigObj(PATH_INI_FILE)
|
||||
config['rabbitmq_user'] = os.environ['RABBITMQ_USER']
|
||||
config['rabbitmq_password'] = os.environ['RABBITMQ_PASSWORD']
|
||||
config['rabbitmq_vhost'] = os.environ['RABBITMQ_VHOST']
|
||||
config.write()
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit(1)
|
||||
|
|
|
@ -10,7 +10,11 @@ ls_param="/usr/lib/airtime/pypo/bin/liquidsoap_scripts/ls_script.liq"
|
|||
|
||||
export PYTHONPATH=${api_client_path}
|
||||
|
||||
cd /usr/lib/airtime/pypo/bin/liquidsoap_scripts
|
||||
SCRIPT=`readlink -f $0`
|
||||
# Absolute directory this script is in
|
||||
SCRIPTPATH=`dirname $SCRIPT`
|
||||
|
||||
cd $SCRIPTPATH/liquidsoap_scripts
|
||||
python generate_liquidsoap_cfg.py
|
||||
|
||||
exec ${ls_path} ${ls_param} 2>&1
|
||||
|
|
|
@ -81,6 +81,10 @@ try:
|
|||
# load config file
|
||||
try:
|
||||
config = ConfigObj(PATH_INI_FILE)
|
||||
config['rabbitmq_user'] = os.environ['RABBITMQ_USER']
|
||||
config['rabbitmq_password'] = os.environ['RABBITMQ_PASSWORD']
|
||||
config['rabbitmq_vhost'] = os.environ['RABBITMQ_VHOST']
|
||||
config.write()
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit(1)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import sys
|
||||
import time
|
||||
from api_clients.api_client import AirtimeApiClient
|
||||
|
||||
def generate_liquidsoap_config(ss):
|
||||
|
@ -26,10 +27,19 @@ def generate_liquidsoap_config(ss):
|
|||
|
||||
logging.basicConfig(format='%(message)s')
|
||||
ac = AirtimeApiClient(logging.getLogger())
|
||||
try:
|
||||
ss = ac.get_stream_setting()
|
||||
generate_liquidsoap_config(ss)
|
||||
except Exception, e:
|
||||
logging.error(str(e))
|
||||
print "Unable to connect to the Airtime server."
|
||||
sys.exit(1)
|
||||
attempts = 0
|
||||
max_attempts = 5
|
||||
|
||||
while True:
|
||||
try:
|
||||
ss = ac.get_stream_setting()
|
||||
generate_liquidsoap_config(ss)
|
||||
break
|
||||
except Exception, e:
|
||||
if attempts == max_attempts:
|
||||
print "Unable to connect to the Airtime server."
|
||||
logging.error(str(e))
|
||||
sys.exit(1)
|
||||
else:
|
||||
time.sleep(3)
|
||||
attempts += 1
|
||||
|
|
|
@ -432,6 +432,7 @@ class PypoFetch(Thread):
|
|||
for key in media:
|
||||
media_item = media[key]
|
||||
if (media_item['type'] == 'file'):
|
||||
self.sanity_check_media_item(media_item)
|
||||
fileExt = os.path.splitext(media_item['uri'])[1]
|
||||
dst = os.path.join(download_dir, unicode(media_item['id']) + fileExt)
|
||||
media_item['dst'] = dst
|
||||
|
@ -455,6 +456,20 @@ class PypoFetch(Thread):
|
|||
try: self.cache_cleanup(media)
|
||||
except Exception, e: self.logger.error("%s", e)
|
||||
|
||||
#do basic validation of file parameters. Useful for debugging
|
||||
#purposes
|
||||
def sanity_check_media_item(self, media_item):
|
||||
start = datetime.strptime(media_item['start'], "%Y-%m-%d-%H-%M-%S")
|
||||
end = datetime.strptime(media_item['end'], "%Y-%m-%d-%H-%M-%S")
|
||||
|
||||
length1 = (end - start).total_seconds()
|
||||
length2 = media_item['cue_out'] - media_item['cue_in']
|
||||
|
||||
if abs(length2 - length1) > 1:
|
||||
self.logger.error("end - start length: %s", length1)
|
||||
self.logger.error("cue_out - cue_in length: %s", length2)
|
||||
self.logger.error("Two lengths are not equal!!!")
|
||||
|
||||
def is_file_opened(self, path):
|
||||
#Capture stderr to avoid polluting py-interpreter.log
|
||||
proc = Popen(["lsof", path], stdout=PIPE, stderr=PIPE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue