From bf99241ad283fde8db3c19cf266e66af34b3050f Mon Sep 17 00:00:00 2001 From: Laurent DEFERT Date: Tue, 27 Dec 2022 23:51:03 +0100 Subject: [PATCH] embedded video player, video downloads --- config/root/etc/nginx/nginx.conf | 5 +++++ tubesync/sync/models.py | 2 +- tubesync/sync/templates/sync/media-item.html | 6 ++++++ tubesync/sync/urls.py | 6 +++++- tubesync/sync/views.py | 19 +++++++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/config/root/etc/nginx/nginx.conf b/config/root/etc/nginx/nginx.conf index 4cddd7b..14c5aea 100644 --- a/config/root/etc/nginx/nginx.conf +++ b/config/root/etc/nginx/nginx.conf @@ -79,6 +79,11 @@ http { proxy_connect_timeout 10; } + # File dwnload and streaming + location /media-data/ { + internal; + alias /downloads/; + } } } diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 4e42086..59ce225 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -21,7 +21,7 @@ from .matching import (get_best_combined_format, get_best_audio_format, from .mediaservers import PlexMediaServer -media_file_storage = FileSystemStorage(location=str(settings.DOWNLOAD_ROOT)) +media_file_storage = FileSystemStorage(location=str(settings.DOWNLOAD_ROOT), base_url='/media-data/') class Source(models.Model): diff --git a/tubesync/sync/templates/sync/media-item.html b/tubesync/sync/templates/sync/media-item.html index 62f6f35..868b1c1 100644 --- a/tubesync/sync/templates/sync/media-item.html +++ b/tubesync/sync/templates/sync/media-item.html @@ -9,6 +9,12 @@ {% if media.title %}

{{ media.title }}

{% endif %}

{{ media.url }}

Downloading to: {{ media.source.directory_path }}

+ {% if download_state == 'downloaded' %} + +

Download

+ {% endif %} {% if not media.can_download %}{% include 'errorbox.html' with message='Media cannot be downloaded because it has no formats which match the source requirements.' %}{% endif %} diff --git a/tubesync/sync/urls.py b/tubesync/sync/urls.py index 9632c3c..bfe73b7 100644 --- a/tubesync/sync/urls.py +++ b/tubesync/sync/urls.py @@ -2,7 +2,7 @@ from django.urls import path from .views import (DashboardView, SourcesView, ValidateSourceView, AddSourceView, SourceView, UpdateSourceView, DeleteSourceView, MediaView, MediaThumbView, MediaItemView, MediaRedownloadView, MediaSkipView, - MediaEnableView, TasksView, CompletedTasksView, ResetTasks, + MediaEnableView, MediaContent, TasksView, CompletedTasksView, ResetTasks, MediaServersView, AddMediaServerView, MediaServerView, DeleteMediaServerView, UpdateMediaServerView) @@ -70,6 +70,10 @@ urlpatterns = [ MediaEnableView.as_view(), name='enable-media'), + path('media-content/', + MediaContent.as_view(), + name='media-content'), + # Task URLs path('tasks', diff --git a/tubesync/sync/views.py b/tubesync/sync/views.py index ce09fe1..0da9df8 100644 --- a/tubesync/sync/views.py +++ b/tubesync/sync/views.py @@ -686,6 +686,25 @@ class MediaEnableView(FormView, SingleObjectMixin): return append_uri_params(url, {'message': 'enabled'}) +class MediaContent(DetailView): + ''' + Redirect to nginx to download the file + ''' + model = Media + + def __init__(self, *args, **kwargs): + self.object = None + super().__init__(*args, **kwargs) + + def dispatch(self, request, *args, **kwargs): + self.object = self.get_object() + + headers = { + 'X-Accel-Redirect': self.object.media_file.url, + } + return HttpResponse(headers=headers) + + class TasksView(ListView): ''' A list of tasks queued to be completed. This is, for example, scraping for new