diff --git a/backend/videoflix/content/signals.py b/backend/videoflix/content/signals.py index a8f44d8..a09bd08 100644 --- a/backend/videoflix/content/signals.py +++ b/backend/videoflix/content/signals.py @@ -18,7 +18,7 @@ def video_post_save(sender, instance, created, **kwargs): create_thumbnails(instance, instance.id) #Convert video - for resolution in ["720", "480", "1080"]: + for resolution in ["1280x720", "640x360", "1920x1080"]: queue.enqueue(convert_video_to_hls, instance.video_file.path, resolution, instance.id) #Delete the original video file @@ -51,7 +51,7 @@ def delete_converted_files(video_file_path): """ Delete all converted video files related to the original video file. """ - resolutions = ["480", "720", "1080"] + resolutions = ["360", "720", "1080"] for resolution in resolutions: converted_video_path = video_file_path + f'_{resolution}p.mp4' converted_video_path = remove_first_mp4(converted_video_path) diff --git a/backend/videoflix/content/tasks.py b/backend/videoflix/content/tasks.py index c1f6037..a2f4242 100644 --- a/backend/videoflix/content/tasks.py +++ b/backend/videoflix/content/tasks.py @@ -8,24 +8,26 @@ def convert_video_to_hls(source, resolution, model_id): """ Converts a video to the HLS format """ + resolution_after_x = resolution.split('x')[1] if 'x' in resolution else resolution + target_dir = os.path.join(os.path.dirname(source), str(model_id)) os.makedirs(target_dir, exist_ok=True) base_filename = os.path.basename(source).split(".")[0] - target = os.path.join(target_dir, f'{base_filename}_{resolution}p') + target = os.path.join(target_dir, f'{base_filename}_{resolution_after_x}p') ffmpeg_path = shutil.which("ffmpeg") cmd = [ ffmpeg_path, '-i', source, - '-s', f'hd{resolution}', + '-s', resolution, '-c:v', 'libx264', '-crf', '23', '-c:a', 'aac', '-strict', '-2', '-hls_time', '10', '-hls_playlist_type', 'vod', - '-hls_segment_filename', os.path.join(target_dir, f'{base_filename}_{resolution}p_%03d.ts'), + '-hls_segment_filename', os.path.join(target_dir, f'{base_filename}_{resolution_after_x}p_%03d.ts'), f'{target}.m3u8' ] diff --git a/backend/videoflix/content/views.py b/backend/videoflix/content/views.py index 9796521..5ecd6fc 100644 --- a/backend/videoflix/content/views.py +++ b/backend/videoflix/content/views.py @@ -12,12 +12,12 @@ from rest_framework.parsers import MultiPartParser, FormParser from django.http import JsonResponse import os -CACHETTL = getattr(settings, 'CACHE_TTL', DEFAULT_TIMEOUT) +CACHE_TTL = getattr(settings, 'CACHE_TTL', DEFAULT_TIMEOUT) # Create your views here. @api_view(['GET']) @permission_classes([IsAuthenticated]) -@cache_page(CACHETTL) +#@cache_page(CACHE_TTL) def video_list(request): """ List all videos. @@ -28,11 +28,11 @@ def video_list(request): @api_view(['GET']) @permission_classes([IsAuthenticated]) -def check_video(request, id): +def check_video_resolutions(request, id): """ - Check if a specific video exists in different resolutions (480p, 720p, 1080p). + Check if a specific video exists in different resolutions (360p, 720p, 1080p). """ - resolutions = ['480', '720', '1080'] + resolutions = ['360', '720', '1080'] result = {} try: @@ -59,6 +59,7 @@ def video_upload(request): if request.method == 'POST': serializer = VideoSerializer(data=request.data) if serializer.is_valid(): - serializer.save() + creator = request.user + serializer.save(creator=creator) return Response(serializer.data, status=201) return Response({"error": "Invalid data", "details": serializer.errors}, status=400) \ No newline at end of file diff --git a/backend/videoflix/videoflix/urls.py b/backend/videoflix/videoflix/urls.py index 0219a01..8106dea 100644 --- a/backend/videoflix/videoflix/urls.py +++ b/backend/videoflix/videoflix/urls.py @@ -38,7 +38,7 @@ urlpatterns = [ # Content URLs path('content/', content_views.video_list, name='video_list'), path('content/upload/', content_views.video_upload, name='video_upload'), - path('content/movie//', content_views.check_video, name='check_video'), + path('content/movie//', content_views.check_video_resolutions, name='check_video_resolutions'), # Users URLs path('users/', user_views.user_list, name='user_list'), diff --git a/frontend/src/app/components/home/browse/browse.component.html b/frontend/src/app/components/home/browse/browse.component.html index 7d6f4e1..7a5eaf9 100644 --- a/frontend/src/app/components/home/browse/browse.component.html +++ b/frontend/src/app/components/home/browse/browse.component.html @@ -43,13 +43,13 @@