Skip to content

Commit

Permalink
add streams/:id/kill/ endpoint to allow for easy killing of streams (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hburgund committed Nov 14, 2017
1 parent 3b6508b commit f26a636
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
16 changes: 15 additions & 1 deletion roundware/api2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from roundware.lib.api import (get_project_tags_new as get_project_tags, modify_stream, move_listener, heartbeat,
skip_ahead, pause, resume, add_asset_to_envelope, get_currently_streaming_asset,
save_asset_from_request, vote_asset, check_is_active,
vote_count_by_asset, log_event, play)
vote_count_by_asset, log_event, play, kill)
from roundware.api2.permissions import AuthenticatedReadAdminWrite
from rest_framework import viewsets, status
from rest_framework.permissions import IsAuthenticated, DjangoObjectPermissions
Expand Down Expand Up @@ -828,6 +828,7 @@ class StreamViewSet(viewsets.ViewSet):
api/2/streams/:id/pause/
api/2/streams/:id/resume/
api/2/streams/:id/isactive/
api/2/streams/:id/kill/
"""
permission_classes = (IsAuthenticated,)

Expand Down Expand Up @@ -923,6 +924,19 @@ def isactive(self, request, pk=None):
return Response({"detail": str(e)},
status.HTTP_400_BAD_REQUEST)

@detail_route(methods=['post'])
def kill(self, request, pk=None):
try:
result = kill(pk, "mp3")
stream_id = int(pk)
return Response({
'stream_id': stream_id,
'success': result
})
except Exception as e:
return Response({"detail": str(e)},
status.HTTP_400_BAD_REQUEST)


class TagViewSet(viewsets.ViewSet):
"""
Expand Down
4 changes: 4 additions & 0 deletions roundware/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ def check_is_active(session_id):

return stream_exists(session_id, audio_format)

def kill(session_id, audio_format):
admin = icecast2.Admin()
result = admin.kill_source(icecast2.mount_point(session_id, audio_format))
return result

# create_envelope
# args: (operation, session_id, [tags])
Expand Down
8 changes: 8 additions & 0 deletions roundwared/icecast2.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def stream_exists(self, mount):
return True
return False

def kill_source(self, mount):
result = self.process_xml(
"/admin/killsource?mount=" + mount, "//icestats/source/@mount")
if not self.stream_exists(mount):
return True
else:
return False

def process_xml(self, url, xpath):
# logger.debug("Request: %s, auth=%s", self.base_uri + url, self.auth)
response = requests.get(self.base_uri + url, auth=self.auth)
Expand Down

0 comments on commit f26a636

Please sign in to comment.