mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-17 07:21:28 +00:00
Add Jellyfin tag context and routing helpers
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import math
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
@@ -248,3 +249,48 @@ def primary_media_source(item: dict[str, Any]) -> dict[str, Any]:
|
||||
if isinstance(source, dict):
|
||||
return source
|
||||
return {}
|
||||
|
||||
|
||||
def tags_to_json(tags: list[str]) -> str:
|
||||
return json.dumps(tags, ensure_ascii=False, separators=(",", ":"))
|
||||
|
||||
|
||||
def tags_from_json(value: str | None) -> list[str]:
|
||||
if not value:
|
||||
return []
|
||||
try:
|
||||
parsed = json.loads(value)
|
||||
except (TypeError, json.JSONDecodeError):
|
||||
return []
|
||||
if not isinstance(parsed, list):
|
||||
return []
|
||||
return [str(tag).strip() for tag in parsed if str(tag).strip()]
|
||||
|
||||
|
||||
def route_override_from_tags(
|
||||
tags: list[str],
|
||||
*,
|
||||
force_specialist_tag: str,
|
||||
force_general_tag: str,
|
||||
specialist_tags: tuple[str, ...],
|
||||
) -> tuple[str, str] | None:
|
||||
normalized = {tag.casefold() for tag in tags}
|
||||
if force_specialist_tag and force_specialist_tag.casefold() in normalized:
|
||||
return ("specialist", "jellyfin-force-tag")
|
||||
if force_general_tag and force_general_tag.casefold() in normalized:
|
||||
return ("general", "jellyfin-force-tag")
|
||||
if normalized.intersection(tag.casefold() for tag in specialist_tags):
|
||||
return ("specialist", "jellyfin-specialist-tag")
|
||||
return None
|
||||
|
||||
|
||||
def caption_context_from_tags(
|
||||
tags: list[str],
|
||||
*,
|
||||
control_tags: tuple[str, ...] = (),
|
||||
) -> str | None:
|
||||
controls = {tag.casefold() for tag in control_tags if tag}
|
||||
visible_tags = [tag for tag in tags if tag.casefold() not in controls]
|
||||
if not visible_tags:
|
||||
return None
|
||||
return "Jellyfin tags: " + ", ".join(visible_tags)
|
||||
|
||||
Reference in New Issue
Block a user