добавил вьюшку для плеера одного трека

This commit is contained in:
Mike0001-droid 2024-06-05 17:03:07 +05:00
parent d863d9167e
commit cafe5588f7
2 changed files with 53 additions and 17 deletions

View File

@ -1,18 +1,52 @@
# from rest_framework.views import APIView import requests
# from rest_framework.response import Response from django.http import HttpResponse
# from .models import NowPlayingSong from rest_framework.views import APIView
# from .serializers import WebhookSerializer from rest_framework.viewsets import ViewSet
# import json from rest_framework.response import Response
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.permissions import AllowAny
# class AzuraNowPlayingWebhookView(APIView): class FetchAndServeFile(ViewSet):
# queryset = NowPlayingSong.objects.all()
# def post(self, request, *args, **kwargs): def list(self, request):
# # Ensure the 'now_playing' data includes a 'song' key file_url = f"http://82.97.242.49:10084/api/station/it-radio/file/fc6377b2dae75d29358783bc/play"
# data = request.data.get('now_playing') api_key = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
# serializer = WebhookSerializer(data=data)
# print(data) headers = {
# if serializer.is_valid(): "Authorization": f"Bearer {api_key}"
# song = serializer.save() }
# print("valid")
# return Response(data, status=201) try:
# return Response(serializer.errors, status=400) response = requests.get(file_url, headers=headers)
response.raise_for_status()
# Create a response with the appropriate content type and headers
file_response = HttpResponse(response.content, content_type='audio/mpeg')
file_response['Content-Disposition'] = 'attachment; filename="output.mp3"'
return file_response
except requests.RequestException as e:
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)
""" def get(self, request, station, song_id, *args, **kwargs):
file_url = f"http://82.97.242.49:10084/api/station/{station}/file/{song_id}/play"
api_key = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
headers = {
"Authorization": f"Bearer {api_key}"
}
try:
response = requests.get(file_url, headers=headers)
response.raise_for_status()
# Create a response with the appropriate content type and headers
file_response = HttpResponse(response.content, content_type='audio/mpeg')
file_response['Content-Disposition'] = 'attachment; filename="output.mp3"'
return file_response
except requests.RequestException as e:
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST) """

View File

@ -15,11 +15,13 @@ from rest_framework import routers, serializers, viewsets
from userProfile.views import TeamViewSet from userProfile.views import TeamViewSet
from django.conf import settings from django.conf import settings
from rubricks.views import RubricViewSet from rubricks.views import RubricViewSet
from api.views import FetchAndServeFile
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'news', newsViews.NewsViewSet) router.register(r'news', newsViews.NewsViewSet)
#router.register(r'profiles', ProfileViewSet, basename='profiles') #router.register(r'profiles', ProfileViewSet, basename='profiles')
router.register(r'single_play', FetchAndServeFile, basename='single_play')
router.register(r'teams', TeamViewSet, basename='teams') router.register(r'teams', TeamViewSet, basename='teams')
router.register(r'rubriks', RubricViewSet, basename='rubriks') router.register(r'rubriks', RubricViewSet, basename='rubriks')