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 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 b92390e..3d60424 100644 --- a/tubesync/sync/signals.py +++ b/tubesync/sync/signals.py @@ -222,6 +222,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 c5812b2..12b083e 100644 --- a/tubesync/sync/templates/sync/source.html +++ b/tubesync/sync/templates/sync/source.html @@ -122,6 +122,10 @@