Merge branch 'meeb:main' into patch-17

This commit is contained in:
tcely 2025-02-12 23:55:04 -05:00 committed by GitHub
commit 11ee871006
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 12 deletions

View File

@ -112,8 +112,8 @@ def append_uri_params(uri, params):
def clean_filename(filename):
if not isinstance(filename, str):
raise ValueError(f'filename must be a str, got {type(filename)}')
to_scrub = '<>\/:*?"|%'
for char in to_scrub:
to_scrub = r'<>\/:*?"|%'
for char in list(to_scrub):
filename = filename.replace(char, '')
clean_filename = ''
for c in filename:

View File

@ -138,7 +138,7 @@ def media_post_save(sender, instance, created, **kwargs):
can_download_changed = False
# Reset the skip flag if the download cap has changed if the media has not
# already been downloaded
if not instance.downloaded and instance.metadata:
if not instance.downloaded:
skip_changed = filter_media(instance)
# Recalculate the "can_download" flag, this may
@ -152,11 +152,6 @@ def media_post_save(sender, instance, created, **kwargs):
if instance.can_download:
instance.can_download = False
can_download_changed = True
# Save the instance if any changes were required
if skip_changed or can_download_changed:
post_save.disconnect(media_post_save, sender=Media)
instance.save()
post_save.connect(media_post_save, sender=Media)
existing_media_metadata_task = get_media_metadata_task(str(instance.pk))
# If the media is missing metadata schedule it to be downloaded
if not (instance.skip or instance.metadata or existing_media_metadata_task):
@ -188,6 +183,10 @@ def media_post_save(sender, instance, created, **kwargs):
existing_media_download_task = get_media_download_task(str(instance.pk))
# If the media has not yet been downloaded schedule it to be downloaded
if not (instance.media_file_exists or existing_media_download_task):
# The file was deleted after it was downloaded, skip this media.
if instance.can_download and instance.downloaded:
skip_changed = True != instance.skip
instance.skip = True
instance.downloaded = False
instance.media_file = None
if (instance.source.download_media and instance.can_download) and not (
@ -200,6 +199,11 @@ def media_post_save(sender, instance, created, **kwargs):
verbose_name=verbose_name.format(instance.name),
remove_existing_tasks=True
)
# Save the instance if any changes were required
if skip_changed or can_download_changed:
post_save.disconnect(media_post_save, sender=Media)
instance.save()
post_save.connect(media_post_save, sender=Media)
@receiver(pre_delete, sender=Media)

View File

@ -268,12 +268,12 @@ class ValidateSourceView(FormView):
class EditSourceMixin:
model = Source
# manual ordering
fields = ('source_type', 'key', 'name', 'directory', 'filter_text', 'filter_text_invert', 'filter_seconds', 'filter_seconds_min',
'media_format', 'index_schedule', 'index_videos', 'index_streams', '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_channel_images',
'delete_removed_media', 'delete_files_on_disk', 'days_to_keep', 'source_resolution',
'source_vcodec', 'source_acodec', 'prefer_60fps', 'prefer_hdr', 'fallback', 'copy_channel_images',
'days_to_keep', 'source_resolution', 'source_vcodec', 'source_acodec',
'prefer_60fps', 'prefer_hdr', 'fallback',
'delete_removed_media', 'delete_files_on_disk', 'copy_channel_images',
'copy_thumbnails', 'write_nfo', 'write_json', 'embed_metadata', 'embed_thumbnail',
'enable_sponsorblock', 'sponsorblock_categories', 'write_subtitles',
'auto_subtitles', 'sub_langs')