summaryrefslogtreecommitdiffstats
path: root/streams/relaxxapi.py
diff options
context:
space:
mode:
Diffstat (limited to 'streams/relaxxapi.py')
-rwxr-xr-xstreams/relaxxapi.py92
1 files changed, 77 insertions, 15 deletions
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")