Skip to content

Commit

Permalink
Merge pull request #727 from tcely/patch-5
Browse files Browse the repository at this point in the history
Do not turn `Media.skip` off for already skipped media
  • Loading branch information
meeb authored Feb 16, 2025
2 parents 7d55bfd + 785ba9e commit fed8d36
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
34 changes: 27 additions & 7 deletions tubesync/sync/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,61 @@

# Check the filter conditions for instance, return is if the Skip property has changed so we can do other things
def filter_media(instance: Media):
unskip = True
# Assume we aren't skipping it, if any of these conditions are true, we skip it
skip = False

# Check if it's published
if not skip and filter_published(instance):
is_published = not filter_published(instance)
if not skip and not is_published:
skip = True

# Check if older than max_cap_age, skip
if not skip and filter_max_cap(instance):
video_too_old = is_published and filter_max_cap(instance)
if not skip and video_too_old:
skip = True

# Check if older than source_cutoff
if not skip and filter_source_cutoff(instance):
download_kept = not filter_source_cutoff(instance)
if not skip and not download_kept:
skip = True

# Check if we have filter_text and filter text matches
if not skip and filter_filter_text(instance):
skip = True
unskip = False

# Check if the video is longer than the max, or shorter than the min
if not skip and filter_duration(instance):
skip = True
unskip = False

# If we aren't already skipping the file, call our custom function that can be overridden
if not skip and filter_custom(instance):
log.info(f"Media: {instance.source} / {instance} has been skipped by Custom Filter")
skip = True
unskip = False

keep_newly_published_video = (
is_published and download_kept and
not (instance.downloaded or video_too_old)
)

# Check if skipping
if not keep_newly_published_video:
unskip = False
if instance.skip != skip:
was_skipped = instance.skip
instance.skip = skip
log.info(
f"Media: {instance.source} / {instance} has changed skip setting to {skip}"
)
return True

if was_skipped and not (unskip or skip):
instance.skip = True

if instance.skip != was_skipped:
log.info(
f"Media: {instance.source} / {instance} has changed skip setting to {instance.skip}"
)
return True

return False

Expand Down
6 changes: 3 additions & 3 deletions tubesync/sync/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ def media_post_save(sender, instance, created, **kwargs):
)
existing_media_download_task = get_media_download_task(str(instance.pk))
# If the media has not yet been downloaded schedule it to be downloaded
downloaded = instance.downloaded
if not (instance.media_file_exists or existing_media_download_task):
# The file was deleted after it was downloaded, skip this media.
if instance.can_download and instance.downloaded:
skip_changed = True != instance.skip
instance.skip = True
instance.downloaded = False
instance.media_file = None
downloaded = False
if (instance.source.download_media and instance.can_download) and not (
instance.skip or instance.downloaded or existing_media_download_task):
instance.skip or downloaded or existing_media_download_task):
verbose_name = _('Downloading media for "{}"')
download_media(
str(instance.pk),
Expand Down
6 changes: 5 additions & 1 deletion tubesync/sync/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@ def download_media(media_id):
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 and media.media_file.name:
downloaded_file_exists = (
media.media_file_exists or
media.filepath.exists()
)
if media.downloaded and downloaded_file_exists:
# Media has been marked as downloaded before the download_media task was fired,
# skip it
log.warn(f'Download task triggered for media: {media} (UUID: {media.pk}) but '
Expand Down

0 comments on commit fed8d36

Please sign in to comment.