Fix #509. Allow semi easy override of filtering logic with custom python code so it can be extended by end users

This commit is contained in:
Tim 2024-07-13 15:48:16 +08:00
parent 575a6f0c6c
commit aa36cace75
2 changed files with 32 additions and 0 deletions

View File

@ -6,6 +6,7 @@ from common.logger import log
from .models import Media
from datetime import datetime, timedelta
from django.utils import timezone
from .overrides.custom_filter import filter_custom
# Check the filter conditions for instance, return is if the Skip property has changed so we can do other things
@ -33,6 +34,10 @@ def filter_media(instance: Media):
if filter_duration(instance):
skip = True
# If we aren't already skipping the file, call our custom function that can be overridden
if not skip and filter_custom(instance):
skip = True
# Check if skipping
if instance.skip != skip:
instance.skip = skip

View File

@ -0,0 +1,27 @@
"""
This file can be overridden with a docker volume to allow specifying a custom filter function to call. This allows
for higher order filtering for those that really want advanced controls, without exposing the web interface to
potential RCE issues.
You are simply provided with an instance of Media, and need to return True to skip it, or False to allow it to be
downloaded.
To use this custom file, download this file and modify the function to do your check for skipping a media item.
Then use docker volumes to override /app/sync/overrides/ with your custom file (it must be called
`custom_filter.py`)
e.g. your `docker run` could have `-v /some/directory/tubesync-overrides:/app/sync/overrides`
or docker-compose could have
volumes:
- /some/directory/tubesync-overrides:/app/sync/overrides
The logic is that if any condition marks an item to be skipped, it will be skipped. To save resources, this
custom filter won't be called if any other filter as already marked it to be skipped
"""
from ..models import Media
def filter_custom(instance: Media) -> bool:
# Return True to skip, or False to allow the media item to be downloaded
return False