From e69adafcec62847fb48ccfa7e95674eb8cd30a6d Mon Sep 17 00:00:00 2001 From: Laurent DEFERT Date: Wed, 28 Dec 2022 18:37:55 +0100 Subject: [PATCH 1/6] fix deleting media files --- tubesync/sync/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/views.py b/tubesync/sync/views.py index 0da9df8..62d59f8 100644 --- a/tubesync/sync/views.py +++ b/tubesync/sync/views.py @@ -416,7 +416,7 @@ class DeleteSourceView(DeleteView, FormMixin): for media in Media.objects.filter(source=source): if media.media_file: # Delete the media file - delete_file(media.media_file.name) + delete_file(media.media_file.path) # Delete thumbnail copy if it exists delete_file(media.thumbpath) # Delete NFO file if it exists From 5a4e6cee58366abfb37998a9b9fd921850825185 Mon Sep 17 00:00:00 2001 From: Laurent DEFERT Date: Wed, 28 Dec 2022 19:06:16 +0100 Subject: [PATCH 2/6] typo fix --- tubesync/sync/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 59ce225..93f1d7b 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -1266,7 +1266,7 @@ class Media(models.Model): ''' indexer = self.INDEXERS.get(self.source.source_type, None) if not callable(indexer): - raise Exception(f'Meida with source type f"{self.source.source_type}" ' + raise Exception(f'Media with source type f"{self.source.source_type}" ' f'has no indexer') return indexer(self.url) From a7100a0f532e45e914126b3a9d941f04fdd7ad3c Mon Sep 17 00:00:00 2001 From: Laurent DEFERT Date: Wed, 28 Dec 2022 19:06:07 +0100 Subject: [PATCH 3/6] prevent exceptions when metadata loading failed --- tubesync/sync/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 93f1d7b..b2aeea5 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -866,7 +866,7 @@ class Media(models.Model): # Otherwise, calculate from matched format codes vformat = None aformat = None - if '+' in format_str: + if format_str and '+' in format_str: # Seperate audio and video streams vformat_code, aformat_code = format_str.split('+') vformat = self.get_format_by_code(vformat_code) @@ -875,7 +875,7 @@ class Media(models.Model): # Combined stream or audio only cformat = self.get_format_by_code(format_str) aformat = cformat - if cformat['vcodec']: + if cformat and cformat['vcodec']: # Combined vformat = cformat if vformat: From 7d16a1714c790f8c34da6863038adf645ea91fb6 Mon Sep 17 00:00:00 2001 From: Laurent DEFERT Date: Wed, 28 Dec 2022 21:36:28 +0100 Subject: [PATCH 4/6] add missing migration --- .../migrations/0014_alter_media_media_file.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tubesync/sync/migrations/0014_alter_media_media_file.py diff --git a/tubesync/sync/migrations/0014_alter_media_media_file.py b/tubesync/sync/migrations/0014_alter_media_media_file.py new file mode 100644 index 0000000..530c8e8 --- /dev/null +++ b/tubesync/sync/migrations/0014_alter_media_media_file.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.15 on 2022-12-28 20:33 + +import django.core.files.storage +from django.conf import settings +from django.db import migrations, models +import sync.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sync', '0013_fix_elative_media_file'), + ] + + operations = [ + migrations.AlterField( + model_name='media', + name='media_file', + field=models.FileField(blank=True, help_text='Media file', max_length=255, null=True, storage=django.core.files.storage.FileSystemStorage(base_url='/media-data/', location=str(settings.DOWNLOAD_ROOT)), upload_to=sync.models.get_media_file_path, verbose_name='media file'), + ), + ] From 2f475bf2a894c9aeec48d1648768f5391755cc3f Mon Sep 17 00:00:00 2001 From: Laurent DEFERT Date: Wed, 28 Dec 2022 12:37:32 +0100 Subject: [PATCH 5/6] limit the number of videos to process --- tubesync/sync/models.py | 6 +++++- tubesync/tubesync/settings.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index b2aeea5..71dbed6 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -477,7 +477,11 @@ class Source(models.Model): response = indexer(self.index_url) if not isinstance(response, dict): return [] - return response.get('entries', []) + entries = response.get('entries', []) + + if settings.MAX_ENTRIES_PROCESSING: + entries = entries[:settings.MAX_ENTRIES_PROCESSING] + return entries def get_media_thumb_path(instance, filename): diff --git a/tubesync/tubesync/settings.py b/tubesync/tubesync/settings.py index 11ce66a..39e6b09 100644 --- a/tubesync/tubesync/settings.py +++ b/tubesync/tubesync/settings.py @@ -138,7 +138,7 @@ BACKGROUND_TASK_ASYNC_THREADS = 1 # Number of async tasks to run at on MAX_BACKGROUND_TASK_ASYNC_THREADS = 8 # For sanity reasons BACKGROUND_TASK_PRIORITY_ORDERING = 'ASC' # Use 'niceness' task priority ordering COMPLETED_TASKS_DAYS_TO_KEEP = 7 # Number of days to keep completed tasks - +MAX_ENTRIES_PROCESSING = 0 # Number of videos to process on source refresh (0 for no limit) SOURCES_PER_PAGE = 100 MEDIA_PER_PAGE = 144 From 419c4c5a9fa1f0222a03cd35efcb0335dc23fcdc Mon Sep 17 00:00:00 2001 From: Laurent DEFERT Date: Wed, 28 Dec 2022 20:30:08 +0100 Subject: [PATCH 6/6] source edition refactoring --- tubesync/sync/views.py | 71 +++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/tubesync/sync/views.py b/tubesync/sync/views.py index 62d59f8..b6bf35a 100644 --- a/tubesync/sync/views.py +++ b/tubesync/sync/views.py @@ -269,13 +269,7 @@ class ValidateSourceView(FormView): return append_uri_params(url, fields) -class AddSourceView(CreateView): - ''' - Adds a new source, optionally takes some initial data querystring values to - prepopulate some of the more unclear values. - ''' - - template_name = 'sync/source-add.html' +class EditSourceMixin: model = Source fields = ('source_type', 'key', 'name', 'directory', 'media_format', 'index_schedule', 'download_media', 'download_cap', 'delete_old_media', @@ -287,6 +281,29 @@ class AddSourceView(CreateView): 'this page for valid media name variables'), } + def form_valid(self, form): + # Perform extra validation to make sure the media_format is valid + obj = form.save(commit=False) + source_type = form.cleaned_data['media_format'] + example_media_file = obj.get_example_media_format() + if example_media_file == '': + form.add_error( + 'media_format', + ValidationError(self.errors['invalid_media_format']) + ) + if form.errors: + return super().form_invalid(form) + return super().form_valid(form) + + +class AddSourceView(EditSourceMixin, CreateView): + ''' + Adds a new source, optionally takes some initial data querystring values to + prepopulate some of the more unclear values. + ''' + + template_name = 'sync/source-add.html' + def __init__(self, *args, **kwargs): self.prepopulated_data = {} super().__init__(*args, **kwargs) @@ -312,20 +329,6 @@ class AddSourceView(CreateView): initial[k] = v return initial - def form_valid(self, form): - # Perform extra validation to make sure the media_format is valid - obj = form.save(commit=False) - source_type = form.cleaned_data['media_format'] - example_media_file = obj.get_example_media_format() - if example_media_file == '': - form.add_error( - 'media_format', - ValidationError(self.errors['invalid_media_format']) - ) - if form.errors: - return super().form_invalid(form) - return super().form_valid(form) - def get_success_url(self): url = reverse_lazy('sync:source', kwargs={'pk': self.object.pk}) return append_uri_params(url, {'message': 'source-created'}) @@ -364,33 +367,9 @@ class SourceView(DetailView): return data -class UpdateSourceView(UpdateView): +class UpdateSourceView(EditSourceMixin, UpdateView): template_name = 'sync/source-update.html' - model = Source - fields = ('source_type', 'key', 'name', 'directory', 'media_format', - 'index_schedule', 'download_media', 'download_cap', 'delete_old_media', - 'days_to_keep', 'source_resolution', 'source_vcodec', 'source_acodec', - 'prefer_60fps', 'prefer_hdr', 'fallback', 'copy_thumbnails', 'write_nfo', 'write_json') - errors = { - 'invalid_media_format': _('Invalid media format, the media format contains ' - 'errors or is empty. Check the table at the end of ' - 'this page for valid media name variables'), - } - - def form_valid(self, form): - # Perform extra validation to make sure the media_format is valid - obj = form.save(commit=False) - source_type = form.cleaned_data['media_format'] - example_media_file = obj.get_example_media_format() - if example_media_file == '': - form.add_error( - 'media_format', - ValidationError(self.errors['invalid_media_format']) - ) - if form.errors: - return super().form_invalid(form) - return super().form_valid(form) def get_success_url(self): url = reverse_lazy('sync:source', kwargs={'pk': self.object.pk})