skip metadata and thumbnails once they are past the cutoff date

This commit is contained in:
George Antoniadis 2022-12-08 01:12:32 +00:00
parent 57921ca6b9
commit fa5bc3ecab
2 changed files with 7 additions and 2 deletions

View File

@ -147,7 +147,7 @@ def media_post_save(sender, instance, created, **kwargs):
instance.save() instance.save()
post_save.connect(media_post_save, sender=Media) post_save.connect(media_post_save, sender=Media)
# If the media is missing metadata schedule it to be downloaded # If the media is missing metadata schedule it to be downloaded
if not instance.metadata: if not instance.metadata and not instance.skip:
log.info(f'Scheduling task to download metadata for: {instance.url}') log.info(f'Scheduling task to download metadata for: {instance.url}')
verbose_name = _('Downloading metadata for "{}"') verbose_name = _('Downloading metadata for "{}"')
download_media_metadata( download_media_metadata(
@ -159,7 +159,7 @@ def media_post_save(sender, instance, created, **kwargs):
# If the media is missing a thumbnail schedule it to be downloaded # If the media is missing a thumbnail schedule it to be downloaded
if not instance.thumb_file_exists: if not instance.thumb_file_exists:
instance.thumb = None instance.thumb = None
if not instance.thumb: if not instance.thumb and not instance.skip:
thumbnail_url = instance.thumbnail thumbnail_url = instance.thumbnail
if thumbnail_url: if thumbnail_url:
log.info(f'Scheduling task to download thumbnail for: {instance.name} ' log.info(f'Scheduling task to download thumbnail for: {instance.name} '

View File

@ -277,6 +277,11 @@ def download_media_thumbnail(media_id, url):
except Media.DoesNotExist: except Media.DoesNotExist:
# Task triggered but the media no longer exists, do nothing # Task triggered but the media no longer exists, do nothing
return return
if media.skip:
# Media was toggled to be skipped after the task was scheduled
log.warn(f'Download task triggered for media: {media} (UUID: {media.pk}) but '
f'it is now marked to be skipped, not downloading thumbnail')
return
width = getattr(settings, 'MEDIA_THUMBNAIL_WIDTH', 430) width = getattr(settings, 'MEDIA_THUMBNAIL_WIDTH', 430)
height = getattr(settings, 'MEDIA_THUMBNAIL_HEIGHT', 240) height = getattr(settings, 'MEDIA_THUMBNAIL_HEIGHT', 240)
i = get_remote_image(url) i = get_remote_image(url)