summaryrefslogtreecommitdiffstats
path: root/god/streams
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2014-04-02 13:23:49 +0200
committermakefu <github@syntax-fehler.de>2014-04-02 13:23:49 +0200
commit82d3258f5a316910bb844ba202748261ae27c5fc (patch)
tree2f40447acca41179a5c43701c40eb719129291ec /god/streams
parent10af0e082e36d6cda7d687362e7c7cf4c04b741c (diff)
relaxxapi: fix broken code
Diffstat (limited to 'god/streams')
-rwxr-xr-xgod/streams/bin/relaxxapi.py26
-rwxr-xr-xgod/streams/bin/relaxxstreams42
2 files changed, 33 insertions, 35 deletions
diff --git a/god/streams/bin/relaxxapi.py b/god/streams/bin/relaxxapi.py
index 55e628b0..38650907 100755
--- a/god/streams/bin/relaxxapi.py
+++ b/god/streams/bin/relaxxapi.py
@@ -1,16 +1,14 @@
-#!/usr/bin/python2
+#!/usr/bin/python
import json
-from urllib import quote
+from urllib.parse import quote
class relaxx:
-
+ r = ""
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`")
+ self.r = requests.session()
+ ret = self.r.get(relaxxurl) # grab cookie
def _status(self,value=0,data="json=null"):
"""
value is some weird current playlist value, 0 seems to work
@@ -66,9 +64,9 @@ class relaxx:
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"]
+ 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)
@@ -130,9 +128,9 @@ class relaxx:
if __name__ == "__main__":
r = relaxx()
- print r.state()
- print r.playing()
- print r.add_radio("http://deluxetelevision.com/livestreams/radio/DELUXE_RADIO.pls")
+ 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"]
diff --git a/god/streams/bin/relaxxstreams b/god/streams/bin/relaxxstreams
index 0d3813a7..75b03df1 100755
--- a/god/streams/bin/relaxxstreams
+++ b/god/streams/bin/relaxxstreams
@@ -1,10 +1,10 @@
-#!/usr/bin/python2
+#!/usr/bin/python
# this version cannot tell if a stream is running or just ordinary music
import os
import sys
import json
-from urllib import quote
+from urllib.parse import quote
from relaxxapi import relaxx
try:
@@ -40,48 +40,48 @@ def streamForUrl(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()
+ 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)
+ print("!! Stream `%s` already running !" % \
+ (ret))
else:
startStream(urlForStream(stream))
- print "** Starting `%s`."% stream
+ print("** Starting `%s`."% stream)
def stop():
ret = api.playing()
if not ret:
- print "!! No Stream running!"
+ print("!! No Stream running!")
else:
- print "** Stopping `%s`" % ret
+ print("** Stopping `%s`" % ret)
api.stop()
def slist():
for url, name in urls:
- print "%s : %s" % (name, url)
+ print("%s : %s" % (name, url))
def shorthelp():
- print "start|stop|restart|status|list [audio stream]"
+ print("start|stop|restart|status|list [audio stream]")
def longhelp():
- print "Usage: %s" % mybin,
+ print("Usage: %s" % mybin)
shorthelp
- print """ get all available streams with '/%(fil)s list'
+ 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}
+ %(fil)s stop""" % {'fil': mybin})
if cmd == "start":
start(stream)
@@ -93,9 +93,9 @@ elif cmd == "switch" or cmd == "restart":
elif cmd == "status":
ret = api.playing()
if not ret:
- print "** nothing running" # , e
+ print("** nothing running") # , e
else:
- print "Now Playing: %s" % ret
+ print("Now Playing: %s" % ret)
elif cmd == "list":
slist()
elif cmd == "--help":
@@ -103,5 +103,5 @@ elif cmd == "--help":
elif cmd == "-h":
shorthelp()
else:
- print "unknown command `%s`" % cmd
- print "try `%s` --help" % os.path.basename(mybin)
+ print("unknown command `%s`" % cmd)
+ print("try `%s` --help" % os.path.basename(mybin))