From bceefc8b0125d75454acf04560acf2622ab9a63c Mon Sep 17 00:00:00 2001 From: meeb Date: Sun, 21 Feb 2021 11:15:57 +1100 Subject: [PATCH] skip media which has no publish date in locally stored metadata --- tubesync/sync/tasks.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index 5688fb60..0e0e6070 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -10,7 +10,7 @@ import math import uuid from io import BytesIO from hashlib import sha1 -from datetime import timedelta +from datetime import timedelta, datetime from shutil import copyfile from PIL import Image from django.conf import settings @@ -242,12 +242,17 @@ def download_media_metadata(media_id): media.skip = True # 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: - 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') + if not isinstance(media.published, datetime): + # Media has no known published date or incomplete metadata + log.warn(f'Media: {source} / {media} has no published date, skipping') 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 if not media.skip: if media.get_format_str():