summaryrefslogtreecommitdiffstats
path: root/streams
diff options
context:
space:
mode:
authorroot <root@monitoring.shack>2012-09-13 23:39:58 +0000
committerroot <root@monitoring.shack>2012-09-13 23:39:58 +0000
commitdb849a18e1659ff28433384d2cdca2989a6d5df0 (patch)
treed600fb3f3e5f0a54b6254c85ee8a3b836ef3d90d /streams
parentd5d39fc3d56b021b642ee6e1d5625524ebbc4d99 (diff)
parent88d4bdc29eb9ce5f62099f2be1488ae927aa09d5 (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'streams')
-rwxr-xr-xstreams/mpdstreams113
-rw-r--r--streams/stream.db25
-rw-r--r--streams/streams.py116
3 files changed, 252 insertions, 2 deletions
diff --git a/streams/mpdstreams b/streams/mpdstreams
new file mode 100755
index 00000000..75d2af13
--- /dev/null
+++ b/streams/mpdstreams
@@ -0,0 +1,113 @@
+#!/usr/bin/python
+
+# this version cannot tell if a stream is running or just ordinary music
+import os
+import sys
+from subprocess import Popen, PIPE
+
+os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
+pidfile = "/tmp/krebs.stream.pid"
+url_file = os.environ.get("STREAM_DB", "stream.db")
+urls = []
+#urls = [ url,f for (url,f) in open(url_file).readline() ]
+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")
+
+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):
+ Popen(["mpc","crossfade","5"],
+ stdout=pipe_silent,stderr=pipe_silent)
+ Popen(["mpc","repeat","yes"],
+ stdout=pipe_silent,stderr=pipe_silent)
+ Popen(["mpc","clear"],
+ stdout=pipe_silent,stderr=pipe_silent)
+ Popen(["mpc","load",stream_url],
+ stdout=pipe_silent,stderr=pipe_silent).wait()
+ Popen(["mpc","play"],
+ stdout=pipe_silent,stderr=pipe_silent)
+
+def start(stream):
+ ret = running()
+ if ret:
+ print "!! Stream `%s` already running !" % \
+ (ret)
+ else:
+ startStream(urlForStream(stream))
+ print "** Starting `%s`."% stream
+
+
+def stop():
+ ret = running()
+ if not ret:
+ print "!! No Stream running!"
+ else:
+ print "** Stopping `%s`" % ret
+ Popen(["mpc","stop"],
+ stdout=pipe_silent,stderr=pipe_silent)
+
+
+def running():
+ try:
+ (out,err) = Popen(["mpc","current"],stdout=PIPE,stderr=PIPE).communicate()
+ out = out.rstrip()
+ return out
+ except Exception as e:
+ return ""
+
+
+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 = running()
+ 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)
diff --git a/streams/stream.db b/streams/stream.db
index 711c5f30..2e873843 100644
--- a/streams/stream.db
+++ b/streams/stream.db
@@ -1,8 +1,6 @@
-http://somafm.com/groovesalad.pls groove
http://deepmix.ru/deepmix128.pls deepmix
http://streams.xenim.de/radiotux.ogg radiotux
http://bassdrive.com/v2/streams/BassDrive.pls bassdrive
-http://somafm.com/illstreet.pls illstreet
http://localhost:8000/stream.ogg icecast
http://localhost:8000/shice.ogg shice
http://stream2.jungletrain.net:8000 jungletrain
@@ -12,3 +10,26 @@ http://radio.krautchan.net:8000/radio.mp3 radiofreieskrautchan
http://nl1.streamhosting.ch/listen.pls lounge
http://deluxetelevision.com/livestreams/radio/DELUXE_RADIO.pls deluxe
http://livestream.radiodarmstadt.de:8000 darmstadt
+http://somafm.com/sxfm.pls southbysoma
+http://somafm.com/indiepop.pls indypop
+http://somafm.com/poptron.pls poptron
+http://somafm.com/480min.pls 480min
+http://somafm.com/u80s.pls underground80s
+http://somafm.com/secretagent.pls secretagent
+http://somafm.com/suburbsofgoa.pls suburbsofgoa
+http://somafm.com/beatblender.pls beatblender
+http://somafm.com/missioncontrol.pls missioncontrol
+http://somafm.com/dronezone.pls dronezone
+http://somafm.com/cliqhop.pls cliqhop
+http://somafm.com/spacestation.pls spacestationsoma
+http://somafm.com/bootliquor.pls bootliquor
+http://somafm.com/covers.pls covers
+http://somafm.com/illstreet.pls illstreet
+http://somafm.com/tags.pls tagstrip
+http://somafm.com/groovesalad.pls groove
+http://somafm.com/lush.pls lush
+http://somafm.com/digitalis.pls digitalis
+http://somafm.com/sonicuniverse.pls sonicuniverse
+http://somafm.com/doomed.pls doomed
+http://somafm.com/brfm.pls blackrockfm
+http://de.scenemusic.net/necta192.mp3 demoscene
diff --git a/streams/streams.py b/streams/streams.py
new file mode 100644
index 00000000..65669b2d
--- /dev/null
+++ b/streams/streams.py
@@ -0,0 +1,116 @@
+#!/usr/bin/python
+import os
+import sys
+from subprocess import Popen, PIPE
+
+os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
+pidfile = "/tmp/krebs.stream.pid"
+url_file = os.environ.get("STREAM_DB", "stream.db")
+urls = []
+#urls = [ url,f for (url,f) in open(url_file).readline() ]
+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"
+
+
+def check_pid(pid):
+ """ Check For the existence of a unix pid. """
+ try:
+ os.kill(pid, 0)
+ except OSError:
+ return False
+ else:
+ return True
+
+
+def urlForStream(stream):
+ for url, s in urls:
+ if s == stream:
+ return url
+
+
+def start(stream):
+ ret = running()
+ if ret:
+ print "!! Stream `%s` already running with pid `%s` !" % \
+ (ret[1], ret[0])
+ else:
+ pipe_silent = open('/dev/null', 'w')
+ url = urlForStream(stream)
+ mpl = Popen(["mplayer", url],
+ stdout=pipe_silent, stderr=pipe_silent).pid
+ print >> open(pidfile, "w+"), "%d %s" % (mpl, stream)
+
+
+def stop():
+ ret = running()
+ if not ret:
+ print "!! No Stream running!"
+ else:
+ pid, name = ret
+ print "** Killing `%s` with pid %s" % (name, pid)
+ os.kill(int(pid), 15)
+ #if check_pid(int(pid)):
+ # print "!! trying harder to kill process"
+ # os.kill(int(pid), 9)
+ os.remove(pidfile)
+
+
+def running():
+ try:
+ pid, currstream = open(pidfile).read().split()
+ if check_pid(int(pid)):
+ return (pid, currstream)
+ else:
+ print "!! removing stale pidfile"
+ os.remove(pidfile)
+ raise Exception("Pidfile stale")
+ except Exception as e:
+ return ()
+
+
+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 = running()
+ if not ret:
+ print "** no stream running" # , e
+ else:
+ print "%s is running(%s)" % (ret[1], urlForStream(ret[1]))
+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)