This commit is contained in:
@@ -76,23 +76,28 @@ def build_channel_path_list(path_entries: list) -> tuple[list[Path], list[dict]]
|
||||
return [p for p, _ in pairs], [c for _, c in pairs]
|
||||
|
||||
|
||||
def _path_to_stream_path(p: Path) -> str:
|
||||
"""Convert absolute path to stream path (for stream?path=)."""
|
||||
try:
|
||||
if MOVIES_ROOT in p.parents:
|
||||
rel = p.relative_to(MOVIES_ROOT)
|
||||
return "movies/" + str(rel).replace("\\", "/")
|
||||
rel = p.relative_to(SERIES_ROOT)
|
||||
return "series/" + str(rel).replace("\\", "/")
|
||||
except ValueError:
|
||||
return "movies/" + p.name
|
||||
|
||||
|
||||
def build_playlist(path_entries: list, base_url: str) -> list[tuple[str, str]]:
|
||||
"""Build playlist as list of (display_name, stream_url)."""
|
||||
data = build_playlist_data(path_entries)
|
||||
return [(name, f"{base_url}/stream?path={path_str}") for name, path_str in data]
|
||||
|
||||
|
||||
def build_playlist_data(path_entries: list) -> list[tuple[str, str]]:
|
||||
"""Build playlist data as list of (display_name, path_str) for caching."""
|
||||
paths, _ = build_channel_path_list(path_entries)
|
||||
playlist = []
|
||||
for p in paths:
|
||||
try:
|
||||
if MOVIES_ROOT in p.parents:
|
||||
rel = p.relative_to(MOVIES_ROOT)
|
||||
path_str = "movies/" + str(rel).replace("\\", "/")
|
||||
else:
|
||||
rel = p.relative_to(SERIES_ROOT)
|
||||
path_str = "series/" + str(rel).replace("\\", "/")
|
||||
except ValueError:
|
||||
path_str = "movies/" + p.name
|
||||
stream_url = f"{base_url}/stream?path={path_str}"
|
||||
playlist.append((p.stem, stream_url))
|
||||
return playlist
|
||||
return [(p.stem, _path_to_stream_path(p)) for p in paths]
|
||||
|
||||
|
||||
def get_duration(path: Path) -> float:
|
||||
@@ -128,6 +133,11 @@ class ScheduleBuilder:
|
||||
self._ttl_sec = SCHEDULE_CACHE_TTL_SEC
|
||||
self._channel_repo = None # injected
|
||||
|
||||
def invalidate_cache(self) -> None:
|
||||
"""Clear in-memory schedule cache (e.g. when channels.json changes)."""
|
||||
self._cache.clear()
|
||||
logger.debug("Schedule cache invalidated")
|
||||
|
||||
def set_channel_repo(self, repo) -> None:
|
||||
"""Set the channel repository for schedule building."""
|
||||
self._channel_repo = repo
|
||||
|
||||
Reference in New Issue
Block a user