add module function alias

This commit is contained in:
jxxghp
2023-06-09 14:36:54 +08:00
parent c89e268b6a
commit dd38428f03
20 changed files with 168 additions and 103 deletions

View File

@ -149,7 +149,7 @@ class _ModuleBase(metaclass=ABCMeta):
"""
pass
def transfer(self, path: str, mediainfo: MediaInfo) -> Optional[str]:
def transfer(self, path: str, mediainfo: MediaInfo) -> Optional[Path]:
"""
转移一个路径下的文件
:param path: 文件路径

View File

@ -26,7 +26,7 @@ class FileTransferModule(_ModuleBase):
def init_setting(self) -> Tuple[str, Union[str, bool]]:
pass
def transfer(self, path: str, mediainfo: MediaInfo) -> Optional[str]:
def transfer(self, path: str, mediainfo: MediaInfo) -> Optional[Path]:
"""
文件转移
:param path: 文件路径
@ -36,14 +36,14 @@ class FileTransferModule(_ModuleBase):
if not settings.LIBRARY_PATH:
logger.error("未设置媒体库目录,无法转移文件")
return None
state, msg = self.transfer_media(in_path=Path(path),
meidainfo=mediainfo,
rmt_mode=settings.TRANSFER_TYPE,
target_dir=Path(settings.LIBRARY_PATH))
if not state:
path, msg = self.transfer_media(in_path=Path(path),
meidainfo=mediainfo,
rmt_mode=settings.TRANSFER_TYPE,
target_dir=Path(settings.LIBRARY_PATH))
if not path:
logger.error(msg)
return state
return path
@staticmethod
def __transfer_command(file_item: Path, target_file: Path, rmt_mode) -> int:
@ -55,8 +55,6 @@ class FileTransferModule(_ModuleBase):
"""
with lock:
# 创建父目录
target_file.parent.mkdir(parents=True, exist_ok=True)
# 转移
if rmt_mode == 'link':
# 硬链接
@ -285,14 +283,16 @@ class FileTransferModule(_ModuleBase):
if over_flag and old_file and old_file.exists():
logger.info(f"正在删除已存在的文件:{old_file}")
old_file.unlink()
logger.info(f"正在转移文件:{file_item.name}{new_file}")
logger.info(f"正在转移文件:{file_item}{new_file}")
# 创建父目录
new_file.parent.mkdir(parents=True, exist_ok=True)
retcode = self.__transfer_command(file_item=file_item,
target_file=new_file,
rmt_mode=rmt_mode)
if retcode == 0:
logger.info(f"文件 {file_item.name} {rmt_mode}完成")
logger.info(f"文件 {file_item} {rmt_mode}完成")
else:
logger.error(f"文件 {file_item.name} {rmt_mode}失败,错误码:{retcode}")
logger.error(f"文件 {file_item} {rmt_mode}失败,错误码:{retcode}")
return retcode
# 处理其他相关文件
return self.__transfer_other_files(org_path=file_item,

View File

@ -5,7 +5,7 @@ from typing import List, Optional, Tuple, Union
from ruamel.yaml import CommentedMap
from app.core import MediaInfo, TorrentInfo, settings
from app.core import MediaInfo, TorrentInfo
from app.log import logger
from app.modules import _ModuleBase
from app.modules.indexer.spider import TorrentSpider

View File

@ -74,7 +74,7 @@ class Telegram(metaclass=Singleton):
else:
chat_id = self._telegram_chat_id
return self.__send_request(chat_id=chat_id, image=image, caption=caption)
return self.__send_request(image=image, caption=caption)
except Exception as msg_e:
logger.error(f"发送消息失败:{msg_e}")
@ -112,7 +112,7 @@ class Telegram(metaclass=Singleton):
else:
chat_id = self._telegram_chat_id
return self.__send_request(chat_id=chat_id, image=image, caption=caption)
return self.__send_request(image=image, caption=caption)
except Exception as msg_e:
logger.error(f"发送消息失败:{msg_e}")
@ -142,13 +142,13 @@ class Telegram(metaclass=Singleton):
else:
chat_id = self._telegram_chat_id
return self.__send_request(chat_id=chat_id, caption=caption)
return self.__send_request(caption=caption)
except Exception as msg_e:
logger.error(f"发送消息失败:{msg_e}")
return False
def __send_request(self, chat_id="", image="", caption="") -> bool:
def __send_request(self, image="", caption="") -> bool:
"""
向Telegram发送报文
"""

View File

@ -97,6 +97,7 @@ class TheMovieDb(_ModuleBase):
else:
# 使用缓存信息
if cache_info.get("title"):
logger.info(f"使用识别缓存:{cache_info.get('title')}")
info = self.tmdb.get_info(mtype=cache_info.get("type"),
tmdbid=cache_info.get("id"))
else: