mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-05-12 03:29:41 +08:00
fix 全局变量定义
This commit is contained in:
@@ -22,7 +22,7 @@ class EmbyModule(_ModuleBase, _MediaServerBase):
|
||||
return
|
||||
for server in mediaservers:
|
||||
if server.type == "emby" and server.enabled:
|
||||
self._servers[server.name] = Emby(**server.config)
|
||||
self._servers[server.name] = Emby(**server.config, sync_libraries=server.sync_libraries)
|
||||
|
||||
@staticmethod
|
||||
def get_name() -> str:
|
||||
|
||||
@@ -18,9 +18,11 @@ class Emby:
|
||||
_host: str = None
|
||||
_playhost: str = None
|
||||
_apikey: str = None
|
||||
_sync_libraries: List[str] = []
|
||||
user: Optional[Union[str, int]] = None
|
||||
|
||||
def __init__(self, host: str = None, apikey: str = None, play_host: str = None, **kwargs):
|
||||
def __init__(self, host: str = None, apikey: str = None, play_host: str = None,
|
||||
sync_libraries: list = None, **kwargs):
|
||||
if not host or not apikey:
|
||||
logger.error("Emby服务器配置不完整!")
|
||||
return
|
||||
@@ -34,6 +36,7 @@ class Emby:
|
||||
self.user = self.get_user(settings.SUPERUSER)
|
||||
self.folders = self.get_emby_folders()
|
||||
self.serverid = self.get_server_id()
|
||||
self._sync_libraries = sync_libraries or []
|
||||
|
||||
def is_inactive(self) -> bool:
|
||||
"""
|
||||
@@ -132,9 +135,8 @@ class Emby:
|
||||
if not self._host or not self._apikey:
|
||||
return []
|
||||
libraries = []
|
||||
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||
for library in self.__get_emby_librarys(username) or []:
|
||||
if library.get("Name") in black_list:
|
||||
if self._sync_libraries and library.get("Id") not in self._sync_libraries:
|
||||
continue
|
||||
match library.get("CollectionType"):
|
||||
case "movies":
|
||||
@@ -1137,9 +1139,8 @@ class Emby:
|
||||
if not self._host or not self._apikey:
|
||||
return []
|
||||
library_folders = []
|
||||
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||
for library in self.get_emby_virtual_folders() or []:
|
||||
if library.get("Name") in black_list:
|
||||
if self._sync_libraries and library.get("Id") not in self._sync_libraries:
|
||||
continue
|
||||
library_folders += [folder for folder in library.get("Path")]
|
||||
return library_folders
|
||||
|
||||
@@ -22,7 +22,7 @@ class JellyfinModule(_ModuleBase, _MediaServerBase):
|
||||
return
|
||||
for server in mediaservers:
|
||||
if server.type == "jellyfin" and server.enabled:
|
||||
self._servers[server.name] = Jellyfin(**server.config)
|
||||
self._servers[server.name] = Jellyfin(**server.config, sync_libraries=server.sync_libraries)
|
||||
|
||||
@staticmethod
|
||||
def get_name() -> str:
|
||||
|
||||
@@ -15,9 +15,11 @@ class Jellyfin:
|
||||
_host: str = None
|
||||
_apikey: str = None
|
||||
_playhost: str = None
|
||||
_sync_libraries: List[str] = []
|
||||
user: Optional[Union[str, int]] = None
|
||||
|
||||
def __init__(self, host: str = None, apikey: str = None, play_host: str = None, **kwargs):
|
||||
def __init__(self, host: str = None, apikey: str = None, play_host: str = None,
|
||||
sync_libraries: list = None, **kwargs):
|
||||
if not host or not apikey:
|
||||
logger.error("Jellyfin服务器配置不完整!!")
|
||||
return
|
||||
@@ -30,6 +32,7 @@ class Jellyfin:
|
||||
self._apikey = apikey
|
||||
self.user = self.get_user(settings.SUPERUSER)
|
||||
self.serverid = self.get_server_id()
|
||||
self._sync_libraries = sync_libraries or []
|
||||
|
||||
def is_inactive(self) -> bool:
|
||||
"""
|
||||
@@ -128,9 +131,8 @@ class Jellyfin:
|
||||
if not self._host or not self._apikey:
|
||||
return []
|
||||
libraries = []
|
||||
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||
for library in self.__get_jellyfin_librarys(username) or []:
|
||||
if library.get("Name") in black_list:
|
||||
if self._sync_libraries and library.get("Id") not in self._sync_libraries:
|
||||
continue
|
||||
match library.get("CollectionType"):
|
||||
case "movies":
|
||||
@@ -871,9 +873,8 @@ class Jellyfin:
|
||||
if not self._host or not self._apikey:
|
||||
return []
|
||||
library_folders = []
|
||||
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||
for library in self.get_jellyfin_virtual_folders() or []:
|
||||
if library.get("Name") in black_list:
|
||||
if self._sync_libraries and library.get("Id") not in self._sync_libraries:
|
||||
continue
|
||||
library_folders += [folder for folder in library.get("Path")]
|
||||
return library_folders
|
||||
|
||||
@@ -22,7 +22,7 @@ class PlexModule(_ModuleBase, _MediaServerBase):
|
||||
return
|
||||
for server in mediaservers:
|
||||
if server.type == "plex" and server.enabled:
|
||||
self._servers[server.name] = Plex(**server.config)
|
||||
self._servers[server.name] = Plex(**server.config, sync_libraries=server.sync_libraries)
|
||||
|
||||
@staticmethod
|
||||
def get_name() -> str:
|
||||
|
||||
@@ -19,8 +19,10 @@ from app.utils.url import UrlUtils
|
||||
class Plex:
|
||||
_plex = None
|
||||
_session = None
|
||||
_sync_libraries: List[str] = []
|
||||
|
||||
def __init__(self, host: str = None, token: str = None, play_host: str = None, **kwargs):
|
||||
def __init__(self, host: str = None, token: str = None, play_host: str = None,
|
||||
sync_libraries: list = None, **kwargs):
|
||||
if not host or not token:
|
||||
logger.error("Plex服务器配置不完整!")
|
||||
return
|
||||
@@ -39,6 +41,7 @@ class Plex:
|
||||
self._plex = None
|
||||
logger.error(f"Plex服务器连接失败:{str(e)}")
|
||||
self._session = self.__adapt_plex_session()
|
||||
self._sync_libraries = sync_libraries or []
|
||||
|
||||
def is_inactive(self) -> bool:
|
||||
"""
|
||||
@@ -109,9 +112,8 @@ class Plex:
|
||||
logger.error(f"获取媒体服务器所有媒体库列表出错:{str(err)}")
|
||||
return []
|
||||
libraries = []
|
||||
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||
for library in self._libraries:
|
||||
if library.title in black_list:
|
||||
if self._sync_libraries and library.key not in self._sync_libraries:
|
||||
continue
|
||||
match library.type:
|
||||
case "movie":
|
||||
@@ -287,18 +289,18 @@ class Plex:
|
||||
return None
|
||||
# 如果配置了外网播放地址以及Token,则默认从Plex媒体服务器获取图片,否则返回有外网地址的图片资源
|
||||
if self._playhost and self._token:
|
||||
query = {"X-Plex-Token": settings.PLEX_TOKEN}
|
||||
query = {"X-Plex-Token": self._token}
|
||||
if image_type == "Poster":
|
||||
if item.thumb:
|
||||
image_url = RequestUtils.combine_url(host=settings.PLEX_PLAY_HOST, path=item.thumb, query=query)
|
||||
image_url = RequestUtils.combine_url(host=self._playhost, path=item.thumb, query=query)
|
||||
else:
|
||||
# 默认使用art也就是Backdrop进行处理
|
||||
if item.art:
|
||||
image_url = RequestUtils.combine_url(host=settings.PLEX_PLAY_HOST, path=item.art, query=query)
|
||||
image_url = RequestUtils.combine_url(host=self._playhost, path=item.art, query=query)
|
||||
# 这里对episode进行特殊处理,实际上episode的Backdrop是Poster
|
||||
# 也有个别情况,比如机智的凡人小子episode就是Poster,因此这里把episode的优先级降低,默认还是取art
|
||||
if not image_url and item.TYPE == "episode" and item.thumb:
|
||||
image_url = RequestUtils.combine_url(host=settings.PLEX_PLAY_HOST, path=item.thumb, query=query)
|
||||
image_url = RequestUtils.combine_url(host=self._playhost, path=item.thumb, query=query)
|
||||
else:
|
||||
if image_type == "Poster":
|
||||
images = self._plex.fetchItems(ekey=f"{ekey}/posters",
|
||||
@@ -811,23 +813,21 @@ class Plex:
|
||||
logger.error(f"连接Plex出错:" + str(e))
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def __get_request_headers() -> dict:
|
||||
def __get_request_headers(self) -> dict:
|
||||
"""获取请求头"""
|
||||
return {
|
||||
"X-Plex-Token": settings.PLEX_TOKEN,
|
||||
"X-Plex-Token": self._token,
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def __adapt_plex_session() -> Session:
|
||||
def __adapt_plex_session(self) -> Session:
|
||||
"""
|
||||
创建并配置一个针对Plex服务的requests.Session实例
|
||||
这个会话包括特定的头部信息,用于处理所有的Plex请求
|
||||
"""
|
||||
# 设置请求头部,通常包括验证令牌和接受/内容类型头部
|
||||
headers = Plex.__get_request_headers()
|
||||
headers = self.__get_request_headers()
|
||||
session = Session()
|
||||
session.headers = headers
|
||||
return session
|
||||
|
||||
@@ -275,7 +275,8 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase):
|
||||
if not server:
|
||||
return None
|
||||
server.set_torrents_tag(ids=hashs, tags=['已整理'])
|
||||
# 移动模式删除种子
|
||||
# FIXME 移动模式删除种子
|
||||
"""
|
||||
if settings.TRANSFER_TYPE in ["move"]:
|
||||
if self.remove_torrents(hashs):
|
||||
logger.info(f"移动模式删除种子成功:{hashs} ")
|
||||
@@ -285,6 +286,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase):
|
||||
if not files:
|
||||
logger.warn(f"删除残留文件夹:{path}")
|
||||
shutil.rmtree(path, ignore_errors=True)
|
||||
"""
|
||||
|
||||
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True,
|
||||
downloader: str = None) -> Optional[bool]:
|
||||
|
||||
@@ -270,7 +270,8 @@ class TransmissionModule(_ModuleBase, _DownloaderBase):
|
||||
else:
|
||||
tags = ['已整理']
|
||||
server.set_torrent_tag(ids=hashs, tags=tags)
|
||||
# 移动模式删除种子
|
||||
# FIXME 移动模式删除种子
|
||||
"""
|
||||
if settings.TRANSFER_TYPE in ["move"]:
|
||||
if self.remove_torrents(hashs):
|
||||
logger.info(f"移动模式删除种子成功:{hashs} ")
|
||||
@@ -280,6 +281,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase):
|
||||
if not files:
|
||||
logger.warn(f"删除残留文件夹:{path}")
|
||||
shutil.rmtree(path, ignore_errors=True)
|
||||
"""
|
||||
|
||||
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True,
|
||||
downloader: str = None) -> Optional[bool]:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import xml.dom.minidom
|
||||
from typing import Optional, Union, List, Tuple, Any, Dict
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.context import Context, MediaInfo
|
||||
from app.helper.notification import NotificationHelper
|
||||
from app.log import logger
|
||||
@@ -66,6 +65,9 @@ class WechatModule(_ModuleBase, _MessageBase):
|
||||
client: WeChat = self.get_client(source)
|
||||
if not client:
|
||||
return None
|
||||
client_config = self.get_config(source)
|
||||
if not client_config:
|
||||
return None
|
||||
# URL参数
|
||||
sVerifyMsgSig = args.get("msg_signature")
|
||||
sVerifyTimeStamp = args.get("timestamp")
|
||||
@@ -74,9 +76,9 @@ class WechatModule(_ModuleBase, _MessageBase):
|
||||
logger.debug(f"微信请求参数错误:{args}")
|
||||
return None
|
||||
# 解密模块
|
||||
wxcpt = WXBizMsgCrypt(sToken=settings.WECHAT_TOKEN,
|
||||
sEncodingAESKey=settings.WECHAT_ENCODING_AESKEY,
|
||||
sReceiveId=settings.WECHAT_CORPID)
|
||||
wxcpt = WXBizMsgCrypt(sToken=client_config.config.get('WECHAT_TOKEN'),
|
||||
sEncodingAESKey=client_config.config.get('WECHAT_ENCODING_AESKEY'),
|
||||
sReceiveId=client_config.config.get('WECHAT_CORPID'))
|
||||
# 报文数据
|
||||
if not body:
|
||||
logger.debug(f"微信请求数据为空")
|
||||
@@ -126,8 +128,8 @@ class WechatModule(_ModuleBase, _MessageBase):
|
||||
# 解析消息内容
|
||||
if msg_type == "event" and event == "click":
|
||||
# 校验用户有权限执行交互命令
|
||||
if settings.WECHAT_ADMINS:
|
||||
wechat_admins = settings.WECHAT_ADMINS.split(',')
|
||||
if client_config.config.get('WECHAT_ADMINS'):
|
||||
wechat_admins = client_config.config.get('WECHAT_ADMINS').split(',')
|
||||
if wechat_admins and not any(
|
||||
user_id == admin_user for admin_user in wechat_admins):
|
||||
client.send_msg(title="用户无权限执行菜单命令", userid=user_id)
|
||||
|
||||
Reference in New Issue
Block a user