add a secondary check when download tasks are triggered for download caps, related to #77
This commit is contained in:
		
							parent
							
								
									c32358bcef
								
							
						
					
					
						commit
						38665eb00d
					
				| 
						 | 
					@ -310,20 +310,28 @@ def download_media(media_id):
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    if media.skip:
 | 
					    if media.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 triggeredd media: {media} (UUID: {media.pk}) but it '
 | 
					        log.warn(f'Download task triggered for  media: {media} (UUID: {media.pk}) but '
 | 
				
			||||||
                 f'is now marked to be skipped, not downloading')
 | 
					                 f'it is now marked to be skipped, not downloading')
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    if media.downloaded and media.media_file:
 | 
					    if media.downloaded and media.media_file:
 | 
				
			||||||
        # Media has been marked as downloaded before the download_media task was fired,
 | 
					        # Media has been marked as downloaded before the download_media task was fired,
 | 
				
			||||||
        # skip it
 | 
					        # skip it
 | 
				
			||||||
        log.warn(f'Download task triggeredd media: {media} (UUID: {media.pk}) but it '
 | 
					        log.warn(f'Download task triggered for media: {media} (UUID: {media.pk}) but '
 | 
				
			||||||
                 f'has already been marked as downloaded, not downloading again')
 | 
					                 f'it has already been marked as downloaded, not downloading again')
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    if not media.source.download_media:
 | 
					    if not media.source.download_media:
 | 
				
			||||||
        log.warn(f'Download task triggeredd media: {media} (UUID: {media.pk}) but the '
 | 
					        log.warn(f'Download task triggered for media: {media} (UUID: {media.pk}) but '
 | 
				
			||||||
                 f'source {media.source} has since been marked to not download media, '
 | 
					                 f'the source {media.source} has since been marked to not download, '
 | 
				
			||||||
                 f'not downloading')
 | 
					                 f'not downloading')
 | 
				
			||||||
        return
 | 
					        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
 | 
					    filepath = media.filepath
 | 
				
			||||||
    log.info(f'Downloading media: {media} (UUID: {media.pk}) to: "{filepath}"')
 | 
					    log.info(f'Downloading media: {media} (UUID: {media.pk}) to: "{filepath}"')
 | 
				
			||||||
    format_str, container = media.download_media()
 | 
					    format_str, container = media.download_media()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue