Commit aeaa194a authored by fred's avatar fred

add publish_to_icecast management command

parent 75f92077
import requests
import urllib
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from emissions.utils import whatsonair
from nonstop.utils import get_current_nonstop_track
class Command(BaseCommand):
def handle(self, *args, **options):
onair = whatsonair()
onair_txt = None
if onair.get('episode'):
onair_txt = '%s - %s' % (
onair.get('emission').title,
onair.get('episode').title)
elif onair.get('emission'):
onair_txt = onair.get('emission').title
elif onair.get('nonstop'):
track = get_current_nonstop_track()
if 'track_artist' in track:
onair_txt = '%s - %s (%s)' % (
onair.get('nonstop').title,
track.get('track_title'),
track.get('track_artist'))
elif 'track_title' in track:
onair_txt = '%s - %s' % (
onair.get('nonstop').title,
track.get('track_title'))
else:
onair_txt = onair.get('nonstop').title
if not onair_txt:
return
for stream_url in settings.STREAM_UPDATE_URLS:
r = requests.get(stream_url + '&song=' + urllib.quote(onair_txt.encode('utf-8')), timeout=5)
r.raise_for_status()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment