mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-30 08:50:17 +08:00
refactor(module): simplify service instantiation with generics
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
from typing import Optional, Tuple, Union, Any, List, Generator, Dict
|
||||
from typing import Optional, Tuple, Union, Any, List, Generator
|
||||
|
||||
from app import schemas
|
||||
from app.core.context import MediaInfo
|
||||
from app.helper.mediaserver import MediaServerHelper
|
||||
from app.log import logger
|
||||
from app.modules import _ModuleBase, _MediaServerBase
|
||||
from app.modules.emby.emby import Emby
|
||||
@@ -10,22 +9,14 @@ from app.schemas import MediaServerConf
|
||||
from app.schemas.types import MediaType
|
||||
|
||||
|
||||
class EmbyModule(_ModuleBase, _MediaServerBase):
|
||||
class EmbyModule(_ModuleBase, _MediaServerBase[Emby]):
|
||||
|
||||
def init_module(self) -> None:
|
||||
"""
|
||||
初始化模块
|
||||
"""
|
||||
# 读取媒体服务器配置
|
||||
self._instances: Dict[str, Emby] = {}
|
||||
self._configs: Dict[str, MediaServerConf] = {}
|
||||
mediaservers = MediaServerHelper().get_mediaservers()
|
||||
if not mediaservers:
|
||||
return
|
||||
for server in mediaservers:
|
||||
if server.type == "emby" and server.enabled:
|
||||
self._configs[server.name] = server
|
||||
self._instances[server.name] = Emby(**server.config, sync_libraries=server.sync_libraries)
|
||||
super().init_service(service_name=Emby.__name__.lower(),
|
||||
service_type=lambda conf: Emby(**conf.config, sync_libraries=conf.sync_libraries))
|
||||
|
||||
@staticmethod
|
||||
def get_name() -> str:
|
||||
@@ -182,7 +173,8 @@ class EmbyModule(_ModuleBase, _MediaServerBase):
|
||||
return server.get_librarys(username=username, hidden=hidden)
|
||||
return None
|
||||
|
||||
def mediaserver_items(self, server: str, library_id: str, start_index: int = 0, limit: int = 100) -> Optional[Generator]:
|
||||
def mediaserver_items(self, server: str, library_id: str, start_index: int = 0, limit: int = 100) \
|
||||
-> Optional[Generator]:
|
||||
"""
|
||||
媒体库项目列表
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user