fix ChineseSubFinder
This commit is contained in:
parent
e09cc8127f
commit
80b5f64478
@ -51,14 +51,16 @@ class FileTransferModule(_ModuleBase):
|
|||||||
if isinstance(result, str):
|
if isinstance(result, str):
|
||||||
return TransferInfo(message=result)
|
return TransferInfo(message=result)
|
||||||
# 解包结果
|
# 解包结果
|
||||||
target_path, file_count, file_size, fail_list, msg = result
|
is_bluray, target_path, file_list, file_size, fail_list, msg = result
|
||||||
# 返回
|
# 返回
|
||||||
return TransferInfo(path=path,
|
return TransferInfo(path=path,
|
||||||
target_path=target_path,
|
target_path=target_path,
|
||||||
message=msg,
|
message=msg,
|
||||||
file_count=file_count,
|
file_count=len(file_list),
|
||||||
total_size=file_size,
|
total_size=file_size,
|
||||||
fail_list=fail_list)
|
fail_list=fail_list,
|
||||||
|
is_bluray=is_bluray,
|
||||||
|
file_list=file_list)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __transfer_command(file_item: Path, target_file: Path, rmt_mode) -> int:
|
def __transfer_command(file_item: Path, target_file: Path, rmt_mode) -> int:
|
||||||
@ -333,14 +335,14 @@ class FileTransferModule(_ModuleBase):
|
|||||||
mediainfo: MediaInfo,
|
mediainfo: MediaInfo,
|
||||||
rmt_mode: str = None,
|
rmt_mode: str = None,
|
||||||
target_dir: Path = None
|
target_dir: Path = None
|
||||||
) -> Union[str, Tuple[Path, int, int, List[Path], str]]:
|
) -> Union[str, Tuple[bool, Path, list, int, List[Path], str]]:
|
||||||
"""
|
"""
|
||||||
识别并转移一个文件、多个文件或者目录
|
识别并转移一个文件、多个文件或者目录
|
||||||
:param in_path: 转移的路径,可能是一个文件也可以是一个目录
|
:param in_path: 转移的路径,可能是一个文件也可以是一个目录
|
||||||
:param target_dir: 目的文件夹,非空的转移到该文件夹,为空时则按类型转移到配置文件中的媒体库文件夹
|
:param target_dir: 目的文件夹,非空的转移到该文件夹,为空时则按类型转移到配置文件中的媒体库文件夹
|
||||||
:param rmt_mode: 文件转移方式
|
:param rmt_mode: 文件转移方式
|
||||||
:param mediainfo: 媒体信息
|
:param mediainfo: 媒体信息
|
||||||
:return: 目的路径、处理文件数、总大小、失败文件列表、错误信息
|
:return: 是否蓝光原盘、目的路径、处理文件清单、总大小、失败文件列表、错误信息
|
||||||
"""
|
"""
|
||||||
# 检查目录路径
|
# 检查目录路径
|
||||||
if not in_path.exists():
|
if not in_path.exists():
|
||||||
@ -359,8 +361,8 @@ class FileTransferModule(_ModuleBase):
|
|||||||
# 总大小
|
# 总大小
|
||||||
total_filesize = 0
|
total_filesize = 0
|
||||||
|
|
||||||
# 处理文件数
|
# 处理文件清单
|
||||||
total_num = 0
|
file_list = []
|
||||||
|
|
||||||
# 失败文件清单
|
# 失败文件清单
|
||||||
fail_list = []
|
fail_list = []
|
||||||
@ -387,12 +389,10 @@ class FileTransferModule(_ModuleBase):
|
|||||||
if retcode != 0:
|
if retcode != 0:
|
||||||
return f"{retcode},蓝光原盘转移失败"
|
return f"{retcode},蓝光原盘转移失败"
|
||||||
else:
|
else:
|
||||||
# 计算文件数
|
|
||||||
total_num += 1
|
|
||||||
# 计算大小
|
# 计算大小
|
||||||
total_filesize += in_path.stat().st_size
|
total_filesize += in_path.stat().st_size
|
||||||
# 返回转移后的路径
|
# 返回转移后的路径
|
||||||
return new_path, total_num, total_filesize, [], ""
|
return bluray_flag, new_path, [], total_filesize, [], ""
|
||||||
else:
|
else:
|
||||||
# 获取文件清单
|
# 获取文件清单
|
||||||
transfer_files: List[Path] = SystemUtils.list_files_with_extensions(in_path, settings.RMT_MEDIAEXT)
|
transfer_files: List[Path] = SystemUtils.list_files_with_extensions(in_path, settings.RMT_MEDIAEXT)
|
||||||
@ -455,7 +455,7 @@ class FileTransferModule(_ModuleBase):
|
|||||||
fail_list.append(transfer_file)
|
fail_list.append(transfer_file)
|
||||||
continue
|
continue
|
||||||
# 计算文件数
|
# 计算文件数
|
||||||
total_num += 1
|
file_list.append(str(new_file))
|
||||||
# 计算大小
|
# 计算大小
|
||||||
total_filesize += new_file.stat().st_size
|
total_filesize += new_file.stat().st_size
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@ -463,12 +463,12 @@ class FileTransferModule(_ModuleBase):
|
|||||||
logger.error(f"{transfer_file}转移失败:{err}")
|
logger.error(f"{transfer_file}转移失败:{err}")
|
||||||
fail_list.append(transfer_file)
|
fail_list.append(transfer_file)
|
||||||
|
|
||||||
if total_num == 0:
|
if not file_list:
|
||||||
# 没有成功的
|
# 没有成功的
|
||||||
return "\n".join(err_msgs)
|
return "\n".join(err_msgs)
|
||||||
|
|
||||||
# 新路径、处理文件数、总大小、失败文件列表、错误信息
|
# 蓝光原盘、新路径、处理文件清单、总大小、失败文件列表、错误信息
|
||||||
return new_path, total_num, total_filesize, fail_list, "\n".join(err_msgs)
|
return bluray_flag, new_path, file_list, total_filesize, fail_list, "\n".join(err_msgs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_naming_dict(meta: MetaBase, mediainfo: MediaInfo, file_ext: str = None) -> dict:
|
def __get_naming_dict(meta: MetaBase, mediainfo: MediaInfo, file_ext: str = None) -> dict:
|
||||||
|
@ -3,9 +3,11 @@ from pathlib import Path
|
|||||||
from typing import List, Tuple, Dict, Any
|
from typing import List, Tuple, Dict, Any
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
|
from app.core.context import MediaInfo
|
||||||
from app.core.event import eventmanager
|
from app.core.event import eventmanager
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.plugins import _PluginBase
|
from app.plugins import _PluginBase
|
||||||
|
from app.schemas import TransferInfo
|
||||||
from app.schemas.types import EventType, MediaType
|
from app.schemas.types import EventType, MediaType
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
|
|
||||||
@ -14,7 +16,7 @@ class ChineseSubFinder(_PluginBase):
|
|||||||
# 插件名称
|
# 插件名称
|
||||||
plugin_name = "ChineseSubFinder"
|
plugin_name = "ChineseSubFinder"
|
||||||
# 插件描述
|
# 插件描述
|
||||||
plugin_desc = "通知ChineseSubFinder下载字幕。"
|
plugin_desc = "整理入库时通知ChineseSubFinder下载字幕。"
|
||||||
# 插件图标
|
# 插件图标
|
||||||
plugin_icon = "chinesesubfinder.png"
|
plugin_icon = "chinesesubfinder.png"
|
||||||
# 主题色
|
# 主题色
|
||||||
@ -34,20 +36,16 @@ class ChineseSubFinder(_PluginBase):
|
|||||||
|
|
||||||
# 私有属性
|
# 私有属性
|
||||||
_save_tmp_path = None
|
_save_tmp_path = None
|
||||||
_enable = False
|
_enabled = False
|
||||||
_host = None
|
_host = None
|
||||||
_api_key = None
|
_api_key = None
|
||||||
_remote_path = None
|
_remote_path = None
|
||||||
_local_path = None
|
_local_path = None
|
||||||
_remote_path2 = None
|
|
||||||
_local_path2 = None
|
|
||||||
_remote_path3 = None
|
|
||||||
_local_path3 = None
|
|
||||||
|
|
||||||
def init_plugin(self, config: dict = None):
|
def init_plugin(self, config: dict = None):
|
||||||
self._save_tmp_path = settings.TEMP_PATH
|
self._save_tmp_path = settings.TEMP_PATH
|
||||||
if config:
|
if config:
|
||||||
self._enable = config.get("enable")
|
self._enabled = config.get("enabled")
|
||||||
self._api_key = config.get("api_key")
|
self._api_key = config.get("api_key")
|
||||||
self._host = config.get('host')
|
self._host = config.get('host')
|
||||||
if self._host:
|
if self._host:
|
||||||
@ -57,10 +55,6 @@ class ChineseSubFinder(_PluginBase):
|
|||||||
self._host = self._host + "/"
|
self._host = self._host + "/"
|
||||||
self._local_path = config.get("local_path")
|
self._local_path = config.get("local_path")
|
||||||
self._remote_path = config.get("remote_path")
|
self._remote_path = config.get("remote_path")
|
||||||
self._local_path2 = config.get("local_path2")
|
|
||||||
self._remote_path2 = config.get("remote_path2")
|
|
||||||
self._local_path3 = config.get("local_path3")
|
|
||||||
self._remote_path3 = config.get("remote_path3")
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_command() -> List[Dict[str, Any]]:
|
def get_command() -> List[Dict[str, Any]]:
|
||||||
@ -70,7 +64,114 @@ class ChineseSubFinder(_PluginBase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
|
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
|
||||||
pass
|
return [
|
||||||
|
{
|
||||||
|
'component': 'VForm',
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VRow',
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VCol',
|
||||||
|
'props': {
|
||||||
|
'cols': 12,
|
||||||
|
'md': 6
|
||||||
|
},
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VSwitch',
|
||||||
|
'props': {
|
||||||
|
'model': 'enabled',
|
||||||
|
'label': '启用插件',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'component': 'VRow',
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VCol',
|
||||||
|
'props': {
|
||||||
|
'cols': 12,
|
||||||
|
'md': 6
|
||||||
|
},
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VTextField',
|
||||||
|
'props': {
|
||||||
|
'model': 'host',
|
||||||
|
'label': '服务器'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'component': 'VCol',
|
||||||
|
'props': {
|
||||||
|
'cols': 12,
|
||||||
|
'md': 6
|
||||||
|
},
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VTextField',
|
||||||
|
'props': {
|
||||||
|
'model': 'api_key',
|
||||||
|
'label': 'API密钥'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'component': 'VRow',
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VCol',
|
||||||
|
'props': {
|
||||||
|
'cols': 12,
|
||||||
|
'md': 6
|
||||||
|
},
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VTextField',
|
||||||
|
'props': {
|
||||||
|
'model': 'local_path',
|
||||||
|
'label': '本地路径'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'component': 'VCol',
|
||||||
|
'props': {
|
||||||
|
'cols': 12,
|
||||||
|
'md': 6
|
||||||
|
},
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'component': 'VTextField',
|
||||||
|
'props': {
|
||||||
|
'model': 'remote_path',
|
||||||
|
'label': '远端路径'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], {
|
||||||
|
"enabled": False,
|
||||||
|
"host": "",
|
||||||
|
"api_key": "",
|
||||||
|
"local_path": "",
|
||||||
|
"remote_path": ""
|
||||||
|
}
|
||||||
|
|
||||||
def get_page(self) -> List[dict]:
|
def get_page(self) -> List[dict]:
|
||||||
pass
|
pass
|
||||||
@ -88,38 +189,36 @@ class ChineseSubFinder(_PluginBase):
|
|||||||
item = event.event_data
|
item = event.event_data
|
||||||
if not item:
|
if not item:
|
||||||
return
|
return
|
||||||
# FIXME
|
# 请求地址
|
||||||
req_url = "%sapi/v1/add-job" % self._host
|
req_url = "%sapi/v1/add-job" % self._host
|
||||||
|
|
||||||
item_media = item.get("media_info")
|
# 媒体信息
|
||||||
item_type = item_media.get("type")
|
item_media: MediaInfo = item.get("mediainfo")
|
||||||
item_bluray = item.get("bluray")
|
# 转移信息
|
||||||
item_file = item.get("file")
|
item_transfer: TransferInfo = item.get("transferinfo")
|
||||||
item_file_ext = item.get("file_ext")
|
# 类型
|
||||||
|
item_type = item_media.type
|
||||||
|
# 目的路径
|
||||||
|
item_dest: Path = item_transfer.target_path
|
||||||
|
# 是否蓝光原盘
|
||||||
|
item_bluray = item_transfer.is_bluray
|
||||||
|
# 文件清单
|
||||||
|
item_file_list = item_transfer.file_list
|
||||||
|
|
||||||
if item_bluray:
|
if item_bluray:
|
||||||
file_path = "%s.mp4" % item_file
|
# 蓝光原盘虚拟个文件
|
||||||
else:
|
item_file_list = ["%s.mp4" % item_dest / item_dest.name]
|
||||||
if Path(item_file).suffix != item_file_ext:
|
|
||||||
file_path = "%s%s" % (item_file, item_file_ext)
|
|
||||||
else:
|
|
||||||
file_path = item_file
|
|
||||||
|
|
||||||
# 路径替换
|
for file_path in item_file_list:
|
||||||
if self._local_path and self._remote_path and file_path.startswith(self._local_path):
|
# 路径替换
|
||||||
file_path = file_path.replace(self._local_path, self._remote_path).replace('\\', '/')
|
if self._local_path and self._remote_path and file_path.startswith(self._local_path):
|
||||||
|
file_path = file_path.replace(self._local_path, self._remote_path).replace('\\', '/')
|
||||||
|
|
||||||
if self._local_path2 and self._remote_path2 and file_path.startswith(self._local_path2):
|
# 调用CSF下载字幕
|
||||||
file_path = file_path.replace(self._local_path2, self._remote_path2).replace('\\', '/')
|
self.__request_csf(req_url=req_url,
|
||||||
|
file_path=file_path,
|
||||||
if self._local_path3 and self._remote_path3 and file_path.startswith(self._local_path3):
|
item_type=0 if item_type == MediaType.MOVIE.value else 1,
|
||||||
file_path = file_path.replace(self._local_path3, self._remote_path3).replace('\\', '/')
|
item_bluray=item_bluray)
|
||||||
|
|
||||||
# 调用CSF下载字幕
|
|
||||||
self.__request_csf(req_url=req_url,
|
|
||||||
file_path=file_path,
|
|
||||||
item_type=0 if item_type == MediaType.MOVIE.value else 1,
|
|
||||||
item_bluray=item_bluray)
|
|
||||||
|
|
||||||
@lru_cache(maxsize=128)
|
@lru_cache(maxsize=128)
|
||||||
def __request_csf(self, req_url, file_path, item_type, item_bluray):
|
def __request_csf(self, req_url, file_path, item_type, item_bluray):
|
||||||
|
@ -39,8 +39,12 @@ class TransferInfo(BaseModel):
|
|||||||
path: Optional[Path] = None
|
path: Optional[Path] = None
|
||||||
# 转移后路径
|
# 转移后路径
|
||||||
target_path: Optional[Path] = None
|
target_path: Optional[Path] = None
|
||||||
|
# 是否蓝光原盘
|
||||||
|
is_bluray: Optional[bool] = False
|
||||||
# 处理文件数
|
# 处理文件数
|
||||||
file_count: Optional[int] = 0
|
file_count: Optional[int] = 0
|
||||||
|
# 处理文件清单
|
||||||
|
file_list: Optional[list] = []
|
||||||
# 总文件大小
|
# 总文件大小
|
||||||
total_size: Optional[float] = 0
|
total_size: Optional[float] = 0
|
||||||
# 失败清单
|
# 失败清单
|
||||||
|
Loading…
x
Reference in New Issue
Block a user