From 0b9e1cce24cb4a77b5bd1798fa05f3adb037ade8 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 31 Oct 2012 22:18:11 +0100 Subject: relaxxapi - initial commit the relaxxapi will provide //streams access to the shack music infrastructure --- streams/relaxxapi.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 streams/relaxxapi.py diff --git a/streams/relaxxapi.py b/streams/relaxxapi.py new file mode 100755 index 00000000..9ef738d0 --- /dev/null +++ b/streams/relaxxapi.py @@ -0,0 +1,78 @@ +#!/usr/bin/python2 +import json +from urllib import quote +class relaxx: + + def __init__(self,relaxxurl="http://lounge.mpd.shack/"): + self.baseurl=relaxxurl + import requests + ret = requests.get(relaxxurl) # grab cookie + try: + self.r = requests.session(cookies=ret.cookies,headers={"Referer":relaxxurl}) + except: + print ("you are missing the `requests` dependency, please do a `pip install requests`") + def _status(self,value=0,data="json=null"): + """ + value is some weird current playlist value, 0 seems to work + data is url encoded kv-store + """ + # TODO get the current playlist value + url=self.baseurl+"include/controller-ping.php?value=%s"%value + return self.r.post(url,data="json=null").text + + def _action(self,action,value="",json="null",method="get"): + """ + This function is the interface to the controller-playlist api + use it if you dare + Possible actions: + clear + play + addSong url_encoded_path + moveSong 1:2 + getPlaylists + getPlaylistInfo 1 + listPlaylistInfo + as everything seems to be a get request, the method is set to GET as + default + """ + url=self.baseurl+"include/controller-playlist.php?action=%s&value=%s&json=%s"%(action,value,json) + if method== "get": + return self.r.get(url).text + elif method == "post": + return r.post(url).text + else: + raise Exception("unknown method %s") + def add_radio(self,playlist=""): + """ + both, post and get the url seem to work here... + """ + url=self.baseurl+"include/controller-netradio.php?playlist=%s"%playlist + print self.r.post(url).text + resolved_url= json.loads(self.r.get(url).text[1:-1])["url"] + self.add_song(resolved_url) + + def add_song(self,path): + return self._action("addSong",quote(path)) + + def clear(self): + return self._action("clear") + + def play(self,ident): + return self._action("play",ident) + + def stop(self): + return self._action("stop") + def get_first(self): + return json.loads(self._action("getPlaylistInfo","0",""))[0] + + def play_first(self): + return self.play(self.get_first()["Id"]) + + def state(self): + return self._action( + +if __name__ == "__main__": + r = relaxx() + r.stop() + print r.play_first() + #print r.add_radio("http://somafm.com/lush.pls") -- cgit v1.2.3 From e1aa728dd46355a59bdea5492c7030d004d80b8c Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 5 Nov 2012 18:45:08 +0100 Subject: retiolum/hosts: rm defunct ach --- retiolum/hosts/ach | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 retiolum/hosts/ach diff --git a/retiolum/hosts/ach b/retiolum/hosts/ach deleted file mode 100644 index 26ee10f2..00000000 --- a/retiolum/hosts/ach +++ /dev/null @@ -1,10 +0,0 @@ -Subnet = 42:c50f:d371:cf01:8cf0:0b77:bb01:5013/128 -Subnet = 42.135.28.73/32 ------BEGIN RSA PUBLIC KEY----- -MIIBCgKCAQEA2d5RaWiFmkuw0UhPsQCrFBNNgBwzHQMDO69rU6XlH8VSGI8HTPuI -v5Jjyhrf2p/ktLAnafBUHO32bNRu/9lbM0rjPZna5t1MjJpUaja6yF5TzdAQ4YMD -KTkGqjI9QEuGBPixFNRq+P9QK5FLx1/wtF0ZE1CYS+A6iwQ9S+IPCIYYswUmhYQF -ik2IaixG6EkZj2NSJqvDF4HDJz8lnwQIQfFqZ8WdP2MtMUng09PdjQHss0jqRbPO -4J7UpDkrXSABjDnEYk4CKH0YhLGPB3VDYeD4rQjKuDTYOWXQ8OYIyPVucKe2RABc -dJF6MQ+z+2m1vMqEYPBOH69Ggncq9GQ4xwIDAQAB ------END RSA PUBLIC KEY----- -- cgit v1.2.3 From 5ae89a515de76e7cf646c2a3e0063036b5556794 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 5 Nov 2012 18:52:46 +0100 Subject: retiolum/hosts: add new ach (AC100-10V; Arch Linux) --- retiolum/hosts/ach | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 retiolum/hosts/ach diff --git a/retiolum/hosts/ach b/retiolum/hosts/ach new file mode 100644 index 00000000..700ad7ae --- /dev/null +++ b/retiolum/hosts/ach @@ -0,0 +1,11 @@ +Subnet = 10.243.0.100 +Subnet = 42:335b:5e83:d8ef:fdf0:d921:22c8:b15d/128 + +-----BEGIN RSA PUBLIC KEY----- +MIIBCgKCAQEAxvRxan/8TtgkqsGCZ26jd+Nuv5tL0Nab2jbKVZa0iwtjIyBlF4cF +wR2H1ypdzqT5hHGVzE2T1QjBqYO1cIJ4cu0wfCbJSp9YtmK9Tm+TK/bz9LNj/RYj +e27ixFVoeYFU7fF2kNG5g66u/xspGnulRFzqNXXqh6Jy0X6eJJmvo8wniSHxcMoc +gyS7kpwDTcoYlnej6+tsGILVuZ6bSWuVr+kbdHp0rUGDXtNDAHW4WDtXRARFLmub +QdyxtBGQXB8n4XmdIlpuVbvyceBAId4SAcky6pIC4VCbvSJ5pDrL9+u07r24JkIz +MAs1gTh4riA3e3IbII8l8iUJ2x9Zlf6+vQIDAQAB +-----END RSA PUBLIC KEY----- -- cgit v1.2.3 From a9b55da4f28985cc878b7fee3219685a21e29052 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 9 Nov 2012 00:46:09 +0100 Subject: relaxxstreams: now using finished relaxxapi.py --- streams/relaxxapi.py | 92 +++++++++++++++++++++++++++++++++------- streams/relaxxplayer.api | 13 ++++++ streams/relaxxstreams | 107 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 15 deletions(-) create mode 100644 streams/relaxxplayer.api create mode 100755 streams/relaxxstreams diff --git a/streams/relaxxapi.py b/streams/relaxxapi.py index 9ef738d0..f367caef 100755 --- a/streams/relaxxapi.py +++ b/streams/relaxxapi.py @@ -20,13 +20,12 @@ class relaxx: url=self.baseurl+"include/controller-ping.php?value=%s"%value return self.r.post(url,data="json=null").text - def _action(self,action,value="",json="null",method="get"): + def _playlist(self,action,value="",json="null",method="get"): """ This function is the interface to the controller-playlist api use it if you dare Possible actions: clear - play addSong url_encoded_path moveSong 1:2 getPlaylists @@ -42,37 +41,100 @@ class relaxx: return r.post(url).text else: raise Exception("unknown method %s") - def add_radio(self,playlist=""): + + def _playback(self,action,value="",json="null",method="get"): + """ + play + continue + stop + setCrossfade + """ + url=self.baseurl+"include/controller-playback.php?action=%s&value=%s&json=%s"%(action,value,json) + # probably obsolete because everything is "get" + if method== "get": + return self.r.get(url).text + elif method == "post": + return r.post(url).text + else: + raise Exception("unknown method %s") + + def _radio(self,playlist=""): """ both, post and get the url seem to work here... """ - url=self.baseurl+"include/controller-netradio.php?playlist=%s"%playlist - print self.r.post(url).text - resolved_url= json.loads(self.r.get(url).text[1:-1])["url"] + url=self.baseurl+"include/controller-netradio.php?playlist=%s"%quote(playlist) + return self.r.get(url).text + + def add_radio(self,playlist=""): + print playlist + print self._radio(playlist) + print json.loads(self._radio(playlist)) #[1:-1])["url"] + resolved_url= json.loads(self._radio(playlist)[1:-1])["url"] self.add_song(resolved_url) def add_song(self,path): - return self._action("addSong",quote(path)) + return self._playlist("addSong",path) + + def get_first(self): + return json.loads(self._playlist("getPlaylistInfo","0",""))[0] + + def get_first(self): + return json.loads(self._playlist("getPlaylistInfo","0",""))[-1] def clear(self): - return self._action("clear") + return self._playlist("clear") + + def crossfade(self,ident="0"): + """ + default: no crossfade + """ + return self._playback("setCrossfade",ident) + + def repeat(self,ident="1"): + """ + default: do repeat + """ + return self._playback("repeat",ident) def play(self,ident): - return self._action("play",ident) + return self._playback("play",ident) def stop(self): - return self._action("stop") - def get_first(self): - return json.loads(self._action("getPlaylistInfo","0",""))[0] + return self._playback("stop") + + def cont(self,ident): + return self._playback("continue",ident) def play_first(self): return self.play(self.get_first()["Id"]) + def play_last(self): + return self.play(self.get_last()["Id"]) + def state(self): - return self._action( + return json.loads(self._status()) + + def is_running(self): + return self.state()["status"]["state"] == "play" + + def playing(self): + """ returns "" if not running + """ + state = self.state() + if state["status"]["state"] == "play" : + ident = state["status"]["song"] + current = state["playlist"]["file"][int(ident)] + return current.get("Name",current.get("Artist")) + " - " + current["Title"] + else: + return "" if __name__ == "__main__": r = relaxx() - r.stop() - print r.play_first() + print r.state() + print r.playing() + print r.add_radio("http://deluxetelevision.com/livestreams/radio/DELUXE_RADIO.pls") + #print r.clear() + #print r.add_radio("http://somafm.com/lush.pls") + #print r.get_first()["Id"] + #print r.play_first() #print r.add_radio("http://somafm.com/lush.pls") diff --git a/streams/relaxxplayer.api b/streams/relaxxplayer.api new file mode 100644 index 00000000..6e8af577 --- /dev/null +++ b/streams/relaxxplayer.api @@ -0,0 +1,13 @@ +http://lounge.mpd.shack/include/controller-playback.php?action=setCrossfade&value=5&json=null +http://lounge.mpd.shack/include/controller-playback.php?action=repeat&value=1&json=null +http://lounge.mpd.shack/include/controller-playlist.php?action=clear&value=&json=null +http://lounge.mpd.shack/include/controller-playlist.php?action=addSong&value=http%3A%2F%2F212.7.194.133%3A8128&json=null +http://lounge.mpd.shack/include/controller- playlist.php?action=getPlaylistInfo&value=0&json= +[{ + "file": "http:\/\/212.7.194.133:8128", + "Title": "Max & Dima - Sapovnela Studio: Batut", + "Name": "Deep Mix Moscow Radio: deepmix.ru", + "Pos": "0", + "Id": "606" +}] +http://lounge.mpd.shack/include/controller-playlist.php?action=continue&value={Id}&json=null diff --git a/streams/relaxxstreams b/streams/relaxxstreams new file mode 100755 index 00000000..57cfb05b --- /dev/null +++ b/streams/relaxxstreams @@ -0,0 +1,107 @@ +#!/usr/bin/python2 + +# this version cannot tell if a stream is running or just ordinary music +import os +import sys +import json +from urllib import quote +from relaxxapi import relaxx + +try: + import requests +except: + print ("you are missing the `requests` dependency, please do a `pip install requests`") +from subprocess import Popen, PIPE + +os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) +pidfile = "/tmp/krebs.stream.pid" +baseurl="http://elab.mpd.shack/" +url=baseurl+"include/controller-playlist.php?action=%s&value=%s&json=%s" +url_file = os.environ.get("STREAM_DB", "direct.db") +urls = [] + +for line in open(url_file): + urls.append(line.split()) +#print urls +mybin = sys.argv[0] +cmd = sys.argv[1] if len(sys.argv) > 1 else "you-are-made-of-stupid" +stream = sys.argv[2] if len(sys.argv) == 3 else "groove" +pipe_silent = open("/dev/null","w") +api = relaxx(baseurl) + +def urlForStream(stream): + for url, s in urls: + if s == stream: + return url + +def streamForUrl(url): + for u, s in urls: + if u == url: + return stream + +def startStream(stream_url): + print api.crossfade("5") + print api.repeat("1") + print api.clear() + print api.add_song(stream_url) + print api.play_first() + +def start(stream): + ret = api.playing() + if ret: + print "!! Stream `%s` already running !" % \ + (ret) + else: + startStream(urlForStream(stream)) + print "** Starting `%s`."% stream + + +def stop(): + ret = api.playing() + if not ret: + print "!! No Stream running!" + else: + print "** Stopping `%s`" % ret + api.stop() + +def slist(): + for url, name in urls: + print "%s : %s" % (name, url) + +def shorthelp(): + print "start|stop|restart|status|list [audio stream]" + + +def longhelp(): + print "Usage: %s" % mybin, + shorthelp + print """ get all available streams with '/%(fil)s list' + Examples: + %(fil)s list + %(fil)s start groove + %(fil)s switch deepmix + %(fil)s status + %(fil)s stop""" % {'fil': mybin} + +if cmd == "start": + start(stream) +elif cmd == "stop": + stop() +elif cmd == "switch" or cmd == "restart": + stop() + start(stream) +elif cmd == "status": + ret = api.playing() + if not ret: + print "** nothing running" # , e + else: + print "Now Playing: %s" % ret +elif cmd == "list": + slist() +elif cmd == "--help": + longhelp() +elif cmd == "-h": + shorthelp() +else: + print "unknown command `%s`" % cmd + print "try `%s` --help" % os.path.basename(mybin) -- cgit v1.2.3