diff --git a/tubesync/sync/migrations/0020_add_delete_files_on_disk.py b/tubesync/sync/migrations/0020_add_delete_files_on_disk.py new file mode 100644 index 0000000..4d33148 --- /dev/null +++ b/tubesync/sync/migrations/0020_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', '0019_add_delete_removed_media'), + ] + + 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 bb8c723..05ca6fc 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -292,6 +292,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 f27b452..0c7a7a3 100644 --- a/tubesync/sync/signals.py +++ b/tubesync/sync/signals.py @@ -203,6 +203,20 @@ 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.source.delete_files_on_disk: + if instance.thumb: + log.info(f'Deleting thumbnail for: {instance} path: {instance.thumb.path}') + delete_file(instance.thumb.path) + # Delete the media file if it exists + if instance.media_file: + filepath = instance.media_file.path + log.info(f'Deleting media for: {instance} path: {filepath}') + delete_file(filepath) + # Delete thumbnail copy if it exists + barefilepath, fileext = os.path.splitext(filepath) + thumbpath = f'{barefilepath}.jpg' + log.info(f'Deleting thumbnail for: {instance} path: {thumbpath}') + delete_file(thumbpath) @receiver(post_delete, sender=Media) diff --git a/tubesync/sync/templates/sync/source.html b/tubesync/sync/templates/sync/source.html index 22122e2..c2a2cd4 100644 --- a/tubesync/sync/templates/sync/source.html +++ b/tubesync/sync/templates/sync/source.html @@ -118,6 +118,10 @@ Delete removed media Delete removed media
{% if source.delete_removed_media %}{% else %}{% endif %} + + + Delete files on disk + Delete files on disk
{% if source.delete_files_on_disk %}{% else %}{% endif %} {% if source.delete_old_media and source.days_to_keep > 0 %} diff --git a/tubesync/sync/views.py b/tubesync/sync/views.py index e187cd8..f747a37 100644 --- a/tubesync/sync/views.py +++ b/tubesync/sync/views.py @@ -296,9 +296,9 @@ class EditSourceMixin: model = Source fields = ('source_type', 'key', 'name', 'directory', 'media_format', 'index_schedule', 'download_media', 'download_cap', 'delete_old_media', - 'delete_removed_media', 'days_to_keep', 'source_resolution', 'source_vcodec', - 'source_acodec', 'prefer_60fps', 'prefer_hdr', 'fallback', 'copy_thumbnails', - 'write_nfo', 'write_json', 'embed_metadata', 'embed_thumbnail', + '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', 'auto_subtitles', 'sub_langs') errors = {