blob: 75b03df19d888eb9900b1dbe68a7e6fca0485735 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#!/usr/bin/python
# this version cannot tell if a stream is running or just ordinary music
import os
import sys
import json
from urllib.parse 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://lounge.mpd.shack/"
url=baseurl+"include/controller-playlist.php?action=%s&value=%s&json=%s"
url_file = os.environ.get("STREAM_DB", "../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("""[32;1m get all available streams with [31;1;4m'/%(fil)s list'[m
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))
|