diff --git a/_working/create b/_working/create deleted file mode 100755 index c6c7088..0000000 --- a/_working/create +++ /dev/null @@ -1,8 +0,0 @@ -mysql -u root deepsouthsounds < _working/mix.sql -mysql -u root deepsouthsounds < _working/label.sql -mysql -u root deepsouthsounds < _working/release.sql -mysql -u root deepsouthsounds < _working/social.sql -mysql -u root deepsouthsounds < _working/venue.sql -mysql -u root deepsouthsounds < _working/recurrence.sql -mysql -u root deepsouthsounds < _working/event.sql - diff --git a/_working/get_downloads.sql b/_working/get_downloads.sql deleted file mode 100755 index 0c94927..0000000 --- a/_working/get_downloads.sql +++ /dev/null @@ -1,5 +0,0 @@ -SELECT spa__activity.`date`, spa__activity.user_id, spa_mixdownload.mix_id - FROM deepsouthsounds.spa_mixdownload spa_mixdownload - INNER JOIN - deepsouthsounds.spa__activity spa__activity - ON (spa_mixdownload._activity_ptr_id = spa__activity.id) \ No newline at end of file diff --git a/_working/get_plays.sql b/_working/get_plays.sql deleted file mode 100755 index 9a15368..0000000 --- a/_working/get_plays.sql +++ /dev/null @@ -1,5 +0,0 @@ -SELECT spa__activity.`date`, spa__activity.user_id, spa_mixplay.mix_id - FROM deepsouthsounds.spa_mixplay spa_mixplay - INNER JOIN - deepsouthsounds.spa__activity spa__activity - ON (spa_mixplay._activity_ptr_id = spa__activity.id) \ No newline at end of file diff --git a/core/radio/__init__.py b/core/radio/__init__.py new file mode 100644 index 0000000..6d4caf8 --- /dev/null +++ b/core/radio/__init__.py @@ -0,0 +1 @@ +__author__ = 'fergalm' diff --git a/core/radio/live.py b/core/radio/live.py new file mode 100644 index 0000000..9bc586e --- /dev/null +++ b/core/radio/live.py @@ -0,0 +1,5 @@ +from core.radio.player import RadioPlayer + + +class LiveRadioPlayer(RadioPlayer): + pass diff --git a/core/radio/player.py b/core/radio/player.py new file mode 100644 index 0000000..05f42da --- /dev/null +++ b/core/radio/player.py @@ -0,0 +1,53 @@ +import shout +import time +import sys + + +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 + + def format_songname(self, song): + result = song.split("/")[-1].split(".") + result = ".".join(result[:len(result) - 1]).replace("_", " ").replace("-", " - ") + return result + + 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) + + t = self._s.open() + + 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/spa/management/commands/radio.py b/spa/management/commands/radio.py new file mode 100644 index 0000000..40a78a4 --- /dev/null +++ b/spa/management/commands/radio.py @@ -0,0 +1,36 @@ +from optparse import make_option +from django.core.management.base import NoArgsCommand, BaseCommand +from core.radio.live import LiveRadioPlayer +from dss import localsettings +from spa.models import Mix + + +class Command(NoArgsCommand): + option_list = BaseCommand.option_list + ( + make_option('--play', + action='store', + dest='play', + help='Slug or id of file to play'), + ) + + def handle(self, *args, **options): + if options['play']: + print "Playing %s" % options['play'] + play_mix(options['play']) + else: + print "Must supply an action" + + +def play_mix(param): + try: + mix = Mix.objects.get(slug=param) + LiveRadioPlayer( + host=localsettings.RADIO_HOST, + port=localsettings.RADIO_PORT, + password=localsettings.RADIO_PASSWORD, + mount=localsettings.RADIO_MOUNT + ).play_track(song_name=mix.title, song_file=mix.get_absolute_path()) + + print "Mix %s located, proceeding to play" % param + except Mix.DoesNotExist: + print "Mix %s not found" % param \ No newline at end of file diff --git a/spa/models/mix.py b/spa/models/mix.py index 0b09fd1..e006d27 100755 --- a/spa/models/mix.py +++ b/spa/models/mix.py @@ -69,7 +69,7 @@ class Mix(_BaseModel): genres = models.ManyToManyField(Genre) - #activity based stuff + # activity based stuff favourites = models.ManyToManyField(UserProfile, related_name='favourites', blank=True, null=True) likes = models.ManyToManyField(UserProfile, related_name='likes', blank=True, null=True) @@ -136,7 +136,7 @@ class Mix(_BaseModel): def get_waveform_url(self): if self.waveform_generated: waveform_root = localsettings.WAVEFORM_URL if hasattr(localsettings, - 'WAVEFORM_URL') else "%swaveforms" % settings.MEDIA_URL + 'WAVEFORM_URL') else "%swaveforms" % settings.MEDIA_URL ret = "%s/%s.%s" % (waveform_root, self.uid, "png") return url.urlclean(ret)