-reorganized/cleaned up python_apps/pypo directory.
This commit is contained in:
parent
f66305e3d3
commit
9cfec2c8ef
|
@ -1,5 +1,5 @@
|
||||||
.*
|
.*
|
||||||
*.pyc
|
*.pyc
|
||||||
/files
|
/files
|
||||||
python_apps/pypo/liquidsoap/liquidsoap
|
python_apps/pypo/liquidsoap_bin/liquidsoap
|
||||||
build/build.properties
|
build/build.properties
|
||||||
|
|
|
@ -70,7 +70,7 @@ class AirtimeIni
|
||||||
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!copy(__DIR__."/../../python_apps/pypo/scripts/liquidsoap.cfg", AirtimeIni::CONF_FILE_LIQUIDSOAP)){
|
if (!copy(__DIR__."/../../python_apps/pypo/liquidsoap_scripts/liquidsoap.cfg", AirtimeIni::CONF_FILE_LIQUIDSOAP)){
|
||||||
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ function CreateIniFiles()
|
||||||
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!copy($AIRTIME_PYTHON_APPS."/pypo/scripts/liquidsoap.cfg", CONF_FILE_LIQUIDSOAP)){
|
if (!copy($AIRTIME_PYTHON_APPS."/pypo/liquidsoap_scripts/liquidsoap.cfg", CONF_FILE_LIQUIDSOAP)){
|
||||||
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ function CreateIniFiles()
|
||||||
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!copy($AIRTIME_PYTHON_APPS."/pypo/scripts/liquidsoap.cfg", CONF_FILE_LIQUIDSOAP)){
|
if (!copy($AIRTIME_PYTHON_APPS."/pypo/liquidsoap_scripts/liquidsoap.cfg", CONF_FILE_LIQUIDSOAP)){
|
||||||
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
ls_user="pypo"
|
ls_user="pypo"
|
||||||
export HOME="/var/tmp/airtime/pypo/"
|
export HOME="/var/tmp/airtime/pypo/"
|
||||||
api_client_path="/usr/lib/airtime/pypo/"
|
api_client_path="/usr/lib/airtime/pypo/"
|
||||||
ls_path="/usr/lib/airtime/pypo/bin/liquidsoap/liquidsoap"
|
ls_path="/usr/lib/airtime/pypo/bin/liquidsoap_bin/liquidsoap"
|
||||||
ls_param="/usr/lib/airtime/pypo/bin/scripts/ls_script.liq"
|
ls_param="/usr/lib/airtime/pypo/bin/liquidsoap_scripts/ls_script.liq"
|
||||||
echo "*** Daemontools: starting liquidsoap"
|
|
||||||
exec 2>&1
|
exec 2>&1
|
||||||
|
|
||||||
cd /usr/lib/airtime/pypo/bin/scripts
|
cd /usr/lib/airtime/pypo/bin/liquidsoap_scripts
|
||||||
|
|
||||||
export PYTHONPATH=${api_client_path}
|
export PYTHONPATH=${api_client_path}
|
||||||
exec ${ls_path} ${ls_param}
|
exec ${ls_path} ${ls_param}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
############################################
|
|
||||||
# pypo - configuration #
|
|
||||||
############################################
|
|
||||||
|
|
||||||
############################################
|
|
||||||
# Directories / Hosts #
|
|
||||||
# _include_ trailing slash !! #
|
|
||||||
############################################
|
|
||||||
cache_dir = '/storage/pypo/cache/'
|
|
||||||
file_dir = '/storage/pypo/files/'
|
|
||||||
tmp_dir = '/var/tmp/obp/'
|
|
||||||
|
|
||||||
############################################
|
|
||||||
# API path & co #
|
|
||||||
############################################
|
|
||||||
base_url = 'http://test.local.obp.ch/'
|
|
||||||
obp_api_key = 'AAA-BBB-CCC-EEE'
|
|
||||||
|
|
||||||
export_path = 'api/pypo/export_range/' # YYYY-MM-DD-hh-mm will be added in script, exports json
|
|
||||||
export_source = 'scheduler' # choose "dayparts" or "scheduler"
|
|
||||||
|
|
||||||
############################################
|
|
||||||
# Liquidsoap settings #
|
|
||||||
############################################
|
|
||||||
ls_host = '127.0.0.1'
|
|
||||||
ls_port = '1234'
|
|
||||||
|
|
||||||
############################################
|
|
||||||
# pypo preferences #
|
|
||||||
############################################
|
|
||||||
prepare_ahead = 12 #in hours
|
|
||||||
cache_for = 12 #how long to hold the cache, in hours
|
|
||||||
|
|
||||||
poll_interval = 10 # in seconds
|
|
||||||
push_interval = 1 # in seconds
|
|
||||||
|
|
||||||
# 'pre' or 'otf'. 'pre' cues while pplaylist preparation
|
|
||||||
# while 'otf' (on the fly) cues while loading into ls
|
|
||||||
# (needs the post_processor patch)
|
|
||||||
cue_style = 'pre'
|
|
|
@ -1,3 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from dls_client import *
|
|
|
@ -1,88 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
import os
|
|
||||||
import socket
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DlsClient():
|
|
||||||
|
|
||||||
def __init__(self, dls_host, dls_port, dls_user, dls_pass):
|
|
||||||
self.dls_host = dls_host
|
|
||||||
self.dls_port = dls_port
|
|
||||||
self.dls_user = dls_user
|
|
||||||
self.dls_pass = dls_pass
|
|
||||||
|
|
||||||
def set_txt(self, txt):
|
|
||||||
|
|
||||||
logger = logging.getLogger("DlsClient.set_txt")
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
print 'trying to update dls'
|
|
||||||
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
s.connect((self.dls_host, self.dls_port))
|
|
||||||
|
|
||||||
s.send('client_zzzz')
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.send('RS_DLS_VERSION' + ' ' + '1')
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.send('SERVICE' + ' ' + self.dls_user)
|
|
||||||
s.send("\r\n")
|
|
||||||
|
|
||||||
s.send('PASSWORD' + ' ' + self.dls_pass)
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.send('SET_DLS_CHARSET' + ' ' + '4')
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.send('CLEAR_DLS')
|
|
||||||
s.send("\r\n")
|
|
||||||
|
|
||||||
s.send('SET_DLS' + ' ' + txt)
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.send('CLOSE_DLS')
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
print 'OK'
|
|
||||||
|
|
||||||
except Exception, e:
|
|
||||||
#print e
|
|
||||||
print 'did not work out.'
|
|
||||||
dls_status = False
|
|
||||||
logger.info("Unable to connect to the update metadata - %s", e)
|
|
||||||
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -81,16 +81,16 @@ try:
|
||||||
|
|
||||||
if architecture == '64bit' and natty:
|
if architecture == '64bit' and natty:
|
||||||
print "Installing 64-bit liquidsoap binary (Natty)"
|
print "Installing 64-bit liquidsoap binary (Natty)"
|
||||||
shutil.copy("%s/../liquidsoap/liquidsoap-amd64-natty"%current_script_dir, "%s/../liquidsoap/liquidsoap"%current_script_dir)
|
shutil.copy("%s/../liquidsoap_bin/liquidsoap-amd64-natty"%current_script_dir, "%s/../liquidsoap_bin/liquidsoap"%current_script_dir)
|
||||||
elif architecture == '32bit' and natty:
|
elif architecture == '32bit' and natty:
|
||||||
print "Installing 32-bit liquidsoap binary (Natty)"
|
print "Installing 32-bit liquidsoap binary (Natty)"
|
||||||
shutil.copy("%s/../liquidsoap/liquidsoap-i386-natty"%current_script_dir, "%s/../liquidsoap/liquidsoap"%current_script_dir)
|
shutil.copy("%s/../liquidsoap_bin/liquidsoap-i386-natty"%current_script_dir, "%s/../liquidsoap_bin/liquidsoap"%current_script_dir)
|
||||||
elif architecture == '64bit' and not natty:
|
elif architecture == '64bit' and not natty:
|
||||||
print "Installing 64-bit liquidsoap binary"
|
print "Installing 64-bit liquidsoap binary"
|
||||||
shutil.copy("%s/../liquidsoap/liquidsoap-amd64"%current_script_dir, "%s/../liquidsoap/liquidsoap"%current_script_dir)
|
shutil.copy("%s/../liquidsoap_bin/liquidsoap-amd64"%current_script_dir, "%s/../liquidsoap_bin/liquidsoap"%current_script_dir)
|
||||||
elif architecture == '32bit' and not natty:
|
elif architecture == '32bit' and not natty:
|
||||||
print "Installing 32-bit liquidsoap binary"
|
print "Installing 32-bit liquidsoap binary"
|
||||||
shutil.copy("%s/../liquidsoap/liquidsoap-i386"%current_script_dir, "%s/../liquidsoap/liquidsoap"%current_script_dir)
|
shutil.copy("%s/../liquidsoap_bin/liquidsoap-i386"%current_script_dir, "%s/../liquidsoap_bin/liquidsoap"%current_script_dir)
|
||||||
else:
|
else:
|
||||||
print "Unknown system architecture."
|
print "Unknown system architecture."
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
def notify(m)
|
def notify(m)
|
||||||
system("/usr/lib/airtime/pypo/bin/scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']}")
|
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']}")
|
||||||
print("/usr/lib/airtime/pypo/bin/scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']}")
|
print("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# A function applied to each metadata chunk
|
# A function applied to each metadata chunk
|
|
@ -1,193 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
|
||||||
Python part of radio playout (pypo)
|
|
||||||
|
|
||||||
This function acts as a gateway between liquidsoap and the obp-api.
|
|
||||||
Mainliy used to tell the platform what pypo/LS does.
|
|
||||||
|
|
||||||
Main case:
|
|
||||||
- whenever Liquidsoap starts playing a new track, its on_metadata callback calls
|
|
||||||
a function in liquidsoap (notify(m)) which then calls the python script here
|
|
||||||
with the currently starting filename as parameter
|
|
||||||
- this python script takes this parameter, tries to extract the actual
|
|
||||||
media id from it, and then calls back to API to tell it about it.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
# python defaults (debian default)
|
|
||||||
import time
|
|
||||||
import os
|
|
||||||
import traceback
|
|
||||||
from optparse import *
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import datetime
|
|
||||||
import logging
|
|
||||||
import logging.config
|
|
||||||
import urllib
|
|
||||||
import urllib2
|
|
||||||
import string
|
|
||||||
|
|
||||||
import socket
|
|
||||||
|
|
||||||
# additional modules (should be checked)
|
|
||||||
from configobj import ConfigObj
|
|
||||||
|
|
||||||
# custom imports
|
|
||||||
from util import *
|
|
||||||
from obp import *
|
|
||||||
|
|
||||||
#set up command-line options
|
|
||||||
parser = OptionParser()
|
|
||||||
|
|
||||||
# help screeen / info
|
|
||||||
usage = "%prog [options]" + " - notification gateway"
|
|
||||||
parser = OptionParser(usage=usage)
|
|
||||||
|
|
||||||
#options
|
|
||||||
parser.add_option("-p", "--playing", help="Tell daddy what is playing right now", metavar="path")
|
|
||||||
|
|
||||||
# parse options
|
|
||||||
(options, args) = parser.parse_args()
|
|
||||||
|
|
||||||
# configure logging
|
|
||||||
logging.config.fileConfig("logging.cfg")
|
|
||||||
|
|
||||||
# loading config file
|
|
||||||
try:
|
|
||||||
config = ConfigObj('config.cfg')
|
|
||||||
TMP_DIR = config['tmp_dir']
|
|
||||||
BASE_URL = config['base_url']
|
|
||||||
API_BASE = BASE_URL + 'mod/medialibrary/'
|
|
||||||
EXPORT_SOURCE = config['export_source']
|
|
||||||
API_KEY = config['api_key']
|
|
||||||
|
|
||||||
except Exception, e:
|
|
||||||
print 'error: ', e
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
|
|
||||||
class Global:
|
|
||||||
def __init__(self):
|
|
||||||
print
|
|
||||||
|
|
||||||
def selfcheck(self):
|
|
||||||
self.api_auth = urllib.urlencode({'api_key': API_KEY})
|
|
||||||
self.api_client = api_client.api_client_factory(config)
|
|
||||||
if (not self.api_client.is_server_compatible()):
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
class Notify:
|
|
||||||
def __init__(self):
|
|
||||||
|
|
||||||
self.tmp_dir = TMP_DIR
|
|
||||||
self.export_source = EXPORT_SOURCE
|
|
||||||
|
|
||||||
self.api_auth = urllib.urlencode({'api_key': API_KEY})
|
|
||||||
self.api_client = api_client.api_client_factory(config)
|
|
||||||
|
|
||||||
|
|
||||||
def start_playing(self, options):
|
|
||||||
logger = logging.getLogger("start_playing")
|
|
||||||
|
|
||||||
tnow = time.localtime(time.time())
|
|
||||||
|
|
||||||
path = options
|
|
||||||
|
|
||||||
try:
|
|
||||||
file = path.split("/")[-1:][0]
|
|
||||||
if file.find('_cue_') > 0:
|
|
||||||
id = file.split("_cue_")[0]
|
|
||||||
else:
|
|
||||||
id = file.split(".")[-2:][0]
|
|
||||||
|
|
||||||
except Exception, e:
|
|
||||||
#print e
|
|
||||||
id = False
|
|
||||||
|
|
||||||
try:
|
|
||||||
id = int(id)
|
|
||||||
except Exception, e:
|
|
||||||
#print e
|
|
||||||
id = False
|
|
||||||
|
|
||||||
print
|
|
||||||
print "Media ID: ",
|
|
||||||
print id
|
|
||||||
|
|
||||||
# self.api_client.update_start_playing(id, self.export_source, path)
|
|
||||||
txt = "test this update"
|
|
||||||
|
|
||||||
# Echo client program
|
|
||||||
HOST = '172.16.16.128' # The remote host
|
|
||||||
PORT = 50008 # The same port as used by the server
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
s.connect((HOST, PORT))
|
|
||||||
|
|
||||||
s.send('client_zzzz')
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.send('RS_DLS_VERSION' + ' ' + '1')
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.send('SERVICE' + ' ' + 'OPENBRO+')
|
|
||||||
s.send("\r\n")
|
|
||||||
|
|
||||||
s.send('PASSWORD' + ' ' + 'OPENBRO+')
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.send('CLEAR_DLS')
|
|
||||||
s.send("\r\n")
|
|
||||||
|
|
||||||
s.send('SET_DLS' + ' ' + txt)
|
|
||||||
s.send("\r\n")
|
|
||||||
data = s.recv(1024)
|
|
||||||
print data;
|
|
||||||
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
print data
|
|
||||||
|
|
||||||
if data == "session":
|
|
||||||
print 'KKK'
|
|
||||||
|
|
||||||
time.sleep(0.1)
|
|
||||||
print 'DONE'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
print
|
|
||||||
print '#########################################'
|
|
||||||
print '# *** pypo *** #'
|
|
||||||
print '# pypo notification gateway #'
|
|
||||||
print '#########################################'
|
|
||||||
print
|
|
||||||
|
|
||||||
# initialize
|
|
||||||
g = Global()
|
|
||||||
g.selfcheck()
|
|
||||||
n = Notify()
|
|
||||||
|
|
||||||
|
|
||||||
run = True
|
|
||||||
while run == True:
|
|
||||||
|
|
||||||
logger = logging.getLogger("pypo notify")
|
|
||||||
|
|
||||||
while options.playing:
|
|
||||||
try: n.start_playing(options.playing)
|
|
||||||
except Exception, e:
|
|
||||||
print e
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
sys.exit()
|
|
Loading…
Reference in New Issue