mirror of
https://github.com/fergalmoran/dss.git
synced 2025-12-22 09:38:18 +00:00
Rudimentary radio player added
This commit is contained in:
@@ -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
|
|
||||||
|
|
||||||
@@ -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)
|
|
||||||
@@ -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)
|
|
||||||
1
core/radio/__init__.py
Normal file
1
core/radio/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
__author__ = 'fergalm'
|
||||||
5
core/radio/live.py
Normal file
5
core/radio/live.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from core.radio.player import RadioPlayer
|
||||||
|
|
||||||
|
|
||||||
|
class LiveRadioPlayer(RadioPlayer):
|
||||||
|
pass
|
||||||
53
core/radio/player.py
Normal file
53
core/radio/player.py
Normal file
@@ -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
|
||||||
36
spa/management/commands/radio.py
Normal file
36
spa/management/commands/radio.py
Normal file
@@ -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
|
||||||
@@ -69,7 +69,7 @@ class Mix(_BaseModel):
|
|||||||
|
|
||||||
genres = models.ManyToManyField(Genre)
|
genres = models.ManyToManyField(Genre)
|
||||||
|
|
||||||
#activity based stuff
|
# activity based stuff
|
||||||
favourites = models.ManyToManyField(UserProfile, related_name='favourites', blank=True, null=True)
|
favourites = models.ManyToManyField(UserProfile, related_name='favourites', blank=True, null=True)
|
||||||
likes = models.ManyToManyField(UserProfile, related_name='likes', 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):
|
def get_waveform_url(self):
|
||||||
if self.waveform_generated:
|
if self.waveform_generated:
|
||||||
waveform_root = localsettings.WAVEFORM_URL if hasattr(localsettings,
|
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")
|
ret = "%s/%s.%s" % (waveform_root, self.uid, "png")
|
||||||
return url.urlclean(ret)
|
return url.urlclean(ret)
|
||||||
|
|||||||
Reference in New Issue
Block a user