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 @@