|
@@ -70,6 +70,7 @@ from .serializers import (
|
|
|
from .stop_words import STOP_WORDS
|
|
|
from .tasks import save_user_action
|
|
|
from .tasks import save_voice_action
|
|
|
+from .tasks import video_with_voices
|
|
|
|
|
|
# TODO: Should we consider USER_VOICE_ACTIONS too?
|
|
|
VALID_USER_ACTIONS = [action for action, name in USER_MEDIA_ACTIONS]
|
|
@@ -861,51 +862,33 @@ class VideoWithVoices(APIView):
|
|
|
|
|
|
@swagger_auto_schema(
|
|
|
manual_parameters=[],
|
|
|
- tags=['Voice Actions'],
|
|
|
+ tags=['Combine a video media with some voices'],
|
|
|
operation_summary='to_be_written',
|
|
|
operation_description='to_be_written',
|
|
|
)
|
|
|
- def post(self, request, friendly_token, uid=None):
|
|
|
- # perform like/dislike/report actions
|
|
|
- #
|
|
|
- # Test command:
|
|
|
- # curl -X POST http://127.0.0.1:80/api/v1/media/dd9TrZxDe/voices/f07f84a8-cf0a-445f-8ae7-568b16ddce55/actions
|
|
|
- # Response:
|
|
|
- # {"detail":"action allowed on logged in users only"}
|
|
|
-
|
|
|
+ def post(self, request, friendly_token):
|
|
|
media = self.get_object(friendly_token)
|
|
|
if isinstance(media, Response):
|
|
|
return media
|
|
|
|
|
|
- # Double-check voice existence.
|
|
|
- try:
|
|
|
- voice = Voice.objects.get(uid=uid)
|
|
|
- except BaseException:
|
|
|
- return Response({"detail": "voice does not exist"}, status=status.HTTP_400_BAD_REQUEST,)
|
|
|
+ voicesUid = request.data.get("voicesUid")
|
|
|
+ voicesSrc = request.data.get("voicesSrc")
|
|
|
|
|
|
- action = request.data.get("type")
|
|
|
- extra = request.data.get("extra_info")
|
|
|
- if request.user.is_anonymous:
|
|
|
- # there is a list of allowed actions for
|
|
|
- # anonymous users, specified in settings
|
|
|
- if action not in settings.ALLOW_ANONYMOUS_ACTIONS:
|
|
|
- return Response(
|
|
|
- {"detail": "action allowed on logged in users only"},
|
|
|
- status=status.HTTP_400_BAD_REQUEST,
|
|
|
- )
|
|
|
- if action:
|
|
|
- user_or_session = get_user_or_session(request)
|
|
|
- save_voice_action.delay(
|
|
|
- user_or_session,
|
|
|
- friendly_token=media.friendly_token,
|
|
|
- action=action,
|
|
|
- extra_info=extra,
|
|
|
- uid=voice.uid,
|
|
|
- )
|
|
|
+ for uid in voicesUid:
|
|
|
+ # Double-check voice existence.
|
|
|
+ try:
|
|
|
+ voice = Voice.objects.get(uid=uid)
|
|
|
+ except BaseException:
|
|
|
+ return Response({"detail": "voice does not exist"}, status=status.HTTP_400_BAD_REQUEST,)
|
|
|
|
|
|
- return Response({"detail": "action received"}, status=status.HTTP_201_CREATED)
|
|
|
- else:
|
|
|
- return Response({"detail": "no action specified"}, status=status.HTTP_400_BAD_REQUEST)
|
|
|
+ user_or_session = get_user_or_session(request)
|
|
|
+ video_with_voices.delay(
|
|
|
+ user_or_session,
|
|
|
+ friendly_token=media.friendly_token,
|
|
|
+ voicesUid=voicesUid,
|
|
|
+ )
|
|
|
+
|
|
|
+ return Response({"detail": "video is combined with voices, it's ready for download"}, status=status.HTTP_201_CREATED)
|
|
|
|
|
|
class MediaSearch(APIView):
|
|
|
"""
|