изменил адрес прода азуры + добавил файл с переменными окружения
This commit is contained in:
parent
43be693e7c
commit
73417d12be
|
|
@ -18,4 +18,6 @@ server/proj/static/rest_framework
|
||||||
__pycache__
|
__pycache__
|
||||||
media/
|
media/
|
||||||
env/
|
env/
|
||||||
|
__init__.py
|
||||||
|
.env
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ ROBOTS_ALLOW=
|
||||||
ROBOTS_DISALLOW=["/"]
|
ROBOTS_DISALLOW=["/"]
|
||||||
SERVICE_SELF_URL=//itradio.team
|
SERVICE_SELF_URL=//itradio.team
|
||||||
SERVICE_URL=//itradio.team
|
SERVICE_URL=//itradio.team
|
||||||
SERVICE_URL_AUDIO=//82.97.242.49:10443
|
SERVICE_URL_AUDIO=//azuracast.itradio.team
|
||||||
SERVICE_PROTOCOL=https
|
SERVICE_PROTOCOL=https
|
||||||
SERVICE_PORT=8000
|
SERVICE_PORT=8000
|
||||||
SERVICE_API=/api
|
SERVICE_API=/api
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
# from django.contrib import admin
|
|
||||||
# from .models import NowPlayingSong
|
|
||||||
|
|
||||||
# # Register your models here.
|
|
||||||
# admin.site.register(NowPlayingSong)
|
|
||||||
|
|
@ -6,44 +6,4 @@ from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.permissions import AllowAny
|
from rest_framework.permissions import AllowAny
|
||||||
|
from conf.settings.base import AZURACAST_API_KEY, AZURACAST_URL
|
||||||
class FetchAndServeFile(ViewSet):
|
|
||||||
def list(self, request):
|
|
||||||
file_url = f"http://82.97.242.49:10084/api/station/it-radio/file/fc6377b2dae75d29358783bc"
|
|
||||||
api_key = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
|
|
||||||
|
|
||||||
headers = {
|
|
||||||
"Authorization": f"Bearer {api_key}"
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = requests.get(file_url, headers=headers)
|
|
||||||
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
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 retrieve(self, request, pk=None):
|
|
||||||
file_url = f"http://82.97.242.49:10084/api/station/it-radio/file/{pk}/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)
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ from django.http import HttpResponse
|
||||||
from .schemas import SongSchema, DeleteSongSchema, PlayListSchema
|
from .schemas import SongSchema, DeleteSongSchema, PlayListSchema
|
||||||
from .models import Song, FavoriteSong, PlayList
|
from .models import Song, FavoriteSong, PlayList
|
||||||
from .serializers import SongSerializer, FavoriteSongSerializer, PlayListSerializer
|
from .serializers import SongSerializer, FavoriteSongSerializer, PlayListSerializer
|
||||||
|
from conf.settings.base import AZURACAST_URL, AZURACAST_API_KEY
|
||||||
|
|
||||||
class PlayListViewSet(GenericViewSet):
|
class PlayListViewSet(GenericViewSet):
|
||||||
queryset = PlayList
|
queryset = PlayList
|
||||||
|
|
@ -102,14 +103,14 @@ class PlayListViewSet(GenericViewSet):
|
||||||
try:
|
try:
|
||||||
song = Song.objects.get(azura_id=request.data.get('azura_id')).pk
|
song = Song.objects.get(azura_id=request.data.get('azura_id')).pk
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
file_url = f"http://82.97.242.49:10084/api/station/it-radio/file/{request.data['azura_id']}"
|
file_url = f"{AZURACAST_URL}api/station/it-radio/file/{request.data['azura_id']}"
|
||||||
API_KEY = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
|
API_KEY = AZURACAST_API_KEY
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {API_KEY}"
|
"Authorization": f"Bearer {API_KEY}"
|
||||||
}
|
}
|
||||||
response = requests.get(file_url, headers=headers)
|
response = requests.get(file_url, headers=headers)
|
||||||
data = request.data
|
data = request.data
|
||||||
file_play = f"http://82.97.242.49:10084/api/station/it-radio/file/{response.json()['unique_id']}/play"
|
file_play = f"{AZURACAST_URL}api/station/it-radio/file/{response.json()['unique_id']}/play"
|
||||||
data.update(unique_id=file_play)
|
data.update(unique_id=file_play)
|
||||||
song_serializer = SongSerializer(data=data)
|
song_serializer = SongSerializer(data=data)
|
||||||
if song_serializer.is_valid():
|
if song_serializer.is_valid():
|
||||||
|
|
@ -168,7 +169,7 @@ class SongViewSet(GenericViewSet):
|
||||||
try:
|
try:
|
||||||
song_obj = Song.objects.get(azura_id=azura_id)
|
song_obj = Song.objects.get(azura_id=azura_id)
|
||||||
file_url = song_obj.unique_id
|
file_url = song_obj.unique_id
|
||||||
API_KEY = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
|
API_KEY = AZURACAST_API_KEY
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {API_KEY}"
|
"Authorization": f"Bearer {API_KEY}"
|
||||||
}
|
}
|
||||||
|
|
@ -195,14 +196,14 @@ class SongViewSet(GenericViewSet):
|
||||||
"user": request.user.pk
|
"user": request.user.pk
|
||||||
}
|
}
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
file_url = f"http://82.97.242.49:10084/api/station/it-radio/file/{request.data['azura_id']}"
|
file_url = f"{AZURACAST_URL}api/station/it-radio/file/{request.data['azura_id']}"
|
||||||
API_KEY = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
|
API_KEY = AZURACAST_API_KEY
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {API_KEY}"
|
"Authorization": f"Bearer {API_KEY}"
|
||||||
}
|
}
|
||||||
response = requests.get(file_url, headers=headers)
|
response = requests.get(file_url, headers=headers)
|
||||||
data = request.data
|
data = request.data
|
||||||
file_play = f"http://82.97.242.49:10084/api/station/it-radio/file/{response.json()['unique_id']}/play"
|
file_play = f"{AZURACAST_URL}/api/station/it-radio/file/{response.json()['unique_id']}/play"
|
||||||
data.update(unique_id=file_play)
|
data.update(unique_id=file_play)
|
||||||
serializer = SongSerializer(data=data)
|
serializer = SongSerializer(data=data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
|
|
@ -230,8 +231,8 @@ class SongViewSet(GenericViewSet):
|
||||||
|
|
||||||
@action(detail=False, methods=['get'])
|
@action(detail=False, methods=['get'])
|
||||||
def get_all_song(self, request):
|
def get_all_song(self, request):
|
||||||
file_url = "http://82.97.242.49:10084/api/station/1/files"
|
file_url = F"{AZURACAST_URL}api/station/1/files"
|
||||||
API_KEY = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
|
API_KEY = AZURACAST_API_KEY
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {API_KEY}"
|
"Authorization": f"Bearer {API_KEY}"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,5 +1,6 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
from decouple import config
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
@ -15,7 +16,7 @@ MEDIA_URL = 'media/'
|
||||||
STATIC_ROOT = PROJECT_DIR / 'static'
|
STATIC_ROOT = PROJECT_DIR / 'static'
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'django-insecure-z242=*-knp4h=0l1*o-nyid^y0bwt4bvg3tf*wvr(qszj&!8$c'
|
SECRET_KEY = config('SECRET_KEY')
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
@ -160,4 +161,9 @@ CORS_ALLOW_CREDENTIALS = True
|
||||||
CORS_ALLOWED_ORIGINS = [
|
CORS_ALLOWED_ORIGINS = [
|
||||||
'http://localhost:5173',
|
'http://localhost:5173',
|
||||||
]
|
]
|
||||||
MIN_LEN_PASSWORD = 8
|
MIN_LEN_PASSWORD = 8
|
||||||
|
|
||||||
|
###AZURACAST CONFIG###
|
||||||
|
AZURACAST_URL = 'https://azuracast.itradio.team/'
|
||||||
|
AZURACAST_API_KEY = config('AZURACAST_API_KEY')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ from rest_framework import routers
|
||||||
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
|
|
||||||
from audio.views import SongViewSet, PlayListViewSet
|
from audio.views import SongViewSet, PlayListViewSet
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -20,7 +19,6 @@ router.register(r'teams', TeamViewSet, basename='teams')
|
||||||
router.register(r'rubriks', RubricViewSet, basename='rubriks')
|
router.register(r'rubriks', RubricViewSet, basename='rubriks')
|
||||||
router.register(r'playlists', PlayListViewSet, basename='playlists')
|
router.register(r'playlists', PlayListViewSet, basename='playlists')
|
||||||
router.register(r'song', SongViewSet, basename='song')
|
router.register(r'song', SongViewSet, basename='song')
|
||||||
router.register(r'fetchandservefile', FetchAndServeFile, basename='fetchandservefile')
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('api/admin/', admin.site.urls),
|
path('api/admin/', admin.site.urls),
|
||||||
|
|
@ -31,8 +29,7 @@ urlpatterns = [
|
||||||
path('api/', include_docs_urls(title='API docs')),
|
path('api/', include_docs_urls(title='API docs')),
|
||||||
path('api/radio/', include(router.urls)),
|
path('api/radio/', include(router.urls)),
|
||||||
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||||
path('api/user/', include('account.urls', namespace='user')),
|
path('api/user/', include('account.urls', namespace='user'))
|
||||||
# path('webhook/', AzuraNowPlayingWebhookView.as_view(), name='webhook-receiver'),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue