fix #516 支持磁力链下载
This commit is contained in:
@@ -36,19 +36,22 @@ class QbittorrentModule(_ModuleBase):
|
||||
if self.qbittorrent.is_inactive():
|
||||
self.qbittorrent = Qbittorrent()
|
||||
|
||||
def download(self, torrent_path: Path, download_dir: Path, cookie: str,
|
||||
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
||||
episodes: Set[int] = None, category: str = None) -> Optional[Tuple[Optional[str], str]]:
|
||||
"""
|
||||
根据种子文件,选择并添加下载任务
|
||||
:param torrent_path: 种子文件地址
|
||||
:param content: 种子文件地址或者磁力链接
|
||||
:param download_dir: 下载目录
|
||||
:param cookie: cookie
|
||||
:param episodes: 需要下载的集数
|
||||
:param category: 分类
|
||||
:return: 种子Hash,错误信息
|
||||
"""
|
||||
if not torrent_path or not torrent_path.exists():
|
||||
return None, f"种子文件不存在:{torrent_path}"
|
||||
if not content:
|
||||
return
|
||||
if isinstance(content, Path) and not content.exists():
|
||||
return None, f"种子文件不存在:{content}"
|
||||
|
||||
# 生成随机Tag
|
||||
tag = StringUtils.generate_random_str(10)
|
||||
if settings.TORRENT_TAG:
|
||||
@@ -58,19 +61,21 @@ class QbittorrentModule(_ModuleBase):
|
||||
# 如果要选择文件则先暂停
|
||||
is_paused = True if episodes else False
|
||||
# 添加任务
|
||||
state = self.qbittorrent.add_torrent(content=torrent_path.read_bytes(),
|
||||
download_dir=str(download_dir),
|
||||
is_paused=is_paused,
|
||||
tag=tags,
|
||||
cookie=cookie,
|
||||
category=category)
|
||||
state = self.qbittorrent.add_torrent(
|
||||
content=content.read_bytes() if isinstance(content, Path) else content,
|
||||
download_dir=str(download_dir),
|
||||
is_paused=is_paused,
|
||||
tag=tags,
|
||||
cookie=cookie,
|
||||
category=category
|
||||
)
|
||||
if not state:
|
||||
return None, f"添加种子任务失败:{torrent_path}"
|
||||
return None, f"添加种子任务失败:{content}"
|
||||
else:
|
||||
# 获取种子Hash
|
||||
torrent_hash = self.qbittorrent.get_torrent_id_by_tag(tags=tag)
|
||||
if not torrent_hash:
|
||||
return None, f"获取种子Hash失败:{torrent_path}"
|
||||
return None, f"获取种子Hash失败:{content}"
|
||||
else:
|
||||
if is_paused:
|
||||
# 种子文件
|
||||
|
@@ -34,18 +34,22 @@ class SubtitleModule(_ModuleBase):
|
||||
def stop(self) -> None:
|
||||
pass
|
||||
|
||||
def download_added(self, context: Context, torrent_path: Path, download_dir: Path) -> None:
|
||||
def download_added(self, context: Context, download_dir: Path, torrent_path: Path = None) -> None:
|
||||
"""
|
||||
添加下载任务成功后,从站点下载字幕,保存到下载目录
|
||||
:param context: 上下文,包括识别信息、媒体信息、种子信息
|
||||
:param torrent_path: 种子文件地址
|
||||
:param download_dir: 下载目录
|
||||
:param torrent_path: 种子文件地址
|
||||
:return: None,该方法可被多个模块同时处理
|
||||
"""
|
||||
if not settings.DOWNLOAD_SUBTITLE:
|
||||
return None
|
||||
|
||||
# 种子信息
|
||||
# 没有种子文件不处理
|
||||
if not torrent_path:
|
||||
return
|
||||
|
||||
# 没有详情页不处理
|
||||
torrent = context.torrent_info
|
||||
if not torrent.page_url:
|
||||
return
|
||||
|
@@ -36,17 +36,22 @@ class TransmissionModule(_ModuleBase):
|
||||
if not self.transmission.is_inactive():
|
||||
self.transmission = Transmission()
|
||||
|
||||
def download(self, torrent_path: Path, download_dir: Path, cookie: str,
|
||||
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
||||
episodes: Set[int] = None, category: str = None) -> Optional[Tuple[Optional[str], str]]:
|
||||
"""
|
||||
根据种子文件,选择并添加下载任务
|
||||
:param torrent_path: 种子文件地址
|
||||
:param content: 种子文件地址或者磁力链接
|
||||
:param download_dir: 下载目录
|
||||
:param cookie: cookie
|
||||
:param episodes: 需要下载的集数
|
||||
:param category: 分类,TR中未使用
|
||||
:return: 种子Hash
|
||||
"""
|
||||
if not content:
|
||||
return
|
||||
if isinstance(content, Path) and not content.exists():
|
||||
return None, f"种子文件不存在:{content}"
|
||||
|
||||
# 如果要选择文件则先暂停
|
||||
is_paused = True if episodes else False
|
||||
# 标签
|
||||
@@ -55,13 +60,15 @@ class TransmissionModule(_ModuleBase):
|
||||
else:
|
||||
labels = None
|
||||
# 添加任务
|
||||
torrent = self.transmission.add_torrent(content=torrent_path.read_bytes(),
|
||||
download_dir=str(download_dir),
|
||||
is_paused=is_paused,
|
||||
labels=labels,
|
||||
cookie=cookie)
|
||||
torrent = self.transmission.add_torrent(
|
||||
content=content.read_bytes() if isinstance(content, Path) else content,
|
||||
download_dir=str(download_dir),
|
||||
is_paused=is_paused,
|
||||
labels=labels,
|
||||
cookie=cookie
|
||||
)
|
||||
if not torrent:
|
||||
return None, f"添加种子任务失败:{torrent_path}"
|
||||
return None, f"添加种子任务失败:{content}"
|
||||
else:
|
||||
torrent_hash = torrent.hashString
|
||||
if is_paused:
|
||||
|
Reference in New Issue
Block a user