From ca61df2e0bb4d07bc518d8f70dd4521ccdd1fe8c Mon Sep 17 00:00:00 2001 From: Richard Hyde Date: Thu, 19 Dec 2024 18:42:14 +0000 Subject: [PATCH] don't add the sync.tasks.download_media_metadata task if the video is skipped or there's already a task running --- tubesync/sync/signals.py | 4 ++-- tubesync/sync/tasks.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/signals.py b/tubesync/sync/signals.py index 9c541e0a..aba445d0 100644 --- a/tubesync/sync/signals.py +++ b/tubesync/sync/signals.py @@ -12,7 +12,7 @@ from .tasks import (delete_task_by_source, delete_task_by_media, index_source_ta download_media_thumbnail, download_media_metadata, map_task_to_instance, check_source_directory_exists, download_media, rescan_media_server, download_source_images, - save_all_media_for_source) + save_all_media_for_source, get_media_metadata_task) from .utils import delete_file from .filtering import filter_media @@ -133,7 +133,7 @@ def media_post_save(sender, instance, created, **kwargs): instance.save() post_save.connect(media_post_save, sender=Media) # If the media is missing metadata schedule it to be downloaded - if not instance.metadata: + if not instance.metadata and not instance.skip and not get_media_metadata_task(instance.pk): log.info(f'Scheduling task to download metadata for: {instance.url}') verbose_name = _('Downloading metadata for "{}"') download_media_metadata( diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index 767820ea..9f3eea57 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -118,6 +118,12 @@ def get_media_download_task(media_id): except IndexError: return False +def get_media_metadata_task(media_id): + try: + return Task.objects.get_task('sync.tasks.download_media_metadata', + args=(str(media_id),))[0] + except IndexError: + return False def delete_task_by_source(task_name, source_id): return Task.objects.filter(task_name=task_name, queue=str(source_id)).delete()