From: Christian Heller Date: Wed, 11 Dec 2024 06:28:10 +0000 (+0100) Subject: Add option for tags whitelist prefilter, i.e. tags of which to show files even if... X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/task?a=commitdiff_plain;p=ytplom Add option for tags whitelist prefilter, i.e. tags of which to show files even if not matching needed-tags prefilter. --- diff --git a/src/ytplom/http.py b/src/ytplom/http.py index 1f0b703..cc7a908 100644 --- a/src/ytplom/http.py +++ b/src/ytplom/http.py @@ -94,7 +94,8 @@ class Server(ThreadingHTTPServer): *args, **kwargs) self.config = config self.jinja = JinjaEnv(loader=JinjaFSLoader(_PATH_TEMPLATES)) - self.player = Player(config.needed_tags_prefilter) + self.player = Player(config.needed_tags_prefilter, + config.whitelist_tags_prefilter) self.downloads = DownloadsManager() self.downloads.clean_unfinished() self.downloads.start_thread() @@ -323,12 +324,15 @@ class _TaskHandler(BaseHTTPRequestHandler): def _send_files_index(self, params: _ReqMap) -> None: filter_path = FilterStr(params.first_for('filter_path')) needed_tags_str = params.first_for('needed_tags') - needed_tags = (self.server.config.needed_tags_prefilter - | Tag.from_joined(needed_tags_str)) show_absent = bool(params.first_for('show_absent')) with DbConn() as conn: files = VideoFile.get_filtered( - conn, filter_path, needed_tags, show_absent) + conn, + filter_path, + self.server.config.needed_tags_prefilter, + Tag.from_joined(needed_tags_str), + self.server.config.whitelist_tags_prefilter, + show_absent) files.sort(key=lambda t: t.rel_path) self._send_rendered_template(_NAME_TEMPLATE_FILES, {'files': files, diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index 5451924..86a1c1f 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -29,6 +29,7 @@ DEFAULTS = { 'port_remote': 8090, 'background_color': '#ffffff', 'queries_cutoff': '', + 'whitelist_tags_prefilter_str': '', 'needed_tags_prefilter_str': '', 'allow_file_edit': True } @@ -92,6 +93,7 @@ class Config: background_color: str queries_cutoff: str needed_tags_prefilter_str: str + whitelist_tags_prefilter_str: str allow_file_edit: bool def __init__(self): @@ -108,6 +110,8 @@ class Config: if k.isupper() and k.startswith(ENVIRON_PREFIX)}) self.needed_tags_prefilter = Tag.from_joined( self.needed_tags_prefilter_str) + self.whitelist_tags_prefilter = Tag.from_joined( + self.whitelist_tags_prefilter_str) class YoutubeQuery(DbData): @@ -328,14 +332,18 @@ class VideoFile(DbData): def get_filtered(cls, conn: BaseDbConn, filter_path: FilterStr, - needed_tags: set[Tag], + needed_tags_dark: set[Tag], + needed_tags_seen: set[Tag], + whitelist_tags: set[Tag], show_absent: bool = False ) -> list[Self]: """Return cls.get_all matching provided filter criteria.""" return [f for f in cls.get_all(conn) if (show_absent or f.present) and str(filter_path).lower() in str(f.rel_path).lower() - and not [t for t in needed_tags if t not in f.tags]] + and ([t for t in whitelist_tags if t in f.tags] + or not [t for t in needed_tags_dark if t not in f.tags]) + and not [t for t in needed_tags_seen if t not in f.tags]] def unused_tags(self, conn: BaseDbConn) -> set[Tag]: """Return tags used among other VideoFiles, not in self.""" @@ -430,12 +438,16 @@ class Player: """MPV representation with some additional features.""" _idx: int - def __init__(self, needed_tags_prefilter: set[Tag]) -> None: + def __init__(self, + whitelist_tags_prefilter: set[Tag], + needed_tags_prefilter: set[Tag], + ) -> None: self.last_update = DatetimeStr('') self._mpv: Optional[MPV] = None self._kill_queue: Queue = Queue() self._monitoring_kill = False self.filter_path = FilterStr('') + self._whitelist_tags_prefilter = whitelist_tags_prefilter self._needed_tags_prefilter = needed_tags_prefilter self.needed_tags: set[Tag] = set() self.load_files_and_start() @@ -466,8 +478,11 @@ class Player: known_files = { f.full_path: f for f in VideoFile.get_filtered( - conn, self.filter_path, - self._needed_tags_prefilter | self.needed_tags)} + conn, + self.filter_path, + self._needed_tags_prefilter, + self.needed_tags, + self._whitelist_tags_prefilter)} self.files = [known_files[p] for p in PATH_DOWNLOADS.iterdir() if p in known_files and p.is_file()