From 8ccb960a1e47ad7e54815076904f1b8f017f19ec Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Tue, 3 Jun 2014 22:44:55 +0100 Subject: [PATCH] Added existing scratch files --- src/live.py | 5 ++++ src/player.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/server.py | 13 ++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/live.py create mode 100644 src/player.py create mode 100644 src/server.py diff --git a/src/live.py b/src/live.py new file mode 100644 index 0000000..9bc586e --- /dev/null +++ b/src/live.py @@ -0,0 +1,5 @@ +from core.radio.player import RadioPlayer + + +class LiveRadioPlayer(RadioPlayer): + pass diff --git a/src/player.py b/src/player.py new file mode 100644 index 0000000..5295ea7 --- /dev/null +++ b/src/player.py @@ -0,0 +1,68 @@ +import shout +import time +import sys + + +class RadioConnectionException(Exception): + pass + + +class RadioPlayer(): + def __init__(self, host="localhost", port=8501, user='source', password='hackme', mount='/mymout'): + self._s = shout.Shout() + self._s.host = host + self._s.port = port + self._s.user = user + self._s.password = password + self._s.mount = mount + self._status = shout.SHOUTERR_UNCONNECTED + + @staticmethod + def format_songname(song): + result = song.split("/")[-1].split(".") + result = ".".join(result[:len(result) - 1]).replace("_", " ").replace("-", " - ") + return result + + def open_player(self): + if self._status != shout.SHOUTERR_CONNECTED: + self._status = self._s.open() + if self._status != shout.SHOUTERR_CONNECTED: + raise RadioConnectionException("Unable to connect to server: %d", self._status) + + def close_player(self): + if self._status == shout.SHOUTERR_CONNECTED: + self._s.close() + + def play_track(self, song_name="", song_file=""): + self._s.format = 'mp3' + # self._s.protocol = 'http' | 'xaudiocast' | 'icy' + self._s.name = 'Deep South Sounds' + # self._s.genre = 'Deep House' + # self._s.url = 'http://www.deepsouthsounds.com/' + # self._s.public = 0 | 1 + # self._s.audio_info = { 'key': 'val', ... } + # (keys are shout.SHOUT_AI_BITRATE, shout.SHOUT_AI_SAMPLERATE, + # shout.SHOUT_AI_CHANNELS, shout.SHOUT_AI_QUALITY) + + + total = 0 + st = time.time() + print "opening file %s" % song_file + f = open(song_file) + self._s.set_metadata({'song': str(song_name)}) + + nbuf = f.read(4096) + while 1: + buf = nbuf + nbuf = f.read(4096) + total += len(buf) + if len(buf) == 0: + break + self._s.send(buf) + self._s.sync() + f.close() + + et = time.time() + br = total * 0.008 / (et - st) + print "Sent %d bytes in %d seconds (%f kbps)" % (total, et - st, br) + pass diff --git a/src/server.py b/src/server.py new file mode 100644 index 0000000..a3d0346 --- /dev/null +++ b/src/server.py @@ -0,0 +1,13 @@ +from celery import Celery +#//Settings module stuff +BROKER_HOST = "amqp://dss-radio:Ku9hwTn0XT5Xo@localhost:5672//" +#//Settings module stuff + +app = Celery('server', BROKER_HOST) + +@app.task +def add(x, y): + return x + y + + +