feat 下载目录二级分类

This commit is contained in:
jxxghp
2023-07-21 07:25:29 +08:00
parent 9de57dd17b
commit 3be445b409
8 changed files with 38 additions and 19 deletions

View File

@ -24,11 +24,12 @@ class QbittorrentModule(_ModuleBase):
def init_setting(self) -> Tuple[str, Union[str, bool]]:
return "DOWNLOADER", "qbittorrent"
def download(self, torrent_path: Path, cookie: str,
def download(self, torrent_path: Path, download_dir: Path, cookie: str,
episodes: Set[int] = None) -> Optional[Tuple[Optional[str], str]]:
"""
根据种子文件,选择并添加下载任务
:param torrent_path: 种子文件地址
:param download_dir: 下载目录
:param cookie: cookie
:param episodes: 需要下载的集数
:return: 种子Hash错误信息
@ -45,7 +46,7 @@ class QbittorrentModule(_ModuleBase):
is_paused = True if episodes else False
# 添加任务
state = self.qbittorrent.add_torrent(content=torrent_path.read_bytes(),
download_dir=settings.DOWNLOAD_PATH,
download_dir=str(download_dir),
is_paused=is_paused,
tag=tags,
cookie=cookie)

View File

@ -34,11 +34,12 @@ class SubtitleModule(_ModuleBase):
def stop(self) -> None:
pass
def download_added(self, context: Context, torrent_path: Path) -> None:
def download_added(self, context: Context, torrent_path: Path, download_dir: Path) -> None:
"""
添加下载任务成功后,从站点下载字幕,保存到下载目录
:param context: 上下文,包括识别信息、媒体信息、种子信息
:param torrent_path: 种子文件地址
:param download_dir: 下载目录
:return: None该方法可被多个模块同时处理
"""
# 种子信息
@ -49,7 +50,8 @@ class SubtitleModule(_ModuleBase):
logger.info("开始从站点下载字幕:%s" % torrent.page_url)
# 获取种子信息
folder_name, _ = TorrentHelper.get_torrent_info(torrent_path)
download_dir = Path(settings.DOWNLOAD_PATH) / folder_name
download_dir = download_dir / (folder_name or "")
# 等待文件或者目录存在
for _ in range(10):
if download_dir.exists():

View File

@ -24,11 +24,12 @@ class TransmissionModule(_ModuleBase):
def init_setting(self) -> Tuple[str, Union[str, bool]]:
return "DOWNLOADER", "transmission"
def download(self, torrent_path: Path, cookie: str,
def download(self, torrent_path: Path, download_dir: Path, cookie: str,
episodes: Set[int] = None) -> Optional[Tuple[Optional[str], str]]:
"""
根据种子文件,选择并添加下载任务
:param torrent_path: 种子文件地址
:param download_dir: 下载目录
:param cookie: cookie
:param episodes: 需要下载的集数
:return: 种子Hash
@ -42,7 +43,7 @@ class TransmissionModule(_ModuleBase):
labels = None
# 添加任务
torrent = self.transmission.add_torrent(content=torrent_path.read_bytes(),
download_dir=settings.DOWNLOAD_PATH,
download_dir=str(download_dir),
is_paused=is_paused,
labels=labels,
cookie=cookie)