From 38665eb00d6ce03a0eeb8598caf9338646502c0a Mon Sep 17 00:00:00 2001 From: meeb Date: Mon, 8 Mar 2021 12:20:44 +1100 Subject: [PATCH] add a secondary check when download tasks are triggered for download caps, related to #77 --- tubesync/sync/tasks.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index 0e0e607..2597649 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -310,20 +310,28 @@ def download_media(media_id): return if media.skip: # Media was toggled to be skipped after the task was scheduled - log.warn(f'Download task triggeredd media: {media} (UUID: {media.pk}) but it ' - f'is now marked to be skipped, not downloading') + log.warn(f'Download task triggered for media: {media} (UUID: {media.pk}) but ' + f'it is now marked to be skipped, not downloading') return if media.downloaded and media.media_file: # Media has been marked as downloaded before the download_media task was fired, # skip it - log.warn(f'Download task triggeredd media: {media} (UUID: {media.pk}) but it ' - f'has already been marked as downloaded, not downloading again') + log.warn(f'Download task triggered for media: {media} (UUID: {media.pk}) but ' + f'it has already been marked as downloaded, not downloading again') return if not media.source.download_media: - log.warn(f'Download task triggeredd media: {media} (UUID: {media.pk}) but the ' - f'source {media.source} has since been marked to not download media, ' + log.warn(f'Download task triggered for media: {media} (UUID: {media.pk}) but ' + f'the source {media.source} has since been marked to not download, ' f'not downloading') return + max_cap_age = media.source.download_cap_date + published = instance.published + if max_cap_age and published: + if published <= max_cap_age: + log.warn(f'Download task triggered media: {media} (UUID: {media.pk}) but ' + f'the source has a download cap and the media is now too old, ' + f'not downloading') + return filepath = media.filepath log.info(f'Downloading media: {media} (UUID: {media.pk}) to: "{filepath}"') format_str, container = media.download_media()