Merge branch 'master' of dev.sourcefabric.org:campcaster
This commit is contained in:
commit
d5546c3952
|
@ -0,0 +1,47 @@
|
|||
############################################
|
||||
# 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://vdeb.openbroadcast.ch/'
|
||||
obp_api_key = 'AAA-BBB-CCC-EEE'
|
||||
|
||||
# stage config
|
||||
#base_url = 'http://stage.openbroadcast.ch/'
|
||||
#obp_api_key = 'EMMKM-PMXWV-NIGOA-KHGWPP
|
||||
|
||||
# prod config
|
||||
#base_url = 'http://openbroadcast.ch/'
|
||||
#obp_api_key = 'XWQWP-XIHJU-ZHENT-NGSAW'
|
||||
|
||||
export_path = 'api/pypo/export_range/' # YYYY-MM-DD-hh-mm will be added in script, exports json
|
||||
|
||||
############################################
|
||||
# Liquidsoap settings #
|
||||
############################################
|
||||
ls_host = '127.0.0.1'
|
||||
ls_port = '1234'
|
||||
|
||||
############################################
|
||||
# pypo preferences #
|
||||
############################################
|
||||
prepare_ahead = 24 #in hours
|
||||
cache_for = 24 #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'
|
|
@ -0,0 +1,40 @@
|
|||
############################################
|
||||
# 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'
|
|
@ -0,0 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from dls_client import *
|
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
import logging
|
||||
|
||||
from util import json
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
[loggers]
|
||||
keys=root
|
||||
|
||||
[handlers]
|
||||
keys=consoleHandler,fileHandlerERROR,fileHandlerDEBUG,nullHandler
|
||||
|
||||
[formatters]
|
||||
keys=simpleFormatter
|
||||
|
||||
[logger_root]
|
||||
level=DEBUG
|
||||
handlers=consoleHandler,fileHandlerERROR,fileHandlerDEBUG
|
||||
|
||||
[logger_libs]
|
||||
handlers=nullHandler
|
||||
level=DEBUG
|
||||
qualname="process"
|
||||
propagate=0
|
||||
|
||||
|
||||
|
||||
[handler_consoleHandler]
|
||||
class=StreamHandler
|
||||
level=ERROR
|
||||
formatter=simpleFormatter
|
||||
args=(sys.stdout,)
|
||||
|
||||
[handler_fileHandlerERROR]
|
||||
class=FileHandler
|
||||
level=WARNING
|
||||
formatter=simpleFormatter
|
||||
args=("/var/log/obp/pypo/error.log",)
|
||||
|
||||
[handler_fileHandlerDEBUG]
|
||||
class=FileHandler
|
||||
level=DEBUG
|
||||
formatter=simpleFormatter
|
||||
args=("/var/log/obp/pypo/debug.log",)
|
||||
|
||||
[handler_nullHandler]
|
||||
class=FileHandler
|
||||
level=DEBUG
|
||||
formatter=simpleFormatter
|
||||
args=("/tmp/sessionlog_null.log",)
|
||||
|
||||
|
||||
|
||||
|
||||
[formatter_simpleFormatter]
|
||||
format=%(asctime)s %(levelname)s - [%(name)s] - %(message)s
|
||||
datefmt=
|
||||
|
||||
|
||||
## multitail color sheme
|
||||
## pyml / python
|
||||
# colorscheme:pyml:www.obp.net
|
||||
# cs_re:blue:\[[^ ]*\]
|
||||
# cs_re:red:CRITICAL:*
|
||||
# cs_re:red,black,blink:ERROR:*
|
||||
# cs_re:blue:NOTICE:*
|
||||
# cs_re:cyan:INFO:*
|
||||
# cs_re:green:DEBUG:*
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from api_client import *
|
|
@ -0,0 +1,144 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
import sys
|
||||
import time
|
||||
import urllib
|
||||
|
||||
import logging
|
||||
|
||||
from util import json
|
||||
|
||||
import os
|
||||
|
||||
|
||||
|
||||
class ApiClient():
|
||||
|
||||
def __init__(self, api_url, api_auth):
|
||||
self.api_url = api_url
|
||||
self.api_auth = api_auth
|
||||
|
||||
def get_obp_version(self):
|
||||
logger = logging.getLogger("ApiClient.get_obp_version")
|
||||
# lookup OBP version
|
||||
|
||||
url = self.api_url + 'api/pypo/status/json'
|
||||
|
||||
try:
|
||||
|
||||
logger.debug("Trying to contact %s", url)
|
||||
|
||||
response = urllib.urlopen(url, self.api_auth)
|
||||
response_json = json.read(response.read())
|
||||
obp_version = int(response_json['version'])
|
||||
logger.debug("OBP Version %s detected", obp_version)
|
||||
|
||||
|
||||
except Exception, e:
|
||||
try:
|
||||
if e[1] == 401:
|
||||
print '#####################################'
|
||||
print '# YOUR API KEY SEEMS TO BE INVALID'
|
||||
print '# ' + self.api_auth
|
||||
print '#####################################'
|
||||
sys.exit()
|
||||
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
try:
|
||||
if e[1] == 404:
|
||||
print '#####################################'
|
||||
print '# Unable to contact the OBP-API'
|
||||
print '# ' + url
|
||||
print '#####################################'
|
||||
sys.exit()
|
||||
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
obp_version = 0
|
||||
logger.error("Unable to detect OBP Version - %s", e)
|
||||
|
||||
|
||||
return obp_version
|
||||
|
||||
|
||||
def update_shedueled_item(self, item_id, value):
|
||||
logger = logging.getLogger("ApiClient.update_shedueled_item")
|
||||
# lookup OBP version
|
||||
|
||||
url = self.api_url + 'api/pypo/update_shedueled_item/' + str(item_id) + '?played=' + str(value)
|
||||
|
||||
try:
|
||||
response = urllib.urlopen(url, self.api_auth)
|
||||
response = json.read(response.read())
|
||||
logger.info("API-Status %s", response['status'])
|
||||
logger.info("API-Message %s", response['message'])
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
api_status = False
|
||||
logger.critical("Unable to connect to the OBP API - %s", e)
|
||||
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def update_start_playing(self, playlist_type, export_source, media_id, playlist_id, transmission_id):
|
||||
|
||||
logger = logging.getLogger("ApiClient.update_shedueled_item")
|
||||
|
||||
url = self.api_url + 'api/pypo/update_start_playing/' \
|
||||
+ '?playlist_type=' + str(playlist_type) \
|
||||
+ '&export_source=' + str(export_source) \
|
||||
+ '&export_source=' + str(export_source) \
|
||||
+ '&media_id=' + str(media_id) \
|
||||
+ '&playlist_id=' + str(playlist_id) \
|
||||
+ '&transmission_id=' + str(transmission_id)
|
||||
|
||||
print url
|
||||
|
||||
try:
|
||||
response = urllib.urlopen(url, self.api_auth)
|
||||
response = json.read(response.read())
|
||||
logger.info("API-Status %s", response['status'])
|
||||
logger.info("API-Message %s", response['message'])
|
||||
logger.info("TXT %s", response['str_dls'])
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
api_status = False
|
||||
logger.critical("Unable to connect to the OBP API - %s", e)
|
||||
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def generate_range_dp(self):
|
||||
logger = logging.getLogger("ApiClient.generate_range_dp")
|
||||
|
||||
url = self.api_url + 'api/pypo/generate_range_dp/'
|
||||
|
||||
try:
|
||||
response = urllib.urlopen(url, self.api_auth)
|
||||
response = json.read(response.read())
|
||||
logger.debug("Trying to contact %s", url)
|
||||
logger.info("API-Status %s", response['status'])
|
||||
logger.info("API-Message %s", response['message'])
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
api_status = False
|
||||
logger.critical("Unable to handle the OBP API request - %s", e)
|
||||
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,307 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
"""
|
||||
Python part of radio playout (pypo)
|
||||
|
||||
The main functionas are "fetch" (./pypo_cli.py -f) and "push" (./pypo_cli.py -p)
|
||||
|
||||
Also check out the php counterpart that handles the api requests:
|
||||
https://lab.digris.ch/svn/elgg/trunk/unstable/mod/medialibrary/application/controllers/api/pypo.php
|
||||
|
||||
Attention & ToDos
|
||||
- liquidsoap does not like mono files! So we have to make sure that only files with
|
||||
2 channels are fed to LS
|
||||
(solved: current = audio_to_stereo(current) - maybe not with ultimate performance)
|
||||
|
||||
|
||||
made for python version 2.5!!
|
||||
should work with 2.6 as well with a bit of adaption. for
|
||||
sure the json parsing has to be changed
|
||||
(2.6 has an parser, pypo brigs it's own -> util/json.py)
|
||||
"""
|
||||
|
||||
# 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 shutil
|
||||
import urllib
|
||||
import urllib2
|
||||
import pickle
|
||||
import telnetlib
|
||||
import random
|
||||
import string
|
||||
import operator
|
||||
|
||||
# additional modules (should be checked)
|
||||
from configobj import ConfigObj
|
||||
|
||||
# custom imports
|
||||
from util import *
|
||||
from obp import *
|
||||
|
||||
|
||||
|
||||
PYPO_VERSION = '0.1'
|
||||
OBP_MIN_VERSION = 2010100101 # required obp version
|
||||
|
||||
|
||||
#set up command-line options
|
||||
parser = OptionParser()
|
||||
|
||||
# help screeen / info
|
||||
usage = "%prog [options]" + " - python playout system"
|
||||
parser = OptionParser(usage=usage)
|
||||
|
||||
#options
|
||||
parser.add_option("-f", "--fetch", help="Fetch Schedule (loop, interval in config file)", default=False, action="store_true", dest="fetch")
|
||||
parser.add_option("-p", "--push", help="Push pl to Liquidsoap (loop, interval in config file)", default=False, action="store_true", dest="push")
|
||||
parser.add_option("-b", "--cleanup", help="Faeili Butzae aka cleanup", default=False, action="store_true", dest="cleanup")
|
||||
parser.add_option("-j", "--jingles", help="Get new jungles from obp, comma separated list if jingle-id's as argument", metavar="LIST")
|
||||
parser.add_option("-c", "--check", help="Check the cached schedule and exit", default=False, action="store_true", dest="check")
|
||||
|
||||
parser.add_option("-P", "--pushpkey", help="Push PKEY", metavar="LIST")
|
||||
|
||||
# parse options
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
# configure logging
|
||||
logging.config.fileConfig("logging.cfg")
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('config.cfg')
|
||||
CACHE_DIR = config['cache_dir']
|
||||
FILE_DIR = config['file_dir']
|
||||
TMP_DIR = config['tmp_dir']
|
||||
BASE_URL = config['base_url']
|
||||
OBP_API_BASE = BASE_URL + 'mod/medialibrary/'
|
||||
EXPORT_URL = OBP_API_BASE + config['export_path']
|
||||
EXPORT_SOURCE = config['export_source']
|
||||
|
||||
OBP_STATUS_URL = OBP_API_BASE + 'status/version/json'
|
||||
OBP_API_KEY = config['obp_api_key']
|
||||
|
||||
POLL_INTERVAL = float(config['poll_interval'])
|
||||
PUSH_INTERVAL = float(config['push_interval'])
|
||||
LS_HOST = config['ls_host']
|
||||
LS_PORT = config['ls_port']
|
||||
PREPARE_AHEAD = config['prepare_ahead']
|
||||
CACHE_FOR = config['cache_for']
|
||||
CUE_STYLE = config['cue_style']
|
||||
|
||||
except Exception, e:
|
||||
print 'error: ', e
|
||||
sys.exit()
|
||||
|
||||
#TIME = time.localtime(time.time())
|
||||
TIME = (2010, 6, 26, 15, 33, 23, 2, 322, 0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Global:
|
||||
def __init__(self):
|
||||
#print '# global initialisation'
|
||||
print
|
||||
|
||||
def selfcheck(self):
|
||||
|
||||
self.api_auth = urllib.urlencode({'api_key': OBP_API_KEY})
|
||||
self.api_client = ApiClient(OBP_API_BASE, self.api_auth)
|
||||
|
||||
obp_version = self.api_client.get_obp_version()
|
||||
|
||||
|
||||
if obp_version == 0:
|
||||
print '#################################################'
|
||||
print 'Unable to get OBP version. Is OBP up and running?'
|
||||
print '#################################################'
|
||||
print
|
||||
sys.exit()
|
||||
|
||||
elif obp_version < OBP_MIN_VERSION:
|
||||
print 'OBP version: ' + str(obp_version)
|
||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||
print 'pypo not compatible with this version of OBP'
|
||||
print
|
||||
sys.exit()
|
||||
|
||||
else:
|
||||
print 'OBP API: ' + str(OBP_API_BASE)
|
||||
print 'OBP version: ' + str(obp_version)
|
||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||
print 'pypo is compatible with this version of OBP'
|
||||
print
|
||||
|
||||
|
||||
"""
|
||||
Uncomment the following lines to let pypo check if
|
||||
liquidsoap is running. (checks for a telnet server)
|
||||
"""
|
||||
# while self.status.check_ls(LS_HOST, LS_PORT) == 0:
|
||||
# print 'Unable to connect to liquidsoap. Is it up and running?'
|
||||
# time.sleep(2)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
class Playout:
|
||||
def __init__(self):
|
||||
#print '# init fallback'
|
||||
|
||||
self.cache_dir = CACHE_DIR
|
||||
self.file_dir = FILE_DIR
|
||||
self.tmp_dir = TMP_DIR
|
||||
self.export_url = EXPORT_URL
|
||||
self.export_source = EXPORT_SOURCE
|
||||
|
||||
self.api_auth = urllib.urlencode({'api_key': OBP_API_KEY})
|
||||
self.api_client = ApiClient(OBP_API_BASE, self.api_auth)
|
||||
self.cue_file = CueFile()
|
||||
|
||||
self.schedule_file = CACHE_DIR + 'schedule'
|
||||
|
||||
# set initial state
|
||||
self.range_updated = False
|
||||
|
||||
|
||||
|
||||
|
||||
def push_liquidsoap(self,options):
|
||||
logger = logging.getLogger("push_liquidsoap")
|
||||
|
||||
print options
|
||||
|
||||
#pkey = '2010-10-26-21-00-00'
|
||||
|
||||
pkey = options
|
||||
|
||||
src = self.cache_dir + str(pkey) + '/list.lsp'
|
||||
|
||||
print src
|
||||
|
||||
|
||||
if True == os.access(src, os.R_OK):
|
||||
print 'OK - Can read'
|
||||
|
||||
pl_file = open(src, "r")
|
||||
|
||||
|
||||
|
||||
"""
|
||||
i know this could be wrapped, maybe later..
|
||||
"""
|
||||
tn = telnetlib.Telnet(LS_HOST, 1234)
|
||||
#tn.write("\n")
|
||||
|
||||
for line in pl_file.readlines():
|
||||
print line.strip()
|
||||
|
||||
#tn.write('q.push ' + pl_entry)
|
||||
#tn.write("\n")
|
||||
|
||||
tn.write('scheduler.push %s' % (line.strip()))
|
||||
tn.write("\n")
|
||||
|
||||
|
||||
|
||||
tn.write("scheduler_q0.queue \n")
|
||||
|
||||
tn.write("scheduler_q1.queue \n")
|
||||
#time.sleep(2)
|
||||
|
||||
|
||||
#print tn.read_all()
|
||||
|
||||
print 'sending "flip"'
|
||||
|
||||
tn.write('scheduler.flip')
|
||||
tn.write("\n")
|
||||
|
||||
|
||||
|
||||
|
||||
#tn.write("live_in.stop\n")
|
||||
#tn.write("stream_disable\n")
|
||||
#time.sleep(0.2)
|
||||
#tn.write("\n")
|
||||
#tn.write("reload_current\n")
|
||||
#tn.write("current.reload\n")
|
||||
#time.sleep(0.2)
|
||||
#tn.write("skip_current\n")
|
||||
|
||||
# if(int(ptype) == 6):
|
||||
# """
|
||||
# Couchcaster / Recast comming. Stop/Start live input to have ls re-read it's playlist
|
||||
# """
|
||||
# print 'Couchcaster - switching to stream'
|
||||
# tn.write("live_in.start\n")
|
||||
# time.sleep(0.2)
|
||||
# tn.write("stream_enable\n")
|
||||
#
|
||||
#
|
||||
#
|
||||
# """
|
||||
# Pass some extra information to liquidsoap
|
||||
# """
|
||||
# tn.write("pl.pl_id '%s'\n" % p_id)
|
||||
# tn.write("pl.user_id '%s'\n" % user_id)
|
||||
|
||||
|
||||
|
||||
tn.write("exit\n")
|
||||
|
||||
print tn.read_all()
|
||||
|
||||
status = 1
|
||||
sys.exit()
|
||||
|
||||
# except Exception, e:
|
||||
# logger.error('%s', e)
|
||||
# status = 0
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
print
|
||||
print '#########################################'
|
||||
print '# *** pypo *** #'
|
||||
print '# obp python playout #'
|
||||
print '#########################################'
|
||||
print
|
||||
|
||||
# initialize
|
||||
g = Global()
|
||||
g.selfcheck()
|
||||
po = Playout()
|
||||
|
||||
|
||||
run = True
|
||||
while run == True:
|
||||
|
||||
logger = logging.getLogger("pypo")
|
||||
|
||||
while options.pushpkey:
|
||||
try: po.push_liquidsoap(options.pushpkey)
|
||||
except Exception, e:
|
||||
print e
|
||||
sys.exit()
|
||||
|
||||
while options.push:
|
||||
po.push_liquidsoap()
|
||||
sys.exit()
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,243 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
"""
|
||||
Python part of radio playout (pypo)
|
||||
|
||||
This function acts as a gateway between liquidsoap and the obp-api.
|
||||
Mainliy used to tell the plattform what pypo/LS does.
|
||||
|
||||
Main case:
|
||||
- whenever LS starts playing a new track, its on_metadata callback calls
|
||||
a function in ls (notify(m)) which then calls the pythin 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 obp via api to tell about
|
||||
|
||||
|
||||
"""
|
||||
|
||||
# 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 *
|
||||
|
||||
|
||||
|
||||
PYPO_VERSION = '0.9'
|
||||
OBP_MIN_VERSION = 2010040501 # required obp version
|
||||
|
||||
|
||||
#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']
|
||||
OBP_API_BASE = BASE_URL + 'mod/medialibrary/'
|
||||
EXPORT_SOURCE = config['export_source']
|
||||
|
||||
OBP_STATUS_URL = OBP_API_BASE + 'status/version/json'
|
||||
OBP_API_KEY = config['obp_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': OBP_API_KEY})
|
||||
self.api_client = ApiClient(OBP_API_BASE, self.api_auth)
|
||||
|
||||
obp_version = self.api_client.get_obp_version()
|
||||
|
||||
if obp_version == 0:
|
||||
print '#################################################'
|
||||
print 'Unable to get OBP version. Is OBP up and running?'
|
||||
print '#################################################'
|
||||
print
|
||||
sys.exit()
|
||||
|
||||
elif obp_version < OBP_MIN_VERSION:
|
||||
print 'OBP version: ' + str(obp_version)
|
||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||
print 'pypo not compatible with this version of OBP'
|
||||
print
|
||||
sys.exit()
|
||||
|
||||
else:
|
||||
print 'OBP API: ' + str(OBP_API_BASE)
|
||||
print 'OBP version: ' + str(obp_version)
|
||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||
print 'pypo is compatible with this version of OBP'
|
||||
print
|
||||
|
||||
class Notify:
|
||||
def __init__(self):
|
||||
|
||||
self.tmp_dir = TMP_DIR
|
||||
self.export_source = EXPORT_SOURCE
|
||||
|
||||
self.api_auth = urllib.urlencode({'api_key': OBP_API_KEY})
|
||||
self.api_client = ApiClient(OBP_API_BASE, self.api_auth)
|
||||
|
||||
|
||||
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()
|
|
@ -0,0 +1,285 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
"""
|
||||
Python part of radio playout (pypo)
|
||||
|
||||
This function acts as a gateway between liquidsoap and the obp-api.
|
||||
Mainliy used to tell the plattform what pypo/LS does.
|
||||
|
||||
Main case:
|
||||
- whenever LS starts playing a new track, its on_metadata callback calls
|
||||
a function in ls (notify(m)) which then calls the pythin 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 obp via api to tell about
|
||||
|
||||
|
||||
"""
|
||||
|
||||
# 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
|
||||
|
||||
# additional modules (should be checked)
|
||||
from configobj import ConfigObj
|
||||
|
||||
# custom imports
|
||||
from util import *
|
||||
from obp import *
|
||||
from dls import *
|
||||
|
||||
|
||||
|
||||
PYPO_VERSION = '0.9'
|
||||
OBP_MIN_VERSION = 2010040501 # required obp version
|
||||
|
||||
|
||||
#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", dest="playing", default=False, metavar=False)
|
||||
|
||||
parser.add_option("-p", "--playing", help="Tell daddy what is playing right now", default=False, action="store_true", dest="playing")
|
||||
|
||||
|
||||
parser.add_option("-t", "--playlist-type", help="Tell daddy what is playing right now", metavar="playlist_type")
|
||||
|
||||
parser.add_option("-M", "--media-id", help="Tell daddy what is playing right now", metavar="media_id")
|
||||
parser.add_option("-U", "--user-id", help="Tell daddy what is playing right now", metavar="user_id")
|
||||
parser.add_option("-P", "--playlist-id", help="Tell daddy what is playing right now", metavar="playlist_id")
|
||||
parser.add_option("-T", "--transmission-id", help="Tell daddy what is playing right now", metavar="transmission_id")
|
||||
parser.add_option("-E", "--export-source", help="Tell daddy what is playing right now", metavar="export_source")
|
||||
|
||||
# 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']
|
||||
OBP_API_BASE = BASE_URL + 'mod/medialibrary/'
|
||||
|
||||
OBP_STATUS_URL = OBP_API_BASE + 'status/version/json'
|
||||
OBP_API_KEY = config['obp_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': OBP_API_KEY})
|
||||
self.api_client = ApiClient(OBP_API_BASE, self.api_auth)
|
||||
|
||||
obp_version = self.api_client.get_obp_version()
|
||||
|
||||
if obp_version == 0:
|
||||
print '#################################################'
|
||||
print 'Unable to get OBP version. Is OBP up and running?'
|
||||
print '#################################################'
|
||||
print
|
||||
sys.exit()
|
||||
|
||||
elif obp_version < OBP_MIN_VERSION:
|
||||
print 'OBP version: ' + str(obp_version)
|
||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||
print 'pypo not compatible with this version of OBP'
|
||||
print
|
||||
sys.exit()
|
||||
|
||||
else:
|
||||
print 'OBP API: ' + str(OBP_API_BASE)
|
||||
print 'OBP version: ' + str(obp_version)
|
||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||
print 'pypo is compatible with this version of OBP'
|
||||
print
|
||||
|
||||
class Notify:
|
||||
def __init__(self):
|
||||
|
||||
self.tmp_dir = TMP_DIR
|
||||
|
||||
self.api_auth = urllib.urlencode({'api_key': OBP_API_KEY})
|
||||
self.api_client = ApiClient(OBP_API_BASE, self.api_auth)
|
||||
|
||||
self.dls_client = DlsClient('127.0.0.128', 50008, 'myusername', 'mypass')
|
||||
|
||||
|
||||
|
||||
|
||||
def start_playing(self, options):
|
||||
logger = logging.getLogger("start_playing")
|
||||
|
||||
tnow = time.localtime(time.time())
|
||||
|
||||
#print options
|
||||
|
||||
|
||||
|
||||
print '#################################################'
|
||||
print '# calling obp to tell about what\'s playing #'
|
||||
print '#################################################'
|
||||
|
||||
if int(options.playlist_type) < 5:
|
||||
print 'seems to be a playlist'
|
||||
|
||||
try:
|
||||
media_id = int(options.media_id)
|
||||
except Exception, e:
|
||||
media_id = 0
|
||||
|
||||
response = self.api_client.update_start_playing(options.playlist_type, options.export_source, media_id, options.playlist_id, options.transmission_id)
|
||||
|
||||
print response
|
||||
|
||||
if int(options.playlist_type) == 6:
|
||||
print 'seems to be a couchcast'
|
||||
|
||||
try:
|
||||
media_id = int(options.media_id)
|
||||
except Exception, e:
|
||||
media_id = 0
|
||||
|
||||
response = self.api_client.update_start_playing(options.playlist_type, options.export_source, media_id, options.playlist_id, options.transmission_id)
|
||||
|
||||
print response
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def start_playing_legacy(self, options):
|
||||
logger = logging.getLogger("start_playing")
|
||||
|
||||
tnow = time.localtime(time.time())
|
||||
|
||||
|
||||
print '#################################################'
|
||||
print '# calling obp to tell about what\'s playing #'
|
||||
print '#################################################'
|
||||
|
||||
path = options
|
||||
|
||||
print
|
||||
print path
|
||||
print
|
||||
|
||||
if 'pl_id' in path:
|
||||
print 'seems to be a playlist'
|
||||
type = 'playlist'
|
||||
id = path[5:]
|
||||
|
||||
elif 'text' in path:
|
||||
print 'seems to be a playlist'
|
||||
type = 'text'
|
||||
id = path[4:]
|
||||
print id
|
||||
|
||||
else:
|
||||
print 'seems to be a single track (media)'
|
||||
type = 'media'
|
||||
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 = id
|
||||
except Exception, e:
|
||||
#print e
|
||||
id = False
|
||||
|
||||
print
|
||||
print type + " id: ",
|
||||
print id
|
||||
|
||||
|
||||
response = self.api_client.update_start_playing(type, id, self.export_source, path)
|
||||
|
||||
print 'DONE'
|
||||
|
||||
try:
|
||||
txt = response['txt']
|
||||
print '#######################################'
|
||||
print txt
|
||||
print '#######################################'
|
||||
#self.dls_client.set_txt(txt)
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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")
|
||||
|
||||
if options.playing:
|
||||
try: n.start_playing(options)
|
||||
except Exception, e:
|
||||
print e
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
|
||||
sys.exit()
|
|
@ -0,0 +1,23 @@
|
|||
This directory contains scripts not directly related to pypo
|
||||
These mainly are things related to liquidsoap & playout
|
||||
|
||||
I added those scripts here to have them at hand for
|
||||
development and also to update/share them via svn
|
||||
|
||||
|
||||
scripts here:
|
||||
|
||||
- ls_run.sh
|
||||
wrapper to run liquid soap. makes sure that the "current" playlist is
|
||||
filled with silence
|
||||
|
||||
- ls_script.liq (called by ls_run.sh)
|
||||
the main liquidsoap control-script
|
||||
|
||||
- ls_cue.liq (included by ls_script.liq)
|
||||
contains a custom protocol that registers the cue-in/out values from the playlist script
|
||||
|
||||
- cue_file.py (called by ls_cue.liq)
|
||||
a wrapper that does the actual cutting.
|
||||
it is called with: path_to_file[path] cue_in[ss.ms] cue_out[ss.ms] and does the mp3 cutting (with mp3cut)
|
||||
returns a temporary file that can be used by ls (make sure to set "TEMP_DIR" in script)
|
|
@ -0,0 +1,127 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
|
||||
"""
|
||||
cue script that gets called by liquidsoap if a file in the playlist
|
||||
gives orders to cue (in/out). eg:
|
||||
cue_file:cue_in=120.0,cue_out=110.0:annotate:***
|
||||
|
||||
params: path_to_file, cue_in [float, seconds], cue_out [float, sseconds]
|
||||
returns: path to the cued temp-file
|
||||
|
||||
examples:
|
||||
calling: ./cue_file.py /storage/pypo/cache/2010-06-25-15-05-00/35.mp3 10 120.095
|
||||
returns: /tmp/lstf_UwDKcEngvF
|
||||
|
||||
One thing to mention here:
|
||||
The way pypo (ab)uses liquidsoap can bring in some unwanted effects. liquidsoap
|
||||
is built in a way that it tries to collect the needed files to playout in advance.
|
||||
we 'force' liquidsoap to immediately start playing a newly loaded list, so ls has
|
||||
no time to prepare the files. If a file is played without cues, this does not afect
|
||||
the playout too much. My testing on a lame VM added a delay of +/- 10ms.
|
||||
|
||||
If the first file in a playlist is cued, the "mp3cut" command takes time to execute.
|
||||
On the same VM this takes an additional 200ms for an average size mp3-file.
|
||||
So the playout will start a bit delayed. This should not be a too big issue, but
|
||||
think about this behaviour if you eg access the files via network (nas) as the reading
|
||||
of files could take some time as well.
|
||||
|
||||
So maybe we should think about a different implementation. One way would be to do the
|
||||
cueing during playlist preparation, so all the files would be pre-cut when they are
|
||||
passed to liquidsoap.
|
||||
Additionally this would allow to run an unpathed version of ls.
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import shutil
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from datetime import timedelta
|
||||
import os
|
||||
|
||||
from mutagen.mp3 import MP3
|
||||
import mad
|
||||
|
||||
TEMP_DIR = '/tmp/';
|
||||
|
||||
|
||||
sys.stderr.write('\n** starting mp3 cutter **\n\n')
|
||||
|
||||
try: src = sys.argv[1]
|
||||
except Exception, e:
|
||||
sys.stderr.write('No file givien. sorry.\n')
|
||||
sys.exit()
|
||||
|
||||
try: cue_in = float(sys.argv[2])
|
||||
except Exception, e:
|
||||
cue_in = float(0)
|
||||
pass
|
||||
|
||||
try: cue_out = float(sys.argv[3])
|
||||
except Exception, e:
|
||||
cue_out = float(0)
|
||||
pass
|
||||
|
||||
sys.stderr.write('in: %s - out: %s file: %s \n' % (cue_in, cue_out, src))
|
||||
dst = TEMP_DIR + 'lstf_' + "".join( [random.choice(string.letters) for i in xrange(10)] )
|
||||
|
||||
# get length of track
|
||||
"""
|
||||
madlib is not accurate enough to get the duration. (only goes to seconds, no ms)
|
||||
so it is not suitable for relative offsets (eg "play until 10s before the end")
|
||||
it anyway wuld be better to provide this script with absolute times, like
|
||||
play from 23.234 to 323.321
|
||||
"""
|
||||
# madlib
|
||||
#mf = mad.MadFile(src)
|
||||
#dur = float(float(mf.total_time())/1000)
|
||||
|
||||
# mutagen
|
||||
audio = MP3(src)
|
||||
dur = round(audio.info.length, 3)
|
||||
|
||||
|
||||
sys.stderr.write('duration: ' + str(dur) + '\n')
|
||||
|
||||
cue_out = round(float(dur) - cue_out, 3)
|
||||
|
||||
str_cue_in = str(timedelta(seconds=cue_in)).replace(".", "+") # hh:mm:ss+mss, eg 00:00:20+000
|
||||
str_cue_out = str(timedelta(seconds=cue_out)).replace(".", "+") #
|
||||
|
||||
"""
|
||||
now a bit a hackish part, don't know how to do this better...
|
||||
need to cut the digits after the "+"
|
||||
|
||||
"""
|
||||
ts = str_cue_in.split("+")
|
||||
try:
|
||||
if len(ts[1]) == 6:
|
||||
ts[1] = ts[1][0:3]
|
||||
str_cue_in = "%s+%s" % (ts[0], ts[1])
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
ts = str_cue_out.split("+")
|
||||
try:
|
||||
if len(ts[1]) == 6:
|
||||
ts[1] = ts[1][0:3]
|
||||
str_cue_out = "%s+%s" % (ts[0], ts[1])
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
#sys.stderr.write(str(timedelta(seconds=cue_in)).replace(".", "+") + '\n\n')
|
||||
sys.stderr.write('in: ' + str_cue_in + '\n')
|
||||
sys.stderr.write('abs: ' + str(str_cue_out) + '\n\n')
|
||||
|
||||
command = 'mp3cut -o %s -t %s-%s %s' % (dst, str_cue_in, str_cue_out, src);
|
||||
|
||||
sys.stderr.write(command + '\n\n\n')
|
||||
os.system(command + ' >/dev/null')
|
||||
#shutil.copy2(src, dst)
|
||||
|
||||
print dst + "\n";
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
#########################################
|
||||
# A/B queue-setup daypart
|
||||
#########################################
|
||||
|
||||
# a/b queue setup
|
||||
daypart_q0 = request.queue(conservative=true,length=600.,id="daypart_q0")
|
||||
daypart_q1 = request.queue(conservative=true,length=600.,id="daypart_q1")
|
||||
|
||||
daypart_q0 = audio_to_stereo(daypart_q0)
|
||||
daypart_q1 = audio_to_stereo(daypart_q1)
|
||||
|
||||
daypart_active = ref 0
|
||||
daypart_queue = ref 1
|
||||
daypart_q0_enabled = ref false
|
||||
daypart_q1_enabled = ref false
|
||||
|
||||
# push function, enqueues file in inactive queue (does not start automatically)
|
||||
def daypart_push(s)
|
||||
list.hd(server.execute("daypart_q#{!daypart_queue}.push #{s}"))
|
||||
print('push to #{!daypart_queue} - #{s}')
|
||||
"Done"
|
||||
end
|
||||
|
||||
|
||||
# flips the queues
|
||||
def daypart_flip()
|
||||
|
||||
# set a/b-queue corresponding to active, see fallback below
|
||||
if !daypart_active==1 then daypart_q0_enabled:=true else daypart_q0_enabled:=false end
|
||||
if !daypart_active==0 then daypart_q1_enabled:=true else daypart_q1_enabled:=false end
|
||||
|
||||
# get playing (active) queue and flush it
|
||||
l = list.hd(server.execute("daypart_q#{!daypart_active}.queue"))
|
||||
l = string.split(separator=" ",l)
|
||||
list.iter(fun (rid) -> ignore(server.execute("daypart_q#{!daypart_active}.ignore #{rid}")), l)
|
||||
|
||||
# skip the playing item
|
||||
# source.skip(if !daypart_active==0 then daypart_q0 else daypart_q1 end)
|
||||
|
||||
# flip variables
|
||||
daypart_active := 1-!daypart_active
|
||||
daypart_queue := 1-!daypart_active
|
||||
|
||||
"Done"
|
||||
end
|
||||
|
||||
|
||||
# print status
|
||||
def daypart_status()
|
||||
print('daypart_active: #{!daypart_active}')
|
||||
print('daypart_queue : #{!daypart_queue}')
|
||||
"Done"
|
||||
end
|
||||
|
||||
# register for telnet access
|
||||
server.register(namespace="daypart","push", daypart_push)
|
||||
server.register(namespace="daypart","flip", fun (_) -> daypart_flip())
|
||||
server.register(namespace="daypart","status", fun (_) -> daypart_status())
|
||||
|
||||
|
||||
# activate / deactivate queues, needed for fallback to work
|
||||
daypart_q0 = switch(track_sensitive=true, [({!daypart_q0_enabled},daypart_q0)])
|
||||
daypart_q1 = switch(track_sensitive=true, [({!daypart_q1_enabled},daypart_q1)])
|
||||
daypart_q_holder = fallback(track_sensitive=true, [daypart_q0, daypart_q1])
|
||||
|
||||
|
||||
# finally the resulting daypart source
|
||||
daypart = fallback(track_sensitive=false, [daypart_q_holder, default])
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
#######################################################################
|
||||
# Dynamic variables
|
||||
#######################################################################
|
||||
|
||||
playlist_id = ref '0'
|
||||
user_id = ref '0'
|
||||
transmission_id = ref '0'
|
||||
playlist_type = ref '0'
|
||||
|
||||
|
||||
def set_user_id(s)
|
||||
user_id := s
|
||||
end
|
||||
|
||||
|
||||
def set_playlist_id(s)
|
||||
playlist_id := s
|
||||
end
|
||||
|
||||
|
||||
def set_transmission_id(s)
|
||||
transmission_id := s
|
||||
end
|
||||
|
||||
def set_playlist_type(s)
|
||||
playlist_type := s
|
||||
end
|
||||
|
||||
server.register(namespace="vars", "user_id", fun (s) -> begin set_user_id(s) "Done!" end)
|
||||
server.register(namespace="vars", "playlist_id", fun (s) -> begin set_playlist_id(s) "Done!" end)
|
||||
server.register(namespace="vars", "transmission_id", fun (s) -> begin set_transmission_id(s) "Done!" end)
|
||||
server.register(namespace="vars", "playlist_type", fun (s) -> begin set_playlist_type(s) "Done!" end)
|
|
@ -0,0 +1,24 @@
|
|||
#######################################################################
|
||||
# Live input - From external icecast server
|
||||
#######################################################################
|
||||
|
||||
|
||||
live_in = input.http(id="live_in",autostart=false,buffer=.1, max=12.,couchcaster_list)
|
||||
live_in = buffer(id="buffer_live_in",buffer=.1,fallible=true,live_in)
|
||||
live_in = mksafe(live_in)
|
||||
|
||||
|
||||
|
||||
live_active = ref false
|
||||
def live_switch(i)
|
||||
print(i)
|
||||
if i=='1' then live_active:=true else live_active:=false end
|
||||
print(live_active)
|
||||
"Done"
|
||||
end
|
||||
server.register(namespace="live","active", live_switch)
|
||||
|
||||
live = switch(track_sensitive=false, [({!live_active},live_in)])
|
||||
|
||||
to_live_s = to_live(jingles_cc)
|
||||
to_scheduler_s = to_scheduler()
|
|
@ -0,0 +1,27 @@
|
|||
########################################
|
||||
# call pypo api gateway
|
||||
########################################
|
||||
|
||||
def notify(m)
|
||||
|
||||
print('user_id: #{!user_id}')
|
||||
print('playlist_id: #{!playlist_id}')
|
||||
print('transmission_id: #{!transmission_id}')
|
||||
print('playlist_type: #{!playlist_type}')
|
||||
|
||||
if !playlist_type=='5' then
|
||||
print('livesession')
|
||||
system("./notify.sh --playing --playlist-type=#{!playlist_type} --transmission-id=#{!transmission_id} --export-source=scheduler")
|
||||
end
|
||||
|
||||
if !playlist_type=='6' then
|
||||
print('couchcaster')
|
||||
system("./notify.sh --playing --playlist-type=#{!playlist_type} --transmission-id=#{!transmission_id} --export-source=scheduler")
|
||||
end
|
||||
|
||||
if !playlist_type=='0' or !playlist_type=='1' or !playlist_type=='2' or !playlist_type=='3' or !playlist_type=='4' then
|
||||
print('playlist')
|
||||
system("./notify.sh --playing --playlist-type=#{!playlist_type} --media-id=#{m['media_id']} --export-source=#{m['export_source']}")
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,77 @@
|
|||
|
||||
#########################################
|
||||
# A/B queue-setup Scheduler
|
||||
#########################################
|
||||
|
||||
# a/b queue setup
|
||||
scheduler_q0 = request.queue(conservative=true,length=600.,id="scheduler_q0")
|
||||
scheduler_q1 = request.queue(conservative=true,length=600.,id="scheduler_q1")
|
||||
|
||||
scheduler_q0 = audio_to_stereo(scheduler_q0)
|
||||
scheduler_q1 = audio_to_stereo(scheduler_q1)
|
||||
|
||||
scheduler_active = ref 0
|
||||
scheduler_queue = ref 1
|
||||
scheduler_q0_enabled = ref false
|
||||
scheduler_q1_enabled = ref false
|
||||
|
||||
# push function, enqueues file in inactive queue (does not start automatically)
|
||||
def scheduler_push(s)
|
||||
list.hd(server.execute("scheduler_q#{!scheduler_queue}.push #{s}"))
|
||||
print('push to #{!scheduler_queue} - #{s}')
|
||||
"Done"
|
||||
end
|
||||
|
||||
|
||||
# flips the queues
|
||||
def scheduler_flip()
|
||||
|
||||
# set a/b-queue corresponding to active, see fallback below
|
||||
if !scheduler_active==1 then scheduler_q0_enabled:=true else scheduler_q0_enabled:=false end
|
||||
if !scheduler_active==0 then scheduler_q1_enabled:=true else scheduler_q1_enabled:=false end
|
||||
|
||||
# get playing (active) queue and flush it
|
||||
l = list.hd(server.execute("scheduler_q#{!scheduler_active}.queue"))
|
||||
l = string.split(separator=" ",l)
|
||||
list.iter(fun (rid) -> ignore(server.execute("scheduler_q#{!scheduler_active}.ignore #{rid}")), l)
|
||||
|
||||
# skip the playing item
|
||||
source.skip(if !scheduler_active==0 then scheduler_q0 else scheduler_q1 end)
|
||||
|
||||
# flip variables
|
||||
scheduler_active := 1-!scheduler_active
|
||||
scheduler_queue := 1-!scheduler_active
|
||||
|
||||
|
||||
"Done"
|
||||
end
|
||||
|
||||
|
||||
# print status
|
||||
def scheduler_status()
|
||||
print('scheduler_active: #{!scheduler_active}')
|
||||
print('scheduler_queue : #{!scheduler_queue}')
|
||||
|
||||
print('user_id: #{!user_id}')
|
||||
print('playlist_id: #{!playlist_id}')
|
||||
print('transmission_id: #{!transmission_id}')
|
||||
print('playlist_type: #{!playlist_type}')
|
||||
|
||||
"Done"
|
||||
end
|
||||
|
||||
# register for telnet access
|
||||
server.register(namespace="scheduler","push", scheduler_push)
|
||||
server.register(namespace="scheduler","flip", fun (_) -> scheduler_flip())
|
||||
server.register(namespace="scheduler","status", fun (_) -> scheduler_status())
|
||||
|
||||
|
||||
# activate / deactivate queues, needed for fallback to work
|
||||
scheduler_q0 = switch(track_sensitive=true, [({!scheduler_q0_enabled},scheduler_q0)])
|
||||
scheduler_q1 = switch(track_sensitive=true, [({!scheduler_q1_enabled},scheduler_q1)])
|
||||
scheduler_q_holder = fallback(track_sensitive=true, [scheduler_q0, scheduler_q1])
|
||||
|
||||
|
||||
# finally the resulting scheduler source
|
||||
scheduler = fallback(track_sensitive=false, [scheduler_q_holder, default])
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
# Define a transition that fades out the
|
||||
# old source, adds a single, and then
|
||||
# plays the new source
|
||||
def to_live(jingle,old,new) =
|
||||
# Fade out old source
|
||||
old = fade.final(old)
|
||||
# Supperpose the jingle
|
||||
s = add([jingle,old])
|
||||
# Compose this in sequence with
|
||||
# the new source
|
||||
sequence([s,new])
|
||||
end
|
||||
|
||||
def to_scheduler(old,new) =
|
||||
# We skip the file
|
||||
# currently in new
|
||||
# in order to being with
|
||||
# a fresh file
|
||||
# source.skip(new)
|
||||
sequence([old,new])
|
||||
end
|
||||
|
||||
# A transition when switching back to files:
|
||||
def to_file(old,new) =
|
||||
# We skip the file
|
||||
# currently in new
|
||||
# in order to being with
|
||||
# a fresh file
|
||||
# source.skip(new)
|
||||
sequence([old,new])
|
||||
end
|
||||
|
||||
|
||||
def dp_to_scheduler(old,new) =
|
||||
old = fade.final(type='log',duration=2.1,old)
|
||||
sequence([old,new])
|
||||
end
|
|
@ -0,0 +1,149 @@
|
|||
# Decoders, enabled when the binary is detected and the os is not Win32.
|
||||
|
||||
# Get_mime is not always defined
|
||||
# so we define a default in this case..
|
||||
my_get_mime = fun (_) -> ""
|
||||
%ifdef get_mime
|
||||
my_get_mime = get_mime
|
||||
%endif
|
||||
get_mime = my_get_mime
|
||||
|
||||
%ifdef add_decoder
|
||||
if test_process("which flac") then
|
||||
log(level=3,"Found flac binary: enabling flac external decoder.")
|
||||
flac_p = "flac -d -c - 2>/dev/null"
|
||||
def test_flac(file) =
|
||||
if test_process("which metaflac") then
|
||||
channels = list.hd(get_process_lines("metaflac \
|
||||
--show-channels #{quote(file)} \
|
||||
2>/dev/null"))
|
||||
# If the value is not an int, this returns 0 and we are ok :)
|
||||
int_of_string(channels)
|
||||
else
|
||||
# Try to detect using mime test..
|
||||
mime = get_mime(file)
|
||||
if string.match(pattern="flac",file) then
|
||||
# We do not know the number of audio channels
|
||||
# so setting to -1
|
||||
(-1)
|
||||
else
|
||||
# All tests failed: no audio decodable using flac..
|
||||
0
|
||||
end
|
||||
end
|
||||
end
|
||||
add_decoder(name="FLAC",description="Decode files using the flac \
|
||||
decoder binary.", test=test_flac,flac_p)
|
||||
else
|
||||
log(level=3,"flac binary not found: flac decoder disabled.")
|
||||
end
|
||||
%endif
|
||||
|
||||
if os.type != "Win32" then
|
||||
if test_process("which metaflac") then
|
||||
log(level=3,"Found metaflac binary: enabling flac external metadata \
|
||||
resolver.")
|
||||
def flac_meta(file)
|
||||
ret = get_process_lines("metaflac --export-tags-to=- \
|
||||
#{quote(file)} 2>/dev/null")
|
||||
ret = list.map(string.split(separator="="),ret)
|
||||
# Could be made better..
|
||||
def f(l',l)=
|
||||
if list.length(l) >= 2 then
|
||||
list.append([(list.hd(l),list.nth(l,1))],l')
|
||||
else
|
||||
if list.length(l) >= 1 then
|
||||
list.append([(list.hd(l),"")],l')
|
||||
else
|
||||
l'
|
||||
end
|
||||
end
|
||||
end
|
||||
list.fold(f,[],ret)
|
||||
end
|
||||
add_metadata_resolver("FLAC",flac_meta)
|
||||
else
|
||||
log(level=3,"metaflac binary not found: flac metadata resolver disabled.")
|
||||
end
|
||||
end
|
||||
|
||||
# A list of know extensions and content-type for AAC.
|
||||
# Values from http://en.wikipedia.org/wiki/Advanced_Audio_Coding
|
||||
# TODO: can we register a setting for that ??
|
||||
aac_mimes = ["audio/aac", "audio/aacp", "audio/3gpp", "audio/3gpp2", "audio/mp4",
|
||||
"audio/MP4A-LATM", "audio/mpeg4-generic", "audio/x-hx-aac-adts"]
|
||||
aac_filexts = ["m4a", "m4b", "m4p", "m4v",
|
||||
"m4r", "3gp", "mp4", "aac"]
|
||||
|
||||
# Faad is not very selective so
|
||||
# We are checking only file that
|
||||
# end with a known extension or mime type
|
||||
def faad_test(file) =
|
||||
# Get the file's mime
|
||||
mime = get_mime(file)
|
||||
# Test mime
|
||||
if list.mem(mime,aac_mimes) then
|
||||
true
|
||||
else
|
||||
# Otherwise test file extension
|
||||
ret = string.extract(pattern='\.(.+)$',file)
|
||||
if list.length(ret) != 0 then
|
||||
ext = ret["1"]
|
||||
list.mem(ext,aac_filexts)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if os.type != "Win32" then
|
||||
if test_process("which faad") then
|
||||
log(level=3,"Found faad binary: enabling external faad decoder and \
|
||||
metadata resolver.")
|
||||
faad_p = (fun (f) -> "faad -w #{quote(f)} 2>/dev/null")
|
||||
def test_faad(file) =
|
||||
if faad_test(file) then
|
||||
channels = list.hd(get_process_lines("faad -i #{quote(file)} 2>&1 | \
|
||||
grep 'ch,'"))
|
||||
ret = string.extract(pattern=", (\d) ch,",channels)
|
||||
ret =
|
||||
if list.length(ret) == 0 then
|
||||
# If we pass the faad_test, chances are
|
||||
# high that the file will contain aac audio data..
|
||||
"-1"
|
||||
else
|
||||
ret["1"]
|
||||
end
|
||||
int_of_string(default=(-1),ret)
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
%ifdef add_oblivious_decoder
|
||||
add_oblivious_decoder(name="FAAD",description="Decode files using \
|
||||
the faad binary.", test=test_faad, faad_p)
|
||||
%endif
|
||||
def faad_meta(file) =
|
||||
if faad_test(file) then
|
||||
ret = get_process_lines("faad -i \
|
||||
#{quote(file)} 2>&1")
|
||||
# Yea, this is tuff programming (again) !
|
||||
def get_meta(l,s)=
|
||||
ret = string.extract(pattern="^(\w+):\s(.+)$",s)
|
||||
if list.length(ret) > 0 then
|
||||
list.append([(ret["1"],ret["2"])],l)
|
||||
else
|
||||
l
|
||||
end
|
||||
end
|
||||
list.fold(get_meta,[],ret)
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
add_metadata_resolver("FAAD",faad_meta)
|
||||
else
|
||||
log(level=3,"faad binary not found: faad decoder disabled.")
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
use strict ;
|
||||
|
||||
my $file = $ARGV[0] || die ;
|
||||
|
||||
sub test_mime {
|
||||
my $file = shift ;
|
||||
if (`which file`) {
|
||||
return `file -b --mime-type "$file"`;
|
||||
}
|
||||
}
|
||||
|
||||
if (($file =~ /\.mp3$/i) || (test_mime($file) =~ /audio\/mpeg/)) {
|
||||
|
||||
if (`which mp3gain`) {
|
||||
|
||||
my $out = `nice -n 20 mp3gain -q "$file" 2> /dev/null` ;
|
||||
$out =~ /Recommended "Track" dB change: (.*)$/m || die ;
|
||||
print "$1 dB\n" ;
|
||||
|
||||
} else {
|
||||
|
||||
print STDERR "Cannot find mp3gain binary!\n";
|
||||
|
||||
}
|
||||
|
||||
} elsif (($file =~ /\.ogg$/i) || (test_mime($file) =~ /application\/ogg/)) {
|
||||
|
||||
if ((`which vorbisgain`) && (`which ogginfo`)) {
|
||||
|
||||
system("nice -n 20 vorbisgain -q -f \"$file\" 2>/dev/null >/dev/null") ;
|
||||
my $info = `ogginfo "$file"` ;
|
||||
$info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/ || die ;
|
||||
print "$1 dB\n" ;
|
||||
|
||||
} else {
|
||||
|
||||
print STDERR "Cannot find vorbisgain or ogginfo!\n";
|
||||
|
||||
}
|
||||
|
||||
} elsif (($file =~ /\.flac$/i) || (test_mime($file) =~ /audio\/x-flac/)) {
|
||||
|
||||
if (`which metaflac`) {
|
||||
|
||||
my $info = `metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "$file"` ;
|
||||
$info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/;
|
||||
if (defined($1)) {
|
||||
|
||||
print "$1 dB\n" ;
|
||||
|
||||
} else {
|
||||
|
||||
system("nice -n 20 metaflac --add-replay-gain \"$file\" \
|
||||
2>/dev/null >/dev/null") ;
|
||||
$info = `metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "$file"` ;
|
||||
$info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/ || die "Error in $file" ;
|
||||
print "$1 dB\n" ;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
print STDERR "Cannot find metaflac!\n";
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
print STDERR "File format not supported...\n";
|
||||
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
|
||||
dummy = fun () -> log("Lastfm/audioscrobbler support was not compiled.")
|
||||
|
||||
%ifdef input.lastfm
|
||||
dummy = fun () -> ()
|
||||
|
||||
# Utility to compose last.fm URIs.
|
||||
# @category String
|
||||
# @param ~user Lastfm user
|
||||
# @param ~password Lastfm password
|
||||
# @param ~discovery Allow lastfm suggestions
|
||||
# @param radio URI, e.g. user/toots5446/playlist, globaltags/rocksteady.
|
||||
def lastfm.uri(~user="",~password="",~discovery=false,
|
||||
radio="globaltags/creative-commons")
|
||||
auth = if user == "" then "" else "#{user}:#{password}@" end
|
||||
discovery = if discovery == true then "1" else "0" end
|
||||
"lastfm://#{auth}#{radio}?discovery=#{discovery}"
|
||||
end
|
||||
|
||||
# Submit metadata to libre.fm using the audioscrobbler protocol.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
def librefm.submit(~user,~password,~source="broadcast",~length=false,m) =
|
||||
audioscrobbler.submit(user=user,password=password,
|
||||
source=source,length=length,
|
||||
host="turtle.libre.fm",port=80,
|
||||
m)
|
||||
end
|
||||
|
||||
# Submit metadata to lastfm.fm using the audioscrobbler protocol.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
def lastfm.submit(~user,~password,~source="broadcast",~length=false,m) =
|
||||
audioscrobbler.submit(user=user,password=password,
|
||||
source=source,length=length,
|
||||
host="post.audioscrobbler.com",port=80,
|
||||
m)
|
||||
end
|
||||
|
||||
# Submit metadata to libre.fm using the audioscrobbler protocol (nowplaying mode).
|
||||
# @category Interaction
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
def librefm.nowplaying(~user,~password,~length=false,m) =
|
||||
audioscrobbler.nowplaying(user=user,password=password,length=length,
|
||||
host="turtle.libre.fm",port=80,
|
||||
m)
|
||||
end
|
||||
|
||||
# Submit metadata to lastfm.fm using the audioscrobbler protocol (nowplaying mode).
|
||||
# @category Interaction
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
def lastfm.nowplaying(~user,~password,~length=false,m) =
|
||||
audioscrobbler.nowplaying(user=user,password=password,length=length,
|
||||
host="post.audioscrobbler.com",port=80,
|
||||
m)
|
||||
end
|
||||
|
||||
# Submit songs using audioscrobbler, respecting the full protocol:
|
||||
# First signal song as now playing when starting, and
|
||||
# then submit song when it ends.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
# @param ~delay Submit song when there is only this delay left, in seconds.
|
||||
# @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
def audioscrobbler.submit.full(
|
||||
~user,~password,
|
||||
~host="post.audioscrobbler.com",~port=80,
|
||||
~source="broadcast",~length=false,
|
||||
~delay=10.,~force=false,s) =
|
||||
f = audioscrobbler.nowplaying(
|
||||
user=user,password=password,
|
||||
host=host,port=port,length=length)
|
||||
s = on_metadata(f,s)
|
||||
f = fun (rem,m) ->
|
||||
# Avoid skipped songs
|
||||
if rem > 0. or force then
|
||||
audioscrobbler.submit(
|
||||
user=user,password=password,
|
||||
host=host,port=port,length=length,
|
||||
source=source,m)
|
||||
else
|
||||
log(label="audioscrobbler.submit.full",
|
||||
level=4,"Remaining time null: \
|
||||
will not submit song (song skipped ?)")
|
||||
end
|
||||
on_end(delay=delay,f,s)
|
||||
end
|
||||
|
||||
# Submit songs to librefm using audioscrobbler, respecting the full protocol:
|
||||
# First signal song as now playing when starting, and
|
||||
# then submit song when it ends.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
# @param ~delay Submit song when there is only this delay left, in seconds. If remaining time is less than this value, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
# @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
def librefm.submit.full(
|
||||
~user,~password,
|
||||
~source="broadcast",~length=false,
|
||||
~delay=10.,~force=false,s) =
|
||||
audioscrobbler.submit.full(
|
||||
user=user,password=password,
|
||||
source=source,length=length,
|
||||
host="turtle.libre.fm",port=80,
|
||||
delay=delay,force=force,s)
|
||||
end
|
||||
|
||||
# Submit songs to lastfm using audioscrobbler, respecting the full protocol:
|
||||
# First signal song as now playing when starting, and
|
||||
# then submit song when it ends.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
# @param ~delay Submit song when there is only this delay left, in seconds. If remaining time is less than this value, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
# @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
def lastfm.submit.full(
|
||||
~user,~password,
|
||||
~source="broadcast",~length=false,
|
||||
~delay=10.,~force=false,s) =
|
||||
audioscrobbler.submit.full(
|
||||
user=user,password=password,
|
||||
source=source,length=length,
|
||||
host="post.audioscrobbler.com",port=80,
|
||||
delay=delay,force=force,s)
|
||||
end
|
||||
|
||||
%endif
|
||||
|
||||
dummy ()
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script is called from liquidsoap for generating a file
|
||||
# for "say:voice/text" URIs.
|
||||
# Usage: liquidtts text output_file voice
|
||||
|
||||
echo $1 | /usr/bin/text2wave -f 44100 > $2.tmp.wav && /usr/bin/sox $2.tmp.wav -t wav -c 2 -r 44100 $2 2> /dev/null > /dev/null
|
||||
return=$?
|
||||
/bin/rm $2.tmp.wav
|
||||
false $2 2> /dev/null > /dev/null
|
||||
exit $return
|
|
@ -0,0 +1,4 @@
|
|||
%include "utils.liq"
|
||||
%include "externals.liq"
|
||||
%include "shoutcast.liq"
|
||||
%include "lastfm.liq"
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
%ifdef output.icecast
|
||||
# Output to shoutcast.
|
||||
# @category Source / Output
|
||||
# @param ~id Output's ID
|
||||
# @param ~start Start output threads on operator initialization.
|
||||
# @param ~restart Restart output after a failure. By default, liquidsoap will stop if the output failed.
|
||||
# @param ~restart_delay Delay, in seconds, before attempting new connection, if restart is enabled.
|
||||
# @param ~user User for shout source connection. Useful only in special cases, like with per-mountpoint users.
|
||||
# @param ~icy_reset Reset shoutcast source buffer upon connecting (necessary for NSV).
|
||||
# @param ~dumpfile Dump stream to file, for debugging purpose. Disabled if empty.
|
||||
# @param ~fallible Allow the child source to fail, in which case the output will be (temporarily) stopped.
|
||||
# @param ~on_start Callback executed when outputting starts.
|
||||
# @param ~on_stop Callback executed when outputting stops.
|
||||
# @param ~on_connect Callback executed when connection starts.
|
||||
# @param ~on_disconnect Callback executed when connection stops.
|
||||
# @param ~icy_metadata Send new metadata using the ICY protocol. One of: "guess", "true", "false"
|
||||
# @param ~format Format, e.g. "audio/ogg". When empty, the encoder is used to guess.
|
||||
# @param e Endoding format. For shoutcast, should be mp3 or AAC(+).
|
||||
# @param s The source to output
|
||||
def output.shoutcast(
|
||||
~id="output.shoutcast",~start=true,
|
||||
~restart=false,~restart_delay=3,
|
||||
~host="localhost",~port=8000,
|
||||
~user="source",~password="hackme",
|
||||
~genre="Misc",~url="http://savonet.sf.net/",
|
||||
~name="OCaml Radio!",~public=true, ~format="",
|
||||
~dumpfile="", ~icy_metadata="guess",
|
||||
~on_connect={()}, ~on_disconnect={()},
|
||||
~aim="",~icq="",~irc="",~icy_reset=true,
|
||||
~fallible=false,~on_start={()},~on_stop={()},
|
||||
e,s) =
|
||||
icy_reset = if icy_reset then "1" else "0" end
|
||||
headers = [("icy-aim",aim),("icy-irc",irc),
|
||||
("icy-icq",icq),("icy-reset",icy_reset)]
|
||||
output.icecast(
|
||||
e, format=format,
|
||||
id=id, headers=headers,
|
||||
start=start,icy_metadata=icy_metadata,
|
||||
on_connect=on_connect, on_disconnect=on_disconnect,
|
||||
restart=restart, restart_delay=restart_delay,
|
||||
host=host, port=port, user=user, password=password,
|
||||
genre=genre, url=url, description="UNUSED",
|
||||
public=public, dumpfile=dumpfile,
|
||||
name=name, mount="/", protocol="icy",
|
||||
fallible=fallible,on_start=on_start,on_stop=on_stop,
|
||||
s)
|
||||
end
|
||||
%endif
|
|
@ -0,0 +1,578 @@
|
|||
|
||||
# Turn a source into an infaillible source.
|
||||
# by adding blank when the source is not available.
|
||||
# @param s the source to turn infaillible
|
||||
# @category Source / Input
|
||||
def mksafe(s)
|
||||
fallback(id="mksafe",track_sensitive=false,[s,blank(id="safe_blank")])
|
||||
end
|
||||
|
||||
# Alias for the <code>l[k]</code> notation.
|
||||
# @category List
|
||||
# @param a Key to look for
|
||||
# @param l List of pairs (key,value)
|
||||
def list.assoc(a,l)
|
||||
l[a]
|
||||
end
|
||||
|
||||
# list.mem_assoc(key,l) returns true if l contains a pair
|
||||
# (key,value)
|
||||
# @category List
|
||||
# @param a Key to look for
|
||||
# @param l List of pairs (key,value)
|
||||
def list.mem_assoc(a,l)
|
||||
v = list.assoc(a,l)
|
||||
# We check for existence, since "" may indicate
|
||||
# either a binding (a,"") or no binding..
|
||||
list.mem((a,v),l)
|
||||
end
|
||||
|
||||
# Remove a pair from an associative list
|
||||
# @category List
|
||||
# @param a Key of pair to be removed
|
||||
# @param l List of pairs (key,value)
|
||||
def list.remove_assoc(a,l)
|
||||
list.remove((a,list.assoc(a,l)),l)
|
||||
end
|
||||
|
||||
# Rewrite metadata on the fly using a list of (target,rules).
|
||||
# @category Source / Track Processing
|
||||
# @param l \
|
||||
# List of (target,value) rewriting rules.
|
||||
# @param ~insert_missing \
|
||||
# Treat track beginnings without metadata as having empty ones. \
|
||||
# The operational order is: \
|
||||
# create empty if needed, map and strip if enabled.
|
||||
# @param ~update \
|
||||
# Only update metadata. \
|
||||
# If false, only returned values will be set as metadata.
|
||||
# @param ~strip \
|
||||
# Completly remove empty metadata. \
|
||||
# Operates on both empty values and empty metadata chunk.
|
||||
def rewrite_metadata(l,~insert_missing=true,
|
||||
~update=true,~strip=false,
|
||||
s)
|
||||
# We don't need to return all values, since
|
||||
# map_metadata only update returned values.
|
||||
# So, we simply apply all rewrite rules !
|
||||
def map(m)
|
||||
def apply(x)
|
||||
label = fst(x)
|
||||
value = snd(x)
|
||||
(label,value % m)
|
||||
end
|
||||
list.map(apply,l)
|
||||
end
|
||||
map_metadata(map,insert_missing=insert_missing,
|
||||
update=update,strip=strip,s)
|
||||
end
|
||||
|
||||
# Add a skip function to a source
|
||||
# when it does not have one
|
||||
# by default
|
||||
# @category Interaction
|
||||
# @param s The source to attach the command to.
|
||||
def add_skip_command(s) =
|
||||
# A command to skip
|
||||
def skip(_) =
|
||||
source.skip(s)
|
||||
"Done!"
|
||||
end
|
||||
# Register the command:
|
||||
server.register(namespace="#{source.id(s)}",
|
||||
usage="skip",
|
||||
description="Skip the current song.",
|
||||
"skip",skip)
|
||||
end
|
||||
|
||||
# Removes all metadata coming from a source
|
||||
# @category Source / Track Processing
|
||||
def clear_metadata(s)
|
||||
def map(m)
|
||||
[]
|
||||
end
|
||||
map_metadata(map,update=false,strip=true,s)
|
||||
end
|
||||
|
||||
output.prefered=output.dummy
|
||||
%ifdef output.oss
|
||||
output.prefered=output.oss
|
||||
%endif
|
||||
%ifdef output.alsa
|
||||
output.prefered=output.alsa
|
||||
%endif
|
||||
%ifdef output.pulseaudio
|
||||
output.prefered=output.pulseaudio
|
||||
%endif
|
||||
%ifdef output.ao
|
||||
output.prefered=output.ao
|
||||
%endif
|
||||
# Output to local audio card using the first available driver in this list:
|
||||
# ao, pulseaudio, alsa, oss, dummy
|
||||
# @category Source / Output
|
||||
def output.prefered(~id="",s)
|
||||
output.prefered(id=id,s)
|
||||
end
|
||||
|
||||
in = fun () -> blank()
|
||||
%ifdef input.oss
|
||||
in = fun () -> input.oss(id="oss_mic")
|
||||
%endif
|
||||
%ifdef input.alsa
|
||||
in = fun () -> input.alsa(id="alsa_mic")
|
||||
%endif
|
||||
%ifdef input.portaudio
|
||||
in = fun () -> input.portaudio(id="pa_mic")
|
||||
%endif
|
||||
# Create a source from the first available input driver in this list:
|
||||
# portaudio, alsa, oss, blank
|
||||
# @category Source / Input
|
||||
def in()
|
||||
in()
|
||||
end
|
||||
|
||||
# Output a stream using the 'output.prefered' operator. The input source does
|
||||
# not need to be infallible, blank will just be played during failures.
|
||||
# @param s the source to output
|
||||
# @category Source / Output
|
||||
def out(s)
|
||||
output.prefered(mksafe(s))
|
||||
end
|
||||
|
||||
# Special track insensitive fallback that
|
||||
# always skip current song before switching.
|
||||
# @category Source / Track Processing
|
||||
# @param ~input The input source
|
||||
# @param f The fallback source
|
||||
def fallback.skip(~input,f)
|
||||
def transition(a,b) =
|
||||
source.skip(a)
|
||||
# This eats the last remaining frame from a
|
||||
sequence([a,b])
|
||||
end
|
||||
fallback(track_sensitive=false,transitions=[transition,transition],[input,f])
|
||||
end
|
||||
|
||||
# Compress and normalize, producing a more uniform and "full" sound.
|
||||
# @category Source / Sound Processing
|
||||
# @param s The input source.
|
||||
def nrj(s)
|
||||
compress(threshold=-15.,ratio=3.,gain=3.,normalize(s))
|
||||
end
|
||||
|
||||
# Multiband-compression.
|
||||
# @category Source / Sound Processing
|
||||
# @param s The input source.
|
||||
def sky(s)
|
||||
# 3-band crossover
|
||||
low = filter.iir.eq.low(frequency = 168.)
|
||||
mh = filter.iir.eq.high(frequency = 100.)
|
||||
mid = filter.iir.eq.low(frequency = 1800.)
|
||||
high = filter.iir.eq.high(frequency = 1366.)
|
||||
|
||||
# Add back
|
||||
add(normalize = false,
|
||||
[ compress(attack = 100., release = 200., threshold = -20.,
|
||||
ratio = 6., gain = 6.7, knee = 0.3,
|
||||
low(s)),
|
||||
compress(attack = 100., release = 200., threshold = -20.,
|
||||
ratio = 6., gain = 6.7, knee = 0.3,
|
||||
mid(mh(s))),
|
||||
compress(attack = 100., release = 200., threshold = -20.,
|
||||
ratio = 6., gain = 6.7, knee = 0.3,
|
||||
high(s))
|
||||
])
|
||||
end
|
||||
|
||||
# Simple crossfade.
|
||||
# @category Source / Track Processing
|
||||
# @param ~start_next Duration in seconds of the crossed end of track.
|
||||
# @param ~fade_in Duration of the fade in for next track
|
||||
# @param ~fade_out Duration of the fade out for previous track
|
||||
# @param s The source to use
|
||||
def crossfade(~id="",~start_next,~fade_in,~fade_out,s)
|
||||
s = fade.in(duration=fade_in,s)
|
||||
s = fade.out(duration=fade_out,s)
|
||||
fader = fun (a,b) -> add(normalize=false,[b,a])
|
||||
cross(id=id,conservative=true,duration=start_next,fader,s)
|
||||
end
|
||||
|
||||
# Append speech-synthesized tracks reading the metadata.
|
||||
# @category Source / Track Processing
|
||||
# @param ~pattern Pattern to use
|
||||
# @param s The source to use
|
||||
def say_metadata
|
||||
p = 'say:$(if $(artist),"It was $(artist)$(if $(title),\", $(title)\").")'
|
||||
fun (s,~pattern=p) ->
|
||||
append(s,fun (m) -> request.queue(queue=[request.create(pattern % m)],
|
||||
interactive=false))
|
||||
end
|
||||
|
||||
# Relay the audio stream of Dolebraï, a libre music netradio running liquidsoap.
|
||||
# @category Source / Input
|
||||
def dolebrai ()
|
||||
input.http(id="dolebrai","http://dolebrai.net:8000/dolebrai.ogg")
|
||||
end
|
||||
|
||||
%ifdef soundtouch
|
||||
# Increases the pitch, making voices sound like on helium.
|
||||
# @category Source / Sound Processing
|
||||
# @param s The input source.
|
||||
def helium(s)
|
||||
soundtouch(pitch=1.5,s)
|
||||
end
|
||||
%endif
|
||||
|
||||
# Return true if process exited with 0 code.
|
||||
# Command should return quickly.
|
||||
# @category System
|
||||
# @param command Command to test
|
||||
def test_process(command)
|
||||
lines =
|
||||
get_process_lines("(" ^ command ^ " >/dev/null 2>&1 && echo 0) || echo 1")
|
||||
if list.length(lines) == 0 then
|
||||
false
|
||||
else
|
||||
"0" == list.hd(lines)
|
||||
end
|
||||
end
|
||||
|
||||
# Get the base name of a path.
|
||||
# Implemented using the corresponding shell command.
|
||||
# @category System
|
||||
# @param s Path
|
||||
def basename(s)
|
||||
lines = get_process_lines("basename #{quote(s)}")
|
||||
if list.length(lines) > 0 then
|
||||
list.hd(lines)
|
||||
else
|
||||
# Don't know what to do.. output s
|
||||
s
|
||||
end
|
||||
end
|
||||
|
||||
# Get the directory name of a path.
|
||||
# Implemented using the corresponding shell command.
|
||||
# @category System
|
||||
# @param s Path
|
||||
# @param ~default Value returned in case of error.
|
||||
def dirname(~default="/nonexistent",s)
|
||||
lines = get_process_lines("dirname #{quote(s)}")
|
||||
if list.length(lines) > 0 then
|
||||
list.hd(lines)
|
||||
else
|
||||
default
|
||||
end
|
||||
end
|
||||
|
||||
# Read some value from standard input (console).
|
||||
# @category System
|
||||
# @param ~hide Hide typed characters (for passwords).
|
||||
def read(~hide=false)
|
||||
if hide then
|
||||
system("stty -echo")
|
||||
end
|
||||
s = list.hd(get_process_lines("read BLA && echo $BLA"))
|
||||
if hide then
|
||||
system("stty echo")
|
||||
end
|
||||
print("")
|
||||
s
|
||||
end
|
||||
|
||||
# Generic mime test. First try to use file.mime if it exist.
|
||||
# Otherwise try to get the value using the file binary.
|
||||
# Returns "" (empty string) if no value can be find.
|
||||
# @category System
|
||||
# @param file The file to test
|
||||
def get_mime(file) =
|
||||
def file_method(file) =
|
||||
if test_process("which file") then
|
||||
list.hd(get_process_lines("file -b --mime-type \
|
||||
#{quote(file)}"))
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
def mime_method(file) =
|
||||
ret = ""
|
||||
%ifdef file.mime
|
||||
ret = file.mime(file)
|
||||
%endif
|
||||
ret
|
||||
end
|
||||
# First try mime method
|
||||
ret = mime_method(file)
|
||||
if ret != "" then
|
||||
ret
|
||||
else
|
||||
# Now try file method
|
||||
file_method(file)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Remove low frequencies often produced by microphones.
|
||||
# @category Source / Sound Processing
|
||||
# @param s The input source.
|
||||
def mic_filter(s)
|
||||
filter(freq=200.,q=1.,mode="high",s)
|
||||
end
|
||||
|
||||
# Creates a source that fails to produce anything.
|
||||
# @category Source / Input
|
||||
def fail()
|
||||
fallback([])
|
||||
end
|
||||
|
||||
# Creates a source that plays only one track of the input source.
|
||||
# @category Source / Track Processing
|
||||
# @param s The input source.
|
||||
def once(s)
|
||||
sequence([s,fail()])
|
||||
end
|
||||
|
||||
# Crossfade between tracks, taking the respective volume levels into account in
|
||||
# the choice of the transition.
|
||||
# @category Source / Track Processing
|
||||
# @param ~start_next Crossing duration, if any.
|
||||
# @param ~fade_in Fade-in duration, if any.
|
||||
# @param ~fade_out Fade-out duration, if any.
|
||||
# @param ~width Width of the volume analysis window.
|
||||
# @param ~conservative Always prepare for a premature end-of-track.
|
||||
# @param ~default Transition used when no rule applies \
|
||||
# (default: sequence).
|
||||
# @param ~high Value, in dB, for loud sound level
|
||||
# @param ~medium Value, in dB, for medium sound level
|
||||
# @param ~margin Margin to detect sources that have too different \
|
||||
# sound level for crossing.
|
||||
# @param s The input source.
|
||||
def smart_crossfade (~start_next=5.,~fade_in=3.,~fade_out=3.,
|
||||
~default=(fun (a,b) -> sequence([a, b])),
|
||||
~high=-15., ~medium=-32., ~margin=4.,
|
||||
~width=2.,~conservative=false,s)
|
||||
fade.out = fade.out(type="sin",duration=fade_out)
|
||||
fade.in = fade.in(type="sin",duration=fade_in)
|
||||
add = fun (a,b) -> add(normalize=false,[b, a])
|
||||
log = log(label="smart_crossfade")
|
||||
|
||||
def transition(a,b,ma,mb,sa,sb)
|
||||
|
||||
list.iter(fun(x)-> log(level=4,"Before: #{x}"),ma)
|
||||
list.iter(fun(x)-> log(level=4,"After : #{x}"),mb)
|
||||
|
||||
if
|
||||
# If A and B are not too loud and close, fully cross-fade them.
|
||||
a <= medium and b <= medium and abs(a - b) <= margin
|
||||
then
|
||||
log("Old <= medium, new <= medium and |old-new| <= margin.")
|
||||
log("Old and new source are not too loud and close.")
|
||||
log("Transition: crossed, fade-in, fade-out.")
|
||||
add(fade.out(sa),fade.in(sb))
|
||||
|
||||
elsif
|
||||
# If B is significantly louder than A, only fade-out A.
|
||||
# We don't want to fade almost silent things, ask for >medium.
|
||||
b >= a + margin and a >= medium and b <= high
|
||||
then
|
||||
log("new >= old + margin, old >= medium and new <= high.")
|
||||
log("New source is significantly louder than old one.")
|
||||
log("Transition: crossed, fade-out.")
|
||||
add(fade.out(sa),sb)
|
||||
|
||||
elsif
|
||||
# Opposite as the previous one.
|
||||
a >= b + margin and b >= medium and a <= high
|
||||
then
|
||||
log("old >= new + margin, new >= medium and old <= high")
|
||||
log("Old source is significantly louder than new one.")
|
||||
log("Transition: crossed, fade-in.")
|
||||
add(sa,fade.in(sb))
|
||||
|
||||
elsif
|
||||
# Do not fade if it's already very low.
|
||||
b >= a + margin and a <= medium and b <= high
|
||||
then
|
||||
log("new >= old + margin, old <= medium and new <= high.")
|
||||
log("Do not fade if it's already very low.")
|
||||
log("Transition: crossed, no fade.")
|
||||
add(sa,sb)
|
||||
|
||||
# What to do with a loud end and a quiet beginning ?
|
||||
# A good idea is to use a jingle to separate the two tracks,
|
||||
# but that's another story.
|
||||
|
||||
else
|
||||
# Otherwise, A and B are just too loud to overlap nicely,
|
||||
# or the difference between them is too large and overlapping would
|
||||
# completely mask one of them.
|
||||
log("No transition: using default.")
|
||||
default(sa, sb)
|
||||
end
|
||||
end
|
||||
|
||||
smart_cross(width=width, duration=start_next, conservative=conservative,
|
||||
transition,s)
|
||||
end
|
||||
|
||||
# Custom playlist source written using the script language.
|
||||
# Will read directory or playlist, play all files and stop
|
||||
# @category Source / Input
|
||||
# @param ~random Randomize playlist content
|
||||
# @param ~on_done Function to execute when the playlist is finished
|
||||
# @param uri Playlist URI
|
||||
def playlist.once(~random=false,~on_done={()},uri)
|
||||
x = ref 0
|
||||
def playlist.custom(files)
|
||||
length = list.length(files)
|
||||
if length == 0 then
|
||||
log("Empty playlist..")
|
||||
fail ()
|
||||
else
|
||||
files =
|
||||
if random then
|
||||
list.sort(fun (x,y) -> int_of_float(random.float()), files)
|
||||
else
|
||||
files
|
||||
end
|
||||
def next () =
|
||||
state = !x
|
||||
file =
|
||||
if state < length then
|
||||
x := state + 1
|
||||
list.nth(files,state)
|
||||
else
|
||||
# Playlist finished
|
||||
on_done ()
|
||||
""
|
||||
end
|
||||
request.create(file)
|
||||
end
|
||||
request.dynamic(next)
|
||||
end
|
||||
end
|
||||
if test_process("test -d #{quote(uri)}") then
|
||||
files = get_process_lines("find #{quote(uri)} -type f | sort")
|
||||
playlist.custom(files)
|
||||
else
|
||||
playlist = request.create.raw(uri)
|
||||
result =
|
||||
if request.resolve(playlist) then
|
||||
playlist = request.filename(playlist)
|
||||
files = playlist.parse(playlist)
|
||||
files = list.map(snd,files)
|
||||
playlist.custom(files)
|
||||
else
|
||||
log("Couldn't read playlist: request resolution failed.")
|
||||
fail ()
|
||||
end
|
||||
request.destroy(playlist)
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
# Mixes two streams, with faded transitions between the state when only the
|
||||
# normal stream is available and when the special stream gets added on top of
|
||||
# it.
|
||||
# @category Source / Track Processing
|
||||
# @param ~delay Delay before starting the special source.
|
||||
# @param ~p Portion of amplitude of the normal source in the mix.
|
||||
# @param ~normal The normal source, which could be called the carrier too.
|
||||
# @param ~special The special source.
|
||||
def smooth_add(~delay=0.5,~p=0.2,~normal,~special)
|
||||
d = delay
|
||||
fade.final = fade.final(duration=d*2.)
|
||||
fade.initial = fade.initial(duration=d*2.)
|
||||
q = 1. - p
|
||||
c = amplify
|
||||
fallback(track_sensitive=false,
|
||||
[special,normal],
|
||||
transitions=[
|
||||
fun(normal,special)->
|
||||
add(normalize=false,
|
||||
[c(p,normal),
|
||||
c(q,fade.final(type="sin",normal)),
|
||||
sequence([blank(duration=d),c(q,special)])]),
|
||||
fun(special,normal)->
|
||||
add(normalize=false,
|
||||
[c(p,normal),
|
||||
c(q,fade.initial(type="sin",normal))])
|
||||
])
|
||||
end
|
||||
|
||||
# Restrict a source to play only when a predicate is true.
|
||||
# @category Source / Track Processing
|
||||
# @param pred The predicate, typically a time interval such as \
|
||||
# <code>{10h-10h30}</code>.
|
||||
def at(pred,s)
|
||||
switch([(pred,s)])
|
||||
end
|
||||
|
||||
# Execute a given action when a predicate is true.
|
||||
# This will be run in background.
|
||||
# @category System
|
||||
# @param ~freq Frequency for checking the predicate, in seconds.
|
||||
# @param ~pred Predicate indicating when to execute the function, \
|
||||
# typically a time interval such as <code>{10h-10h30}</code>.
|
||||
# @param f Function to execute when the predicate is true.
|
||||
def exec_at(~freq=1.,~pred,f)
|
||||
def check()
|
||||
if pred() then
|
||||
f()
|
||||
end
|
||||
freq
|
||||
end
|
||||
add_timeout(freq,check)
|
||||
end
|
||||
|
||||
# Register the replaygain protocol
|
||||
def replaygain_protocol(arg,delay)
|
||||
# The extraction program
|
||||
extract_replaygain = "#{configure.libdir}/extract-replaygain"
|
||||
x = get_process_lines("#{extract_replaygain} #{quote(arg)}")
|
||||
if list.hd(x) != "" then
|
||||
["annotate:replay_gain=\"#{list.hd(x)}\":#{arg}"]
|
||||
else
|
||||
[arg]
|
||||
end
|
||||
end
|
||||
add_protocol("replay_gain", replaygain_protocol)
|
||||
|
||||
# Enable replay gain metadata resolver. This resolver will
|
||||
# process any file decoded by liquidsoap and add a @replay_gain@
|
||||
# metadata when this value could be computed. For a finer-grained
|
||||
# replay gain processing, use the @replay_gain@ protocol.
|
||||
# @category Liquidsoap
|
||||
# @param ~extract_replaygain The extraction program
|
||||
def enable_replaygain_metadata(
|
||||
~extract_replaygain="#{configure.libdir}/extract-replaygain")
|
||||
def replaygain_metadata(file)
|
||||
x = get_process_lines("#{extract_replaygain} \
|
||||
#{quote(file)}")
|
||||
if list.hd(x) != "" then
|
||||
[("replay_gain",list.hd(x))]
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
add_metadata_resolver("replay_gain", replaygain_metadata)
|
||||
end
|
||||
|
||||
# Create a log of clock times for all the clocks initially present.
|
||||
# The log is in simple format, which you can notably directly use with gnuplot.
|
||||
# @category Liquidsoap
|
||||
# @param ~interval Polling interval.
|
||||
def log_clocks(~interval=1.,logfile)
|
||||
# Get the current clocks
|
||||
clocks = list.map(fst,get_clock_status())
|
||||
# Column headers
|
||||
system("echo \# #{string.concat(separator=' ',clocks)} > #{logfile}")
|
||||
def report()
|
||||
status = get_clock_status()
|
||||
status = list.map(fun (x) -> (fst(x),string_of(snd(x))), status)
|
||||
status = list.map(fun (c) -> status[c], clocks)
|
||||
system("echo #{string.concat(separator=' ',status)} >> #{logfile}")
|
||||
interval
|
||||
end
|
||||
add_timeout(interval,report)
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
DATE=$(date '+%Y-%m-%d')
|
||||
CI_LOG=/var/log/obp/ci/log-$DATE.php
|
||||
|
||||
clear
|
||||
echo
|
||||
echo "##############################"
|
||||
echo "# STARTING PYPO MULTI-LOG #"
|
||||
echo "##############################"
|
||||
sleep 1
|
||||
clear
|
||||
|
||||
# split
|
||||
multitail -s 2 -cS pyml /var/log/obp/pypo/debug.log \
|
||||
-cS pyml /var/log/obp/pypo/error.log \
|
||||
-l "tail -f -n 50 $CI_LOG | grep API" \
|
||||
/var/log/obp/ls/ls_script.log
|
|
@ -0,0 +1,49 @@
|
|||
###########################################
|
||||
# liquidsoap config file #
|
||||
###########################################
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
|
||||
# this file is specific to the obp
|
||||
# installation. eg it assumes that there are
|
||||
# two instances of LS running
|
||||
# the "scheduler" & the "fallback" instance
|
||||
|
||||
|
||||
###########################################
|
||||
# general settings #
|
||||
###########################################
|
||||
|
||||
log_file = "/var/log/obp/ls/<script>.log"
|
||||
log_level = 3
|
||||
|
||||
# archive directory
|
||||
archive_dir = "/storage/pypo/archive/"
|
||||
|
||||
|
||||
# list pointing to the current couchcaster mountpoint
|
||||
couchcaster_list = "http://vdeb.openbroadcast.ch/mod/ml/api/pypo/current_couchcaster"
|
||||
|
||||
|
||||
|
||||
###########################################
|
||||
# stream settings #
|
||||
###########################################
|
||||
icecast_host = "172.16.16.128"
|
||||
icecast_port = 8000
|
||||
icecast_pass = "hackme"
|
||||
|
||||
# mountpoints
|
||||
mount_scheduler = "pypo_scheduler.mp3"
|
||||
mount_fallback = "pypo_fallback.mp3"
|
||||
mount_final = "pypo_final.mp3"
|
||||
|
||||
# mount intra is used for scheduler >>> fallback stream
|
||||
mount_intra = "pypo_intra"
|
||||
|
||||
# intra-LS streaming (no icecast here)
|
||||
intra_host = "172.16.16.128"
|
||||
intra_port = 9000
|
||||
intra_pass = "hackme"
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
###########################################
|
||||
# liquidsoap config file #
|
||||
###########################################
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
|
||||
# this file is specific to the obp
|
||||
# installation. eg it assumes that there are
|
||||
# two instances of LS running
|
||||
# the "scheduler" & the "fallback" instance
|
||||
|
||||
|
||||
###########################################
|
||||
# general settings #
|
||||
###########################################
|
||||
|
||||
log_file = "/var/log/obp/ls/<script>.log"
|
||||
log_level = 5
|
||||
|
||||
# archive directory
|
||||
archive_dir = "/storage/pypo/archive/"
|
||||
|
||||
|
||||
# list pointing to the current couchcaster mountpoint
|
||||
couchcaster_list = "http://stage.openbroadcast.ch/mod/ml/api/pypo/current_couchcaster"
|
||||
|
||||
|
||||
|
||||
###########################################
|
||||
# stream settings #
|
||||
###########################################
|
||||
icecast_host = "stream.domain.com"
|
||||
icecast_port = 8000
|
||||
icecast_pass = "hackme"
|
||||
|
||||
# mountpoints
|
||||
mount_scheduler = "pypo_scheduler.mp3"
|
||||
mount_fallback = "pypo_fallback.mp3"
|
||||
mount_final = "pypo_final.mp3"
|
||||
|
||||
# mount intra is used for scheduler >>> fallback stream
|
||||
mount_intra = "pypo_intra"
|
||||
|
||||
# intra-LS streaming (no icecast here)
|
||||
intra_host = "pypo-fallback.my-playout-server.xyz.net"
|
||||
intra_port = 9000
|
||||
intra_pass = "hackmetoo"
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
# Register the cut protocol
|
||||
def cue_protocol(arg,delay)
|
||||
# The extraction program
|
||||
# cut_file = "#{configure.libdir}/cut-file.py"
|
||||
cue_script = "./cue_file.py"
|
||||
# Parse args
|
||||
ret = string.extract(pattern="cue_in=(\d+)",arg)
|
||||
start =
|
||||
if list.length(ret) == 0 then
|
||||
"0"
|
||||
else
|
||||
ret["1"]
|
||||
end
|
||||
ret = string.extract(pattern="cue_out=(\d+)",arg)
|
||||
stop =
|
||||
if list.length(ret) == 0 then
|
||||
"0"
|
||||
else
|
||||
ret["1"]
|
||||
end
|
||||
ret = string.extract(pattern=":(.*)$",arg)
|
||||
uri =
|
||||
if list.length(ret) == 0 then
|
||||
""
|
||||
else
|
||||
ret["1"]
|
||||
end
|
||||
x = get_process_lines("#{cue_script} #{quote(uri)} #{start} #{stop}")
|
||||
if list.hd(x) != "" then
|
||||
([list.hd(x)],[])
|
||||
else
|
||||
([uri],[])
|
||||
end
|
||||
end
|
||||
add_post_processor("cue_file", temporary=true, cue_protocol)
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
# export home dir
|
||||
export HOME=/home/liquidsoap/
|
||||
|
||||
# start liquidsoap with corresponding user & scrupt
|
||||
sudo -u liquidsoap /usr/local/bin/liquidsoap ls_script.liq
|
|
@ -0,0 +1,154 @@
|
|||
######################################
|
||||
# main liquidsoap development script #
|
||||
######################################
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
########################################
|
||||
# include configuration #
|
||||
########################################
|
||||
|
||||
%include "ls_config.liq"
|
||||
%include "library.liq"
|
||||
|
||||
%include "include_dynamic_vars.liq"
|
||||
%include "include_notify.liq"
|
||||
|
||||
|
||||
silence_threshold = -50.
|
||||
silence_time = 3.
|
||||
|
||||
|
||||
# log
|
||||
set("log.file.path",log_file)
|
||||
set("log.stdout", true)
|
||||
set("log.level",log_level)
|
||||
|
||||
# telnet server
|
||||
set("server.telnet", true)
|
||||
|
||||
|
||||
|
||||
######################################
|
||||
# some functions needed #
|
||||
######################################
|
||||
|
||||
def fcross(a,b) =
|
||||
add(normalize=false,[b,a])
|
||||
end
|
||||
|
||||
|
||||
######################################
|
||||
# live recording functions
|
||||
######################################
|
||||
def live_start() =
|
||||
log("got live source")
|
||||
ignore(execute("archives.start"))
|
||||
end
|
||||
|
||||
def live_stop() =
|
||||
log("live source has gone")
|
||||
ignore(execute("archives.stop"))
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# File locations / sources
|
||||
#######################################################################
|
||||
|
||||
silence = single("/storage/pypo/files/basic/silence.mp3")
|
||||
jingles_cc = playlist("/storage/pypo/files/jingles/jcc")
|
||||
fallback_couchcaster = playlist("/storage/pypo/files/fallback_couchcaster")
|
||||
fallback_couchcaster = audio_to_stereo(fallback_couchcaster)
|
||||
|
||||
# default
|
||||
default = silence
|
||||
|
||||
special = request.queue(id="special")
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# Includeing two A/B Queues, daypart & scheduler
|
||||
# this will give us the sources 'daypart' & 'scheduler'
|
||||
#######################################################################
|
||||
|
||||
%include "include_daypart.liq"
|
||||
|
||||
%include "include_scheduler.liq"
|
||||
|
||||
|
||||
source = fallback(track_sensitive=false,transitions=[dp_to_scheduler],[strip_blank(threshold=silence_threshold,length=silence_time,scheduler),daypart])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
%include "include_live_in.liq"
|
||||
|
||||
|
||||
|
||||
live = fallback(track_sensitive=false,[strip_blank(threshold=silence_threshold,length=silence_time,live),fallback_couchcaster])
|
||||
live = switch(track_sensitive=false, [({!live_active},live)])
|
||||
|
||||
source = fallback(track_sensitive=false,transitions=[to_live_s, to_scheduler_s],[live, source])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# handle the annotate fades
|
||||
faded = fade.in(type="log", fade.out(type="log", source))
|
||||
|
||||
# add up with a crossfade function (defined above)
|
||||
source = cross(fcross,faded)
|
||||
|
||||
|
||||
# track start detection (for notifications)
|
||||
source = on_metadata(notify, source)
|
||||
#source = on_track(notify, source)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# special to mix with final source
|
||||
source = smooth_add(normal=source,special=special)
|
||||
|
||||
|
||||
|
||||
|
||||
#####################################
|
||||
# Stream Output
|
||||
#####################################
|
||||
# finally the output | mp3
|
||||
clock(id="clock_icecast",
|
||||
output.icecast(%mp3,
|
||||
host = icecast_host, port = icecast_port,
|
||||
password = icecast_pass, mount = mount_scheduler,
|
||||
fallible = true,
|
||||
restart = true,
|
||||
restart_delay = 5,
|
||||
buffer(source)))
|
||||
|
||||
|
||||
|
||||
#output.dummy(live_in)
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
############################################
|
||||
# just a wrapper to call the notifyer #
|
||||
# needed here to keep dirs/configs clean #
|
||||
# and maybe to set user-rights #
|
||||
############################################
|
||||
cd ../
|
||||
./pypo_notify.py $1 $2 $3 $4 $5 $6 $7 $8 &
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
|
||||
clear
|
||||
echo
|
||||
echo "##############################"
|
||||
echo "# STARTING PYPO MULTI-LOG #"
|
||||
echo "##############################"
|
||||
sleep 1
|
||||
clear
|
||||
|
||||
# split
|
||||
multitail -s 2 /var/log/obp/pypo/debug.log \
|
||||
/var/svc.d/pypo_push/log/main/current \
|
||||
/var/svc.d/pypo_fetch/log/main/current \
|
||||
/var/svc.d/pypo_ls/log/main/current
|
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from json import *
|
||||
from status import *
|
||||
from cue_file import *
|
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
import sys
|
||||
import shutil
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from datetime import timedelta
|
||||
import os
|
||||
import logging
|
||||
|
||||
from mutagen.mp3 import MP3
|
||||
|
||||
|
||||
class CueFile():
|
||||
|
||||
def __init__(self):
|
||||
logger = logging.getLogger("cue_file")
|
||||
logger.debug("init")
|
||||
|
||||
def cue(self, src, dst, cue_in, cue_out):
|
||||
|
||||
logger = logging.getLogger("cue_file.cue")
|
||||
logger.debug("cue file: %s %s %s %s", src, dst, cue_in, cue_out)
|
||||
|
||||
# mutagen
|
||||
audio = MP3(src)
|
||||
dur = round(audio.info.length, 3)
|
||||
|
||||
logger.debug("duration by mutagen: %s", dur)
|
||||
|
||||
cue_out = round(float(dur) - cue_out, 3)
|
||||
|
||||
str_cue_in = str(timedelta(seconds=cue_in)).replace(".", "+") # hh:mm:ss+mss, eg 00:00:20+000
|
||||
str_cue_out = str(timedelta(seconds=cue_out)).replace(".", "+") #
|
||||
|
||||
"""
|
||||
now a bit a hackish part, don't know how to do this better...
|
||||
need to cut the digits after the "+"
|
||||
"""
|
||||
ts = str_cue_in.split("+")
|
||||
try:
|
||||
if len(ts[1]) == 6:
|
||||
ts[1] = ts[1][0:3]
|
||||
str_cue_in = "%s+%s" % (ts[0], ts[1])
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
ts = str_cue_out.split("+")
|
||||
try:
|
||||
if len(ts[1]) == 6:
|
||||
ts[1] = ts[1][0:3]
|
||||
str_cue_out = "%s+%s" % (ts[0], ts[1])
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
#sys.stderr.write(str(timedelta(seconds=cue_in)).replace(".", "+") + '\n\n')
|
||||
logger.debug("in: %s", str_cue_in)
|
||||
logger.debug("out: %s", str(str_cue_out) )
|
||||
|
||||
# command = 'mp3cut -o %s -t %s-%s %s' % (dst, str_cue_in, str_cue_out, src);
|
||||
# logger.info("command: %s", command)
|
||||
# os.system(command + ' >/dev/null')
|
||||
#
|
||||
# command = 'mp3val -f %s' % (dst);
|
||||
# logger.info("command: %s", command)
|
||||
# os.system(command + ' >/dev/null')
|
||||
|
||||
command = 'mp3cut -o %s -t %s-%s %s' % (dst + '.tmp.mp3', str_cue_in, str_cue_out, src);
|
||||
logger.info("command: %s", command)
|
||||
os.system(command + ' >/dev/null')
|
||||
|
||||
command = 'lame -b 32 %s %s' % (dst + '.tmp.mp3', dst);
|
||||
logger.info("command: %s", command)
|
||||
os.system(command + ' >/dev/null')
|
||||
|
||||
|
||||
return dst
|
|
@ -0,0 +1,310 @@
|
|||
import string
|
||||
import types
|
||||
|
||||
## json.py implements a JSON (http://json.org) reader and writer.
|
||||
## Copyright (C) 2005 Patrick D. Logan
|
||||
## Contact mailto:patrickdlogan@stardecisions.com
|
||||
##
|
||||
## This library is free software; you can redistribute it and/or
|
||||
## modify it under the terms of the GNU Lesser General Public
|
||||
## License as published by the Free Software Foundation; either
|
||||
## version 2.1 of the License, or (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
## Lesser General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Lesser General Public
|
||||
## License along with this library; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
class _StringGenerator(object):
|
||||
def __init__(self, string):
|
||||
self.string = string
|
||||
self.index = -1
|
||||
def peek(self):
|
||||
i = self.index + 1
|
||||
if i < len(self.string):
|
||||
return self.string[i]
|
||||
else:
|
||||
return None
|
||||
def next(self):
|
||||
self.index += 1
|
||||
if self.index < len(self.string):
|
||||
return self.string[self.index]
|
||||
else:
|
||||
raise StopIteration
|
||||
def all(self):
|
||||
return self.string
|
||||
|
||||
class WriteException(Exception):
|
||||
pass
|
||||
|
||||
class ReadException(Exception):
|
||||
pass
|
||||
|
||||
class JsonReader(object):
|
||||
hex_digits = {'A': 10,'B': 11,'C': 12,'D': 13,'E': 14,'F':15}
|
||||
escapes = {'t':'\t','n':'\n','f':'\f','r':'\r','b':'\b'}
|
||||
|
||||
def read(self, s):
|
||||
self._generator = _StringGenerator(s)
|
||||
result = self._read()
|
||||
return result
|
||||
|
||||
def _read(self):
|
||||
self._eatWhitespace()
|
||||
peek = self._peek()
|
||||
if peek is None:
|
||||
raise ReadException, "Nothing to read: '%s'" % self._generator.all()
|
||||
if peek == '{':
|
||||
return self._readObject()
|
||||
elif peek == '[':
|
||||
return self._readArray()
|
||||
elif peek == '"':
|
||||
return self._readString()
|
||||
elif peek == '-' or peek.isdigit():
|
||||
return self._readNumber()
|
||||
elif peek == 't':
|
||||
return self._readTrue()
|
||||
elif peek == 'f':
|
||||
return self._readFalse()
|
||||
elif peek == 'n':
|
||||
return self._readNull()
|
||||
elif peek == '/':
|
||||
self._readComment()
|
||||
return self._read()
|
||||
else:
|
||||
raise ReadException, "Input is not valid JSON: '%s'" % self._generator.all()
|
||||
|
||||
def _readTrue(self):
|
||||
self._assertNext('t', "true")
|
||||
self._assertNext('r', "true")
|
||||
self._assertNext('u', "true")
|
||||
self._assertNext('e', "true")
|
||||
return True
|
||||
|
||||
def _readFalse(self):
|
||||
self._assertNext('f', "false")
|
||||
self._assertNext('a', "false")
|
||||
self._assertNext('l', "false")
|
||||
self._assertNext('s', "false")
|
||||
self._assertNext('e', "false")
|
||||
return False
|
||||
|
||||
def _readNull(self):
|
||||
self._assertNext('n', "null")
|
||||
self._assertNext('u', "null")
|
||||
self._assertNext('l', "null")
|
||||
self._assertNext('l', "null")
|
||||
return None
|
||||
|
||||
def _assertNext(self, ch, target):
|
||||
if self._next() != ch:
|
||||
raise ReadException, "Trying to read %s: '%s'" % (target, self._generator.all())
|
||||
|
||||
def _readNumber(self):
|
||||
isfloat = False
|
||||
result = self._next()
|
||||
peek = self._peek()
|
||||
while peek is not None and (peek.isdigit() or peek == "."):
|
||||
isfloat = isfloat or peek == "."
|
||||
result = result + self._next()
|
||||
peek = self._peek()
|
||||
try:
|
||||
if isfloat:
|
||||
return float(result)
|
||||
else:
|
||||
return int(result)
|
||||
except ValueError:
|
||||
raise ReadException, "Not a valid JSON number: '%s'" % result
|
||||
|
||||
def _readString(self):
|
||||
result = ""
|
||||
assert self._next() == '"'
|
||||
try:
|
||||
while self._peek() != '"':
|
||||
ch = self._next()
|
||||
if ch == "\\":
|
||||
ch = self._next()
|
||||
if ch in 'brnft':
|
||||
ch = self.escapes[ch]
|
||||
elif ch == "u":
|
||||
ch4096 = self._next()
|
||||
ch256 = self._next()
|
||||
ch16 = self._next()
|
||||
ch1 = self._next()
|
||||
n = 4096 * self._hexDigitToInt(ch4096)
|
||||
n += 256 * self._hexDigitToInt(ch256)
|
||||
n += 16 * self._hexDigitToInt(ch16)
|
||||
n += self._hexDigitToInt(ch1)
|
||||
ch = unichr(n)
|
||||
elif ch not in '"/\\':
|
||||
raise ReadException, "Not a valid escaped JSON character: '%s' in %s" % (ch, self._generator.all())
|
||||
result = result + ch
|
||||
except StopIteration:
|
||||
raise ReadException, "Not a valid JSON string: '%s'" % self._generator.all()
|
||||
assert self._next() == '"'
|
||||
return result
|
||||
|
||||
def _hexDigitToInt(self, ch):
|
||||
try:
|
||||
result = self.hex_digits[ch.upper()]
|
||||
except KeyError:
|
||||
try:
|
||||
result = int(ch)
|
||||
except ValueError:
|
||||
raise ReadException, "The character %s is not a hex digit." % ch
|
||||
return result
|
||||
|
||||
def _readComment(self):
|
||||
assert self._next() == "/"
|
||||
second = self._next()
|
||||
if second == "/":
|
||||
self._readDoubleSolidusComment()
|
||||
elif second == '*':
|
||||
self._readCStyleComment()
|
||||
else:
|
||||
raise ReadException, "Not a valid JSON comment: %s" % self._generator.all()
|
||||
|
||||
def _readCStyleComment(self):
|
||||
try:
|
||||
done = False
|
||||
while not done:
|
||||
ch = self._next()
|
||||
done = (ch == "*" and self._peek() == "/")
|
||||
if not done and ch == "/" and self._peek() == "*":
|
||||
raise ReadException, "Not a valid JSON comment: %s, '/*' cannot be embedded in the comment." % self._generator.all()
|
||||
self._next()
|
||||
except StopIteration:
|
||||
raise ReadException, "Not a valid JSON comment: %s, expected */" % self._generator.all()
|
||||
|
||||
def _readDoubleSolidusComment(self):
|
||||
try:
|
||||
ch = self._next()
|
||||
while ch != "\r" and ch != "\n":
|
||||
ch = self._next()
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
def _readArray(self):
|
||||
result = []
|
||||
assert self._next() == '['
|
||||
done = self._peek() == ']'
|
||||
while not done:
|
||||
item = self._read()
|
||||
result.append(item)
|
||||
self._eatWhitespace()
|
||||
done = self._peek() == ']'
|
||||
if not done:
|
||||
ch = self._next()
|
||||
if ch != ",":
|
||||
raise ReadException, "Not a valid JSON array: '%s' due to: '%s'" % (self._generator.all(), ch)
|
||||
assert ']' == self._next()
|
||||
return result
|
||||
|
||||
def _readObject(self):
|
||||
result = {}
|
||||
assert self._next() == '{'
|
||||
done = self._peek() == '}'
|
||||
while not done:
|
||||
key = self._read()
|
||||
if type(key) is not types.StringType:
|
||||
raise ReadException, "Not a valid JSON object key (should be a string): %s" % key
|
||||
self._eatWhitespace()
|
||||
ch = self._next()
|
||||
if ch != ":":
|
||||
raise ReadException, "Not a valid JSON object: '%s' due to: '%s'" % (self._generator.all(), ch)
|
||||
self._eatWhitespace()
|
||||
val = self._read()
|
||||
result[key] = val
|
||||
self._eatWhitespace()
|
||||
done = self._peek() == '}'
|
||||
if not done:
|
||||
ch = self._next()
|
||||
if ch != ",":
|
||||
raise ReadException, "Not a valid JSON array: '%s' due to: '%s'" % (self._generator.all(), ch)
|
||||
assert self._next() == "}"
|
||||
return result
|
||||
|
||||
def _eatWhitespace(self):
|
||||
p = self._peek()
|
||||
while p is not None and p in string.whitespace or p == '/':
|
||||
if p == '/':
|
||||
self._readComment()
|
||||
else:
|
||||
self._next()
|
||||
p = self._peek()
|
||||
|
||||
def _peek(self):
|
||||
return self._generator.peek()
|
||||
|
||||
def _next(self):
|
||||
return self._generator.next()
|
||||
|
||||
class JsonWriter(object):
|
||||
|
||||
def _append(self, s):
|
||||
self._results.append(s)
|
||||
|
||||
def write(self, obj, escaped_forward_slash=False):
|
||||
self._escaped_forward_slash = escaped_forward_slash
|
||||
self._results = []
|
||||
self._write(obj)
|
||||
return "".join(self._results)
|
||||
|
||||
def _write(self, obj):
|
||||
ty = type(obj)
|
||||
if ty is types.DictType:
|
||||
n = len(obj)
|
||||
self._append("{")
|
||||
for k, v in obj.items():
|
||||
self._write(k)
|
||||
self._append(":")
|
||||
self._write(v)
|
||||
n = n - 1
|
||||
if n > 0:
|
||||
self._append(",")
|
||||
self._append("}")
|
||||
elif ty is types.ListType or ty is types.TupleType:
|
||||
n = len(obj)
|
||||
self._append("[")
|
||||
for item in obj:
|
||||
self._write(item)
|
||||
n = n - 1
|
||||
if n > 0:
|
||||
self._append(",")
|
||||
self._append("]")
|
||||
elif ty is types.StringType or ty is types.UnicodeType:
|
||||
self._append('"')
|
||||
obj = obj.replace('\\', r'\\')
|
||||
if self._escaped_forward_slash:
|
||||
obj = obj.replace('/', r'\/')
|
||||
obj = obj.replace('"', r'\"')
|
||||
obj = obj.replace('\b', r'\b')
|
||||
obj = obj.replace('\f', r'\f')
|
||||
obj = obj.replace('\n', r'\n')
|
||||
obj = obj.replace('\r', r'\r')
|
||||
obj = obj.replace('\t', r'\t')
|
||||
self._append(obj)
|
||||
self._append('"')
|
||||
elif ty is types.IntType or ty is types.LongType:
|
||||
self._append(str(obj))
|
||||
elif ty is types.FloatType:
|
||||
self._append("%f" % obj)
|
||||
elif obj is True:
|
||||
self._append("true")
|
||||
elif obj is False:
|
||||
self._append("false")
|
||||
elif obj is None:
|
||||
self._append("null")
|
||||
else:
|
||||
raise WriteException, "Cannot write in JSON: %s" % repr(obj)
|
||||
|
||||
def write(obj, escaped_forward_slash=False):
|
||||
return JsonWriter().write(obj, escaped_forward_slash)
|
||||
|
||||
def read(s):
|
||||
return JsonReader().read(s)
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
import time
|
||||
import urllib
|
||||
|
||||
import logging
|
||||
|
||||
import telnetlib
|
||||
|
||||
from util import json
|
||||
|
||||
import os
|
||||
|
||||
ALLOWED_EXTS = ('mp3')
|
||||
|
||||
class Callable:
|
||||
def __init__(self, anycallable):
|
||||
self.__call__ = anycallable
|
||||
|
||||
class Status:
|
||||
def __init__(self, status_url):
|
||||
self.status_url = status_url
|
||||
def get_obp_version(self):
|
||||
logger = logging.getLogger("status.get_obp_version")
|
||||
# lookup OBP version
|
||||
try:
|
||||
response = urllib.urlopen(self.status_url)
|
||||
response_json = json.read(response.read())
|
||||
obp_version = int(response_json['version'])
|
||||
logger.debug("OBP Version %s detected", obp_version)
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
obp_version = 0
|
||||
logger.error("Unable to detect OBP Version - %s", e)
|
||||
|
||||
|
||||
return obp_version
|
||||
|
||||
|
||||
def check_ls(self, ls_host, ls_port):
|
||||
logger = logging.getLogger("status.get_ls_version")
|
||||
# lookup OBP version
|
||||
try:
|
||||
tn = telnetlib.Telnet(ls_host, ls_port)
|
||||
tn.write("\n")
|
||||
tn.write("version\n")
|
||||
tn.write("exit\n")
|
||||
print tn.read_all()
|
||||
logger.info("liquidsoap connection ok")
|
||||
return 1
|
||||
|
||||
except Exception, e:
|
||||
obp_version = 0
|
||||
logger.error("Unable to connect to liquidsoap")
|
||||
return 0
|
||||
|
||||
|
Loading…
Reference in New Issue