mirror of
https://github.com/fergalmoran/dss.api.git
synced 2026-01-09 01:54:03 +00:00
Merge branch 'feature/radio_player' into develop
This commit is contained in:
@@ -2,10 +2,12 @@ import datetime
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_201_CREATED, HTTP_204_NO_CONTENT, HTTP_200_OK
|
||||
from rest_framework.views import APIView
|
||||
from core.radio import ice_scrobbler
|
||||
from dss import settings
|
||||
from spa.models import Mix, UserProfile
|
||||
from core.utils import session
|
||||
|
||||
|
||||
class Helper(APIView):
|
||||
pass
|
||||
|
||||
@@ -22,7 +24,7 @@ class ChatHelper(ActivityHelper):
|
||||
# do some persistence stuff with the chat
|
||||
from core.realtime import chat
|
||||
|
||||
#user = self.get_session(request)
|
||||
# user = self.get_session(request)
|
||||
u = request.user
|
||||
if not u.is_anonymous():
|
||||
image = u.userprofile.get_sized_avatar_image(32, 32)
|
||||
@@ -59,3 +61,18 @@ class UserSlugCheckHelper(Helper):
|
||||
return Response(status=HTTP_204_NO_CONTENT)
|
||||
except UserProfile.DoesNotExist:
|
||||
return Response(status=HTTP_200_OK)
|
||||
|
||||
|
||||
class RadioHelper(Helper):
|
||||
def get(self, request):
|
||||
if 'rmix' in self.request.query_params:
|
||||
m = Mix.objects.order_by('?').first()
|
||||
ret = {
|
||||
'url': m.get_stream_url(),
|
||||
'slug': m.get_full_url(),
|
||||
'title': str(m)
|
||||
}
|
||||
elif 'np' in self.request.query_params:
|
||||
ret = ice_scrobbler.get_server_details("localhost", "8000", "dss")
|
||||
|
||||
return Response(data=ret, status=HTTP_200_OK)
|
||||
|
||||
@@ -64,6 +64,7 @@ urlpatterns = patterns(
|
||||
url(r'^_act/play', helpers.ActivityPlayHelper.as_view()),
|
||||
url(r'^_chat/', helpers.ChatHelper.as_view()),
|
||||
|
||||
url(r'^_radio', helpers.RadioHelper.as_view()),
|
||||
|
||||
url(r'^__debug/', DebugView.as_view()),
|
||||
|
||||
|
||||
BIN
core/jingles/220.mp3
Normal file
BIN
core/jingles/220.mp3
Normal file
Binary file not shown.
BIN
core/jingles/360.mp3
Normal file
BIN
core/jingles/360.mp3
Normal file
Binary file not shown.
BIN
core/jingles/440.mp3
Normal file
BIN
core/jingles/440.mp3
Normal file
Binary file not shown.
1
core/radio/__init__.py
Normal file
1
core/radio/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'fergalm'
|
||||
45
core/radio/ice_scrobbler.py
Normal file
45
core/radio/ice_scrobbler.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from requests.packages.urllib3.connection import ConnectionError
|
||||
|
||||
|
||||
def get_server_details(server, port, mount):
|
||||
server = "http://%s:%s/status.xsl?mount=/%s" % (server, port, mount)
|
||||
print("Getting info for %s" % server)
|
||||
try:
|
||||
response = requests.get(server)
|
||||
html = response.text
|
||||
if html:
|
||||
try:
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
info = {
|
||||
'stream_title': soup.find(text="Stream Title:").findNext('td').contents[0],
|
||||
'stream_description': soup.find(text="Stream Description:").findNext('td').contents[0],
|
||||
'content_type': soup.find(text="Content Type:").findNext('td').contents[0],
|
||||
'mount_started': soup.find(text="Mount started:").findNext('td').contents[0],
|
||||
'current_listeners': soup.find(text="Current Listeners:").findNext('td').contents[0],
|
||||
'peak_listeners': soup.find(text="Peak Listeners:").findNext('td').contents[0],
|
||||
'stream_url': soup.find(text="Stream URL:").findNext('td').findNext('a').contents[0],
|
||||
'current_song': soup.find(text="Current Song:").findNext('td').contents[0]
|
||||
}
|
||||
return {
|
||||
'status': 2,
|
||||
'metadata': info
|
||||
}
|
||||
except AttributeError:
|
||||
return {
|
||||
'status': 1
|
||||
}
|
||||
else:
|
||||
return {
|
||||
'status': 0
|
||||
}
|
||||
except Exception as ex:
|
||||
return {
|
||||
'status': 0
|
||||
}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
d = get_server_details("localhost", "8000", "dss")
|
||||
print(d)
|
||||
@@ -95,7 +95,7 @@ class Mix(BaseModel):
|
||||
return self.__unicode__()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
return "{} - {}".format(self.user.get_nice_name(), self.title)
|
||||
|
||||
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
|
||||
if not self.id:
|
||||
|
||||
Reference in New Issue
Block a user