From 691b7d84ad908c1161310ba9b1a8bc2dba98c919 Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Thu, 12 Nov 2026 15:57:48 -0400 Subject: [PATCH] fix(jellyfin): use dedicated routes for additional library types --- app/modules/jellyfin/jellyfin.py | 13 +++++++++++ tests/test_jellyfin.py | 38 ++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/modules/jellyfin/jellyfin.py b/app/modules/jellyfin/jellyfin.py index 5a0f41509..0946a7782 100644 --- a/app/modules/jellyfin/jellyfin.py +++ b/app/modules/jellyfin/jellyfin.py @@ -248,6 +248,19 @@ class Jellyfin: elif library.get("CollectionType") in ("music", "musicvideos"): library_type = MediaType.MUSIC.value link = f"{self._playhost or self._host}web/index.html#!/music.html?topParentId={library.get('Id')}" + elif library.get("CollectionType") in ("boxsets", "books", "playlists"): + library_type = MediaType.UNKNOWN.value + collection_type = library.get("CollectionType") + link = ( + f"{self._playhost or self._host}web/index.html#!/{collection_type}" + f"?topParentId={library.get('Id')}&collectionType={collection_type}" + ) + elif library.get("CollectionType") in ("homevideos", "livetv"): + library_type = MediaType.UNKNOWN.value + link = ( + f"{self._playhost or self._host}web/index.html#!/{library.get('CollectionType')}" + f"?topParentId={library.get('Id')}" + ) elif library.get("CollectionType") is None and library.get("Type") == "CollectionFolder": # 混合内容库:Jellyfin 前端没有 library 路由,自身对该类库使用 mixed 路由。 library_type = MediaType.UNKNOWN.value diff --git a/tests/test_jellyfin.py b/tests/test_jellyfin.py index 8016d4e23..7f30b7d4c 100644 --- a/tests/test_jellyfin.py +++ b/tests/test_jellyfin.py @@ -3,8 +3,11 @@ """ import sys +from typing import Optional from unittest.mock import patch +import pytest + from app.modules.jellyfin import jellyfin as jellyfin_module from app.modules.jellyfin.jellyfin import Jellyfin from app.schemas.mediaserver import MediaServerField, MediaServerQueryOptions @@ -249,13 +252,13 @@ def test_get_librarys_other_unknown_types_keep_library_route() -> None: 非混合的其他未知类型库不改走 mixed 路由,保持原有链接。 Jellyfin 只对 CollectionType 为空且类型为 CollectionFolder 的库使用 mixed 路由; - 书籍等有专属路由的类型不在本次修复范围,仍走原有分支。 + 未识别的类型仍保留原有兜底行为。 """ client = _build_client() libraries = _get_librarys_with_mocked_views( client, [ - {"Id": "b1", "Name": "书籍", "CollectionType": "books", "Type": "CollectionFolder"}, + {"Id": "b1", "Name": "未知", "CollectionType": "unsupported", "Type": "CollectionFolder"}, {"Id": "u1", "Name": "视图", "CollectionType": None, "Type": "UserView"}, ], ) @@ -264,3 +267,34 @@ def test_get_librarys_other_unknown_types_keep_library_route() -> None: "http://jellyfin.local:8096/web/index.html#!/library.html?topParentId=b1", "http://jellyfin.local:8096/web/index.html#!/library.html?topParentId=u1", ] + + +@pytest.mark.parametrize("play_host", [None, "https://play.example/jellyfin/"]) +@pytest.mark.parametrize( + "collection_type,query_suffix", + [ + ("boxsets", "&collectionType=boxsets"), + ("books", "&collectionType=books"), + ("homevideos", ""), + ("playlists", "&collectionType=playlists"), + ("livetv", ""), + ], +) +def test_get_librarys_uses_dedicated_routes( + play_host: Optional[str], collection_type: str, query_suffix: str, +) -> None: + """ + 特殊类型库使用对应前端路由,并优先使用外网播放地址。 + """ + client = _build_client() + client._playhost = play_host + libraries = _get_librarys_with_mocked_views( + client, + [{"Id": "library-id", "Name": "媒体库", "CollectionType": collection_type}], + ) + + host = play_host or "http://jellyfin.local:8096/" + assert libraries[0].link == ( + f"{host}web/index.html#!/{collection_type}?topParentId=library-id{query_suffix}" + ) + assert libraries[0].type == MediaType.UNKNOWN.value