From 21bb561b81d6c395ce0b004ce3b70a02c00360ef Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 20 Dec 2012 10:50:50 +0700 Subject: //streams -> //god/streams --- streams/Makefile | 16 ------ streams/README | 10 ---- streams/mpdstreams | 114 -------------------------------------- streams/relaxxapi.py | 140 ----------------------------------------------- streams/relaxxplayer.api | 13 ----- streams/relaxxstreams | 107 ------------------------------------ streams/stream-starter | 19 ------- streams/stream.db | 35 ------------ streams/streams | 131 -------------------------------------------- streams/streams.py | 116 --------------------------------------- 10 files changed, 701 deletions(-) delete mode 100644 streams/Makefile delete mode 100644 streams/README delete mode 100755 streams/mpdstreams delete mode 100755 streams/relaxxapi.py delete mode 100644 streams/relaxxplayer.api delete mode 100755 streams/relaxxstreams delete mode 100755 streams/stream-starter delete mode 100644 streams/stream.db delete mode 100755 streams/streams delete mode 100644 streams/streams.py (limited to 'streams') diff --git a/streams/Makefile b/streams/Makefile deleted file mode 100644 index ab5d1429..00000000 --- a/streams/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -INITD = $(shell test -e /etc/rc.d/ && echo /etc/rc.d/ || echo /etc/init.d/) -streams = $(shell cut -d\ -f2 stream.db) - - -CURRDIR = ${PWD} -.PHONY: all $(streams) -local: ../bin/streams - -../bin/streams: - ln -sf $$PWD/streams ../bin/streams -all: $(streams) - @update-rc.d groove defaults 2>/dev/null || echo "** put groove daemon in DAEMONS in /etc/rc.conf" - -$(streams): local - @test -L $(INITD)$@ || test ! -e $(INITD)$@ && \ - ln -n -s -f $$PWD/stream-starter $(INITD)$@ && echo "writing $@ to $(INITD)" diff --git a/streams/README b/streams/README deleted file mode 100644 index 82300c24..00000000 --- a/streams/README +++ /dev/null @@ -1,10 +0,0 @@ -streams done right - -deepmix,groovesalad and radiotux are now init.d scrips which can be -started and stopped. - -scripts are dumped into /etc/init.d and groovesalad will be set as -default via update-rc.d - -mplayer will be started in a tmux session either by creating a new -session or starting a new window inside the first existing one diff --git a/streams/mpdstreams b/streams/mpdstreams deleted file mode 100755 index d9132937..00000000 --- a/streams/mpdstreams +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/python2 - -# 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" -host="lounge.mpd.shack" -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","--host",host,"crossfade","5"], - stdout=pipe_silent,stderr=pipe_silent) - Popen(["mpc","--host",host,"repeat","yes"], - stdout=pipe_silent,stderr=pipe_silent) - Popen(["mpc","--host",host,"clear"], - stdout=pipe_silent,stderr=pipe_silent) - Popen(["mpc","--host",host,"add",stream_url], - stdout=pipe_silent,stderr=pipe_silent).wait() - Popen(["mpc","--host",host,"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","--host",host,"stop"], - stdout=pipe_silent,stderr=pipe_silent) - - -def running(): - try: - (out,err) = Popen(["mpc","--host",host,"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/relaxxapi.py b/streams/relaxxapi.py deleted file mode 100755 index f367caef..00000000 --- a/streams/relaxxapi.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/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 _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 - 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 _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"%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._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._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._playback("play",ident) - - def stop(self): - 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 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() - 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 deleted file mode 100644 index 6e8af577..00000000 --- a/streams/relaxxplayer.api +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100755 index 57cfb05b..00000000 --- a/streams/relaxxstreams +++ /dev/null @@ -1,107 +0,0 @@ -#!/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) diff --git a/streams/stream-starter b/streams/stream-starter deleted file mode 100755 index 4d3a406f..00000000 --- a/streams/stream-starter +++ /dev/null @@ -1,19 +0,0 @@ -#! /bin/bash -set -euf -HERE=$(dirname $(readlink -f $0)) -STR=$HERE/streams -NAME=`basename $0` -case "$1" in - start) - $STR start $NAME - ;; - stop) - $STR stop - ;; - restart) - $STR restart $NAME - ;; - *) - echo "aidsballs" - ;; -esac diff --git a/streams/stream.db b/streams/stream.db deleted file mode 100644 index 2e873843..00000000 --- a/streams/stream.db +++ /dev/null @@ -1,35 +0,0 @@ -http://deepmix.ru/deepmix128.pls deepmix -http://streams.xenim.de/radiotux.ogg radiotux -http://bassdrive.com/v2/streams/BassDrive.pls bassdrive -http://localhost:8000/stream.ogg icecast -http://localhost:8000/shice.ogg shice -http://stream2.jungletrain.net:8000 jungletrain -http://playlist.tormentedradio.com/tormentedradio.pls tormented -http://filebitch.shack:8000 mpd -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 b/streams/streams deleted file mode 100755 index 80c654ad..00000000 --- a/streams/streams +++ /dev/null @@ -1,131 +0,0 @@ -#! /bin/bash -set -euf - -stream_file=/tmp/krebs.stream.current - -HERE=$(dirname $(readlink -f $0)) -URLS=`cat $HERE/stream.db` -CURRENT_STREAM="no stream" #will be set when calling `status` -if [ ! `id -u` -eq "0" ]; then - exec sudo "$0" "$@" -fi - -#if [ ! `id -u` -eq "0" ]; then -# echo "we are going sudo..." -# exec sudo "$0" "$@" -#fi - -function start() { - # start the given stream von $1 - REQ=$1 - tmux start-server - if status &>/dev/null ; then - echo "!! Stream already running!" - exit 1 - fi - - if echo "$URLS" | while read URL NAME; do - if [ "$NAME" = "$REQ" ];then - tmux new-session -s streams -n streams -d " - while sleep 1; do - echo $NAME > $stream_file - mplayer $URL - done - " - echo "** $REQ started" - exit 1 - fi - done; then - echo "!! Stream '$REQ' not found!" - exit 1 - fi -} -function stop() -{ - #stops every stream - if status &>/dev/null; then - status | cut -d\ -f2 | xargs printf "** killing %s\n" - tmux kill-session -t streams 2>/dev/null || echo "!! killing session failed" - else - echo "** no stream running"; - return 1 - fi -} - -function status() -{ - #tmux has-session -t streams 2>/dev/null - #RET=$? - - #tmux list-sessions 2>/dev/null - #return $RET - EV="`ps -ef | grep mplayer`" - if echo "$URLS" | while read URL NAME; do - if [ "`echo "$EV" | grep \"$URL\"`" ] ;then - echo "** $NAME running ($URL)" - exit 1 - fi - done; then - echo "** no stream running" - return 1 - else - return 0 - fi -} -function current() -{ - - return 1 -} -function list() -{ - echo "$URLS" | while read URL NAME ; do - echo "$NAME : $URL" - done - -} - -function shorthelp() -{ - echo "start|stop|restart|status|list [audio stream]" -} -function longhelp() -{ - B=`basename $0` - echo -n "Usage: $B " - shorthelp - echo " get all available streams with '/$B list' -Examples: - $B list - $B start groove - $B restart deepmix - $B status - $B stop" -} - - -case "$1" in - start) - start ${2-"`test -f $stream_file && cat $stream_file`"} - ;; - stop) - stop - ;; - (switch|restart) - stop - start $2 - ;; - status) - status - exit $? - ;; - list) - list - ;; - (--help) - shorthelp - ;; - *) - longhelp - ;; -esac diff --git a/streams/streams.py b/streams/streams.py deleted file mode 100644 index 65669b2d..00000000 --- a/streams/streams.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/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) -- cgit v1.2.3