CC-1665: Scheduled stream rebroadcasting and recording
-send stream name back to Airtime: [("url","http://idobiradio.com/"), ("title","Good Charlotte - Like It's Her Birthday")]
This commit is contained in:
parent
899c94eb67
commit
d773dcd112
13 changed files with 206 additions and 40 deletions
|
@ -115,3 +115,5 @@ get_bootstrap_info = 'get-bootstrap-info/format/json/api_key/%%api_key%%'
|
|||
get_files_without_replay_gain = 'get-files-without-replay-gain/api_key/%%api_key%%/dir_id/%%dir_id%%'
|
||||
|
||||
update_replay_gain_value = 'update-replay-gain-value/api_key/%%api_key%%'
|
||||
|
||||
notify_webstream_data = 'notify-webstream-data/api_key/%%api_key%%/media_id/%%media_id%%/format/json'
|
||||
|
|
|
@ -81,9 +81,17 @@ class AirtimeApiClient():
|
|||
successful_response = True
|
||||
except IOError, e:
|
||||
logger.error('Error Authenticating with remote server: %s', e)
|
||||
if isinstance(url, urllib2.Request):
|
||||
logger.debug(url.get_full_url())
|
||||
else:
|
||||
logger.debug(url)
|
||||
except Exception, e:
|
||||
logger.error('Couldn\'t connect to remote server. Is it running?')
|
||||
logger.error("%s" % e)
|
||||
if isinstance(url, urllib2.Request):
|
||||
logger.debug(url.get_full_url())
|
||||
else:
|
||||
logger.debug(url)
|
||||
|
||||
if not successful_response:
|
||||
logger.error("Error connecting to server, waiting 5 seconds and trying again.")
|
||||
|
@ -684,7 +692,25 @@ class AirtimeApiClient():
|
|||
data = urllib.urlencode({'data': json.dumps(pairs)})
|
||||
request = urllib2.Request(url, data)
|
||||
|
||||
self.get_response_from_server(request)
|
||||
self.logger.debug(self.get_response_from_server(request))
|
||||
except Exception, e:
|
||||
self.logger.error("Exception: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
def notify_webstream_data(self, data, media_id):
|
||||
"""
|
||||
Update the server with the latest metadata we've received from the
|
||||
external webstream
|
||||
"""
|
||||
try:
|
||||
url = "http://%(base_url)s:%(base_port)s/%(api_base)s/%(notify_webstream_data)s/" % (self.config)
|
||||
url = url.replace("%%media_id%%", str(media_id))
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
data = urllib.urlencode({'data': data})
|
||||
self.logger.debug(url)
|
||||
request = urllib2.Request(url, data)
|
||||
|
||||
self.logger.info(self.get_response_from_server(request))
|
||||
except Exception, e:
|
||||
self.logger.error("Exception: %s", e)
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
def notify(m)
|
||||
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']} &")
|
||||
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']} &")
|
||||
current_media_id := string_of(m['schedule_table_id'])
|
||||
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']} &"
|
||||
log(command)
|
||||
system(command)
|
||||
end
|
||||
|
||||
def notify_stream(m)
|
||||
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --stream --uri=#{base64.encode(m['uri'])} --title=#{base64.encode(m['title'])} &")
|
||||
#system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --stream --uri=#{base64.encode(m['uri'])} --title=#{base64.encode(m['title'])} &")
|
||||
json_str = string.replace(pattern="\n",(fun (s) -> ""), json_of(m))
|
||||
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --webstream='#{json_str}' --media-id=#{!current_media_id} &"
|
||||
log(command)
|
||||
system(command)
|
||||
end
|
||||
|
||||
# A function applied to each metadata chunk
|
||||
|
|
|
@ -27,6 +27,7 @@ stream_metadata_type = ref 0
|
|||
default_dj_fade = ref 0.
|
||||
station_name = ref ''
|
||||
show_name = ref ''
|
||||
current_media_id = ref ''
|
||||
|
||||
s1_connected = ref ''
|
||||
s2_connected = ref ''
|
||||
|
|
|
@ -6,10 +6,10 @@ Python part of radio playout (pypo)
|
|||
This function acts as a gateway between liquidsoap and the server API.
|
||||
Mainly used to tell the platform what pypo/liquidsoap does.
|
||||
|
||||
Main case:
|
||||
Main case:
|
||||
- whenever LS starts playing a new track, its on_metadata callback calls
|
||||
a function in ls (notify(m)) which then calls the python script here
|
||||
with the currently starting filename as parameter
|
||||
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 the API to tell about it about it.
|
||||
|
||||
|
@ -33,14 +33,15 @@ usage = "%prog [options]" + " - notification gateway"
|
|||
parser = OptionParser(usage=usage)
|
||||
|
||||
# Options
|
||||
parser.add_option("-d", "--data", help="Pass JSON data from liquidsoap into this script.", metavar="data")
|
||||
parser.add_option("-d", "--data", help="Pass JSON data from Liquidsoap into this script.", metavar="data")
|
||||
parser.add_option("-m", "--media-id", help="ID of the file that is currently playing.", metavar="media_id")
|
||||
parser.add_option("-e", "--error", action="store", dest="error", type="string", help="liquidsoap error msg.", metavar="error_msg")
|
||||
parser.add_option("-e", "--error", action="store", dest="error", type="string", help="Liquidsoap error msg.", metavar="error_msg")
|
||||
parser.add_option("-s", "--stream-id", help="ID stream", metavar="stream_id")
|
||||
parser.add_option("-c", "--connect", help="liquidsoap connected", action="store_true", metavar="connect")
|
||||
parser.add_option("-t", "--time", help="liquidsoap boot up time", action="store", dest="time", metavar="time", type="string")
|
||||
parser.add_option("-c", "--connect", help="Liquidsoap connected", action="store_true", metavar="connect")
|
||||
parser.add_option("-t", "--time", help="Liquidsoap boot up time", action="store", dest="time", metavar="time", type="string")
|
||||
parser.add_option("-x", "--source-name", help="source connection name", metavar="source_name")
|
||||
parser.add_option("-y", "--source-status", help="source connection stauts", metavar="source_status")
|
||||
parser.add_option("-y", "--source-status", help="source connection status", metavar="source_status")
|
||||
parser.add_option("-w", "--webstream", help="JSON metadata associated with webstream", metavar="json_data")
|
||||
|
||||
# parse options
|
||||
(options, args) = parser.parse_args()
|
||||
|
@ -97,6 +98,15 @@ class Notify:
|
|||
response = self.api_client.notify_source_status(source_name, status)
|
||||
logger.debug("Response: " + json.dumps(response))
|
||||
|
||||
def notify_webstream_data(self, data, media_id):
|
||||
logger = logging.getLogger("notify")
|
||||
logger.debug('#################################################')
|
||||
logger.debug('# Calling server to update webstream data #')
|
||||
logger.debug('#################################################')
|
||||
response = self.api_client.notify_webstream_data(data, media_id)
|
||||
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
print
|
||||
print '#########################################'
|
||||
|
@ -124,6 +134,12 @@ if __name__ == '__main__':
|
|||
n.notify_source_status(options.source_name, options.source_status)
|
||||
except Exception, e:
|
||||
print e
|
||||
elif options.webstream:
|
||||
try:
|
||||
n = Notify()
|
||||
n.notify_webstream_data(options.webstream, options.media_id)
|
||||
except Exception, e:
|
||||
print e
|
||||
else:
|
||||
if not options.data:
|
||||
print "NOTICE: 'data' command-line argument not given."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue