skip media which has no publish date in locally stored metadata

This commit is contained in:
meeb 2021-02-21 11:15:57 +11:00
parent 820cc69937
commit bceefc8b01
1 changed files with 11 additions and 6 deletions

View File

@ -10,7 +10,7 @@ import math
import uuid import uuid
from io import BytesIO from io import BytesIO
from hashlib import sha1 from hashlib import sha1
from datetime import timedelta from datetime import timedelta, datetime
from shutil import copyfile from shutil import copyfile
from PIL import Image from PIL import Image
from django.conf import settings from django.conf import settings
@ -242,12 +242,17 @@ def download_media_metadata(media_id):
media.skip = True media.skip = True
# If the source has a cut-off check the upload date is within the allowed delta # If the source has a cut-off check the upload date is within the allowed delta
if source.delete_old_media and source.days_to_keep > 0: if source.delete_old_media and source.days_to_keep > 0:
delta = timezone.now() - timedelta(days=source.days_to_keep) if not isinstance(media.published, datetime):
if media.published < delta: # Media has no known published date or incomplete metadata
# Media was published after the cutoff date, skip it log.warn(f'Media: {source} / {media} has no published date, skipping')
log.warn(f'Media: {source} / {media} is older than '
f'{source.days_to_keep} days, skipping')
media.skip = True media.skip = True
else:
delta = timezone.now() - timedelta(days=source.days_to_keep)
if media.published < delta:
# Media was published after the cutoff date, skip it
log.warn(f'Media: {source} / {media} is older than '
f'{source.days_to_keep} days, skipping')
media.skip = True
# Check we can download the media item # Check we can download the media item
if not media.skip: if not media.skip:
if media.get_format_str(): if media.get_format_str():