Unify filtering for metadata to use same filtering for downloading

This commit is contained in:
Tim 2024-07-11 16:20:58 +08:00
parent ea8223d86b
commit 96ba4d25ed
2 changed files with 4 additions and 30 deletions

View File

@ -39,7 +39,7 @@ def filter_media(instance: Media):
def filter_published(instance: Media):
# Check if the instance is not published, we have to skip then
if not instance.published:
if not isinstance(instance.published, datetime):
log.warn(f'Media: {instance.source} / {instance} has no published date '
f'set, marking to be skipped')
return True

View File

@ -27,6 +27,7 @@ from common.utils import json_serial
from .models import Source, Media, MediaServer
from .utils import (get_remote_image, resize_image_to_height, delete_file,
write_text_file)
from .filtering import filter_media
def get_hash(task_name, pk):
@ -292,35 +293,8 @@ def download_media_metadata(media_id):
# Media must have a valid upload date
if upload_date:
media.published = timezone.make_aware(upload_date)
else:
log.error(f'Media has no upload date, skipping: {source} / {media}')
media.skip = True
# If the source has a download cap date check the upload date is allowed
max_cap_age = source.download_cap_date
if media.published and max_cap_age:
if media.published < max_cap_age:
# Media was published after the cap date, skip it
log.warn(f'Media: {source} / {media} is older than cap age '
f'{max_cap_age}, skipping')
media.skip = True
# If the source has a search filter, check the video title matches the filter
if source.filter_text and not source.is_regex_match(media.title):
# Filter text not found in the media title. Accepts regex string, blank search filter results in this returning false
log.warn(f'Media: {source} / {media} does not match {source.filter_text}, skipping')
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:
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
filter_media(media)
# Check we can download the media item
if not media.skip:
if media.get_format_str():