This commit is contained in:
tcely 2025-06-16 21:36:59 +00:00 committed by GitHub
commit 0a536c9f22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 13 deletions

View File

@ -103,12 +103,12 @@ def copy_thumbnail(self):
if not self.source.copy_thumbnails: if not self.source.copy_thumbnails:
return return
if not self.thumb_file_exists: if not self.thumb_file_exists:
from sync.tasks import delete_task_by_media, download_media_thumbnail from sync.tasks import delete_task_by_media, download_media_image
args = ( str(self.pk), self.thumbnail, ) args = ( str(self.pk), self.thumbnail, )
if not args[1]: if not args[1]:
return return
delete_task_by_media('sync.tasks.download_media_thumbnail', args) delete_task_by_media('sync.tasks.download_media_thumbnail', args)
if download_media_thumbnail.now(*args): if download_media_image.call_local(*args):
self.refresh_from_db() self.refresh_from_db()
if not self.thumb_file_exists: if not self.thumb_file_exists:
return return

View File

@ -497,17 +497,15 @@ def index_source_task(source_id):
log.info(f'Indexed new media: {source} / {media}') log.info(f'Indexed new media: {source} / {media}')
log.info(f'Scheduling tasks to download thumbnail for: {media.key}') log.info(f'Scheduling tasks to download thumbnail for: {media.key}')
thumbnail_fmt = 'https://i.ytimg.com/vi/{}/{}default.jpg' thumbnail_fmt = 'https://i.ytimg.com/vi/{}/{}default.jpg'
vn_fmt = _('Downloading {} thumbnail for: "{}": {}') for num, prefix in enumerate(reversed(('hq', 'sd', 'maxres',))):
for num, prefix in enumerate(('hq', 'sd', 'maxres',)):
thumbnail_url = thumbnail_fmt.format( thumbnail_url = thumbnail_fmt.format(
media.key, media.key,
prefix, prefix,
) )
download_media_thumbnail( download_media_image.schedule(
str(media.pk), (str(media.pk), thumbnail_url,),
thumbnail_url, priority=10+(5*num),
schedule=dict(run_at=10+(300*num)), delay=65-(30*num),
verbose_name=vn_fmt.format(prefix, media.key, media.name),
) )
log.info(f'Scheduling task to download metadata for: {media.url}') log.info(f'Scheduling task to download metadata for: {media.url}')
verbose_name = _('Downloading metadata for: "{}": {}') verbose_name = _('Downloading metadata for: "{}": {}')
@ -702,8 +700,8 @@ def download_media_metadata(media_id):
f'{source} / {media}: {media_id}') f'{source} / {media}: {media_id}')
@background(schedule=dict(priority=10, run_at=10), queue=Val(TaskQueue.FS), remove_existing_tasks=True) @dynamic_retry(db_task, delay=10, priority=90, retries=15, queue=Val(TaskQueue.NET))
def download_media_thumbnail(media_id, url): def download_media_image(media_id, url):
''' '''
Downloads an image from a URL and save it as a local thumbnail attached to a Downloads an image from a URL and save it as a local thumbnail attached to a
Media instance. Media instance.
@ -712,7 +710,7 @@ def download_media_thumbnail(media_id, url):
media = Media.objects.get(pk=media_id) media = Media.objects.get(pk=media_id)
except Media.DoesNotExist as e: except Media.DoesNotExist as e:
# Task triggered but the media no longer exists, do nothing # Task triggered but the media no longer exists, do nothing
raise InvalidTaskError(_('no such media')) from e raise CancelExecution(_('no such media'), retry=False) from e
if media.skip or media.manual_skip: if media.skip or media.manual_skip:
# Media was toggled to be skipped after the task was scheduled # Media was toggled to be skipped after the task was scheduled
log.warn(f'Download task triggered for media: {media} (UUID: {media.pk}) but ' log.warn(f'Download task triggered for media: {media} (UUID: {media.pk}) but '
@ -728,7 +726,7 @@ def download_media_thumbnail(media_id, url):
raise raise
raise NoThumbnailException(re.response.reason) from re raise NoThumbnailException(re.response.reason) from re
except NoThumbnailException as e: except NoThumbnailException as e:
raise InvalidTaskError(str(e.__cause__)) from e raise CancelExecution(str(e.__cause__), retry=False) from e
if (i.width > width) and (i.height > height): if (i.width > width) and (i.height > height):
log.info(f'Resizing {i.width}x{i.height} thumbnail to ' log.info(f'Resizing {i.width}x{i.height} thumbnail to '
f'{width}x{height}: {url}') f'{width}x{height}: {url}')
@ -759,6 +757,12 @@ def download_media_thumbnail(media_id, url):
copyfile(media.thumb.path, media.thumbpath) copyfile(media.thumb.path, media.thumbpath)
return True return True
@background(schedule=dict(priority=10, run_at=10), queue=Val(TaskQueue.FS), remove_existing_tasks=True)
def download_media_thumbnail(media_id, url):
try:
return download_media_image.call_local(media_id, url)
except CancelExecution as e:
raise InvalidTaskError(str(e)) from e
@background(schedule=dict(priority=30, run_at=60), queue=Val(TaskQueue.NET), remove_existing_tasks=True) @background(schedule=dict(priority=30, run_at=60), queue=Val(TaskQueue.NET), remove_existing_tasks=True)
def download_media(media_id, override=False): def download_media(media_id, override=False):