mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-17 10:36:35 +00:00
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:
parent
575a6f0c6c
commit
aa36cace75
@ -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
|
||||
|
27
tubesync/sync/overrides/custom_filter.py
Normal file
27
tubesync/sync/overrides/custom_filter.py
Normal 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
|
Loading…
Reference in New Issue
Block a user