diff --git a/config/root/etc/nginx/nginx.conf b/config/root/etc/nginx/nginx.conf index 4cddd7b6..14c5aea9 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/migrations/0013_fix_elative_media_file.py b/tubesync/sync/migrations/0013_fix_elative_media_file.py new file mode 100644 index 00000000..c9eee22e --- /dev/null +++ b/tubesync/sync/migrations/0013_fix_elative_media_file.py @@ -0,0 +1,25 @@ +# Generated by Django 3.2.12 on 2022-04-06 06:19 + +from django.conf import settings +from django.db import migrations, models + + +def fix_media_file(apps, schema_editor): + Media = apps.get_model('sync', 'Media') + for media in Media.objects.filter(downloaded=True): + download_dir = str(settings.DOWNLOAD_ROOT) + + if media.media_file.name.startswith(download_dir): + media.media_file.name = media.media_file.name[len(download_dir) + 1:] + media.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('sync', '0012_alter_media_downloaded_format'), + ] + + operations = [ + migrations.RunPython(fix_media_file) + ] diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 15437f61..59ce2253 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -21,7 +21,7 @@ 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): @@ -392,10 +392,14 @@ def format_summary(self): @property def directory_path(self): download_dir = Path(media_file_storage.location) + return download_dir / self.type_directory_path + + @property + def type_directory_path(self): if self.source_resolution == self.SOURCE_RESOLUTION_AUDIO: - return download_dir / settings.DOWNLOAD_AUDIO_DIR / self.directory + return Path(settings.DOWNLOAD_AUDIO_DIR) / self.directory else: - return download_dir / settings.DOWNLOAD_VIDEO_DIR / self.directory + return Path(settings.DOWNLOAD_VIDEO_DIR) / self.directory def make_directory(self): return os.makedirs(self.directory_path, exist_ok=True) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index 34f13816..a597d11e 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -341,7 +341,7 @@ def download_media(media_id): log.info(f'Successfully downloaded media: {media} (UUID: {media.pk}) to: ' f'"{filepath}"') # Link the media file to the object and update info about the download - media.media_file.name = str(filepath) + media.media_file.name = str(media.source.type_directory_path / media.filename) media.downloaded = True media.download_date = timezone.now() media.downloaded_filesize = os.path.getsize(filepath) diff --git a/tubesync/sync/templates/sync/media-item.html b/tubesync/sync/templates/sync/media-item.html index 62f6f358..868b1c1e 100644 --- a/tubesync/sync/templates/sync/media-item.html +++ b/tubesync/sync/templates/sync/media-item.html @@ -9,6 +9,12 @@
Downloading to: {{ media.source.directory_path }}
+ {% if download_state == 'downloaded' %} + + + {% 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 9632c3c6..bfe73b71 100644 --- a/tubesync/sync/urls.py +++ b/tubesync/sync/urls.py @@ -2,7 +2,7 @@ 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 @@ MediaEnableView.as_view(), name='enable-media'), + path('media-content/