Merge branch 'delete-files-on-disk' of https://github.com/sparklesmcfadden/tubesync into main-delete-files-on-disk
Merge from sparklesmcfadden:delete-files-on-disk
This commit is contained in:
commit
805a0eefbd
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -300,6 +300,11 @@ class Source(models.Model):
|
||||||
default=False,
|
default=False,
|
||||||
help_text=_('Delete media that is no longer on this playlist')
|
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 = models.CharField(
|
||||||
_('source resolution'),
|
_('source resolution'),
|
||||||
max_length=8,
|
max_length=8,
|
||||||
|
|
|
@ -222,6 +222,20 @@ def media_pre_delete(sender, instance, **kwargs):
|
||||||
if thumbnail_url:
|
if thumbnail_url:
|
||||||
delete_task_by_media('sync.tasks.download_media_thumbnail',
|
delete_task_by_media('sync.tasks.download_media_thumbnail',
|
||||||
(str(instance.pk), thumbnail_url))
|
(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)
|
@receiver(post_delete, sender=Media)
|
||||||
|
|
|
@ -122,6 +122,10 @@
|
||||||
<tr title="Delete media that is no longer on this playlist?">
|
<tr title="Delete media that is no longer on this playlist?">
|
||||||
<td class="hide-on-small-only">Delete removed media</td>
|
<td class="hide-on-small-only">Delete removed media</td>
|
||||||
<td><span class="hide-on-med-and-up">Delete removed media<br></span><strong>{% if source.delete_removed_media %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
|
<td><span class="hide-on-med-and-up">Delete removed media<br></span><strong>{% if source.delete_removed_media %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr title="Delete files on disk when they are removed from TubeSync?">
|
||||||
|
<td class="hide-on-small-only">Delete files on disk</td>
|
||||||
|
<td><span class="hide-on-med-and-up">Delete files on disk<br></span><strong>{% if source.delete_files_on_disk %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if source.delete_old_media and source.days_to_keep > 0 %}
|
{% if source.delete_old_media and source.days_to_keep > 0 %}
|
||||||
<tr title="Days after which your media from this source will be locally deleted">
|
<tr title="Days after which your media from this source will be locally deleted">
|
||||||
|
|
|
@ -296,9 +296,9 @@ class EditSourceMixin:
|
||||||
model = Source
|
model = Source
|
||||||
fields = ('source_type', 'key', 'name', 'directory', 'filter_text', 'media_format',
|
fields = ('source_type', 'key', 'name', 'directory', 'filter_text', 'media_format',
|
||||||
'index_schedule', 'download_media', 'download_cap', 'delete_old_media',
|
'index_schedule', 'download_media', 'download_cap', 'delete_old_media',
|
||||||
'delete_removed_media', 'days_to_keep', 'source_resolution', 'source_vcodec',
|
'delete_removed_media', 'delete_files_on_disk', 'days_to_keep', 'source_resolution',
|
||||||
'source_acodec', 'prefer_60fps', 'prefer_hdr', 'fallback', 'copy_thumbnails',
|
'source_vcodec', 'source_acodec', 'prefer_60fps', 'prefer_hdr', 'fallback',
|
||||||
'write_nfo', 'write_json', 'embed_metadata', 'embed_thumbnail',
|
'copy_thumbnails', 'write_nfo', 'write_json', 'embed_metadata', 'embed_thumbnail',
|
||||||
'enable_sponsorblock', 'sponsorblock_categories', 'write_subtitles',
|
'enable_sponsorblock', 'sponsorblock_categories', 'write_subtitles',
|
||||||
'auto_subtitles', 'sub_langs')
|
'auto_subtitles', 'sub_langs')
|
||||||
errors = {
|
errors = {
|
||||||
|
|
Loading…
Reference in New Issue