From ed07073cf431b7de57c289873867ea0cda9bdad0 Mon Sep 17 00:00:00 2001 From: administrator <7dn1yh5j@debauchez.fr> Date: Mon, 11 Dec 2023 03:38:37 +0100 Subject: [PATCH] Revert "Removed non-pertinent source option" This reverts commit 46ba2593a2d7d756676d6e57e0924326ee1bb74e. Restore option --- .../migrations/0021_add_delete_files_on_disk.py | 17 +++++++++++++++++ tubesync/sync/models.py | 5 +++++ tubesync/sync/signals.py | 2 +- tubesync/sync/views.py | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tubesync/sync/migrations/0021_add_delete_files_on_disk.py diff --git a/tubesync/sync/migrations/0021_add_delete_files_on_disk.py b/tubesync/sync/migrations/0021_add_delete_files_on_disk.py new file mode 100644 index 0000000..5745d47 --- /dev/null +++ b/tubesync/sync/migrations/0021_add_delete_files_on_disk.py @@ -0,0 +1,17 @@ +# Generated by pac + +from django.db import migrations, models + +class Migration(migrations.Migration): + + dependencies = [ + ('sync', '0020_auto_20231024_1825'), + ] + + operations = [ + migrations.AddField( + model_name='source', + name='delete_files_on_disk', + field=models.BooleanField(default=False, help_text='Delete files on disk when they are removed from TubeSync', verbose_name='delete files on disk'), + ), + ] \ No newline at end of file diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index dff8063..a63c57e 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -300,6 +300,11 @@ class Source(models.Model): default=False, help_text=_('Delete media that is no longer on this playlist') ) + delete_files_on_disk = models.BooleanField( + _('delete files on disk'), + default=False, + help_text=_('Delete files on disk when they are removed from TubeSync') + ) source_resolution = models.CharField( _('source resolution'), max_length=8, diff --git a/tubesync/sync/signals.py b/tubesync/sync/signals.py index 6600b71..b9f8835 100644 --- a/tubesync/sync/signals.py +++ b/tubesync/sync/signals.py @@ -224,7 +224,7 @@ def media_pre_delete(sender, instance, **kwargs): if thumbnail_url: delete_task_by_media('sync.tasks.download_media_thumbnail', (str(instance.pk), thumbnail_url)) - if instance.media_file or instance.thumb: + if instance.source.delete_files_on_disk and (instance.media_file or instance.thumb): # Delete all media files if it contains filename filepath = instance.media_file.path if instance.media_file else instance.thumb.path barefilepath, fileext = os.path.splitext(filepath) diff --git a/tubesync/sync/views.py b/tubesync/sync/views.py index ba319c0..ac65d5c 100644 --- a/tubesync/sync/views.py +++ b/tubesync/sync/views.py @@ -298,7 +298,7 @@ class EditSourceMixin: model = Source fields = ('source_type', 'key', 'name', 'directory', 'filter_text', 'media_format', 'index_schedule', 'download_media', 'download_cap', 'delete_old_media', - 'delete_removed_media', 'days_to_keep', 'source_resolution', + 'delete_removed_media', 'delete_files_on_disk', 'days_to_keep', 'source_resolution', 'source_vcodec', 'source_acodec', 'prefer_60fps', 'prefer_hdr', 'fallback', 'copy_thumbnails', 'write_nfo', 'write_json', 'embed_metadata', 'embed_thumbnail', 'enable_sponsorblock', 'sponsorblock_categories', 'write_subtitles',