diff --git a/README.md b/README.md index a8c245c1..5b800ec1 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ docker pull jxxghp/moviepilot:latest - **QB_HOST:** qbittorrent地址,格式:`ip:port`,https需要添加`https://`前缀 - **QB_USER:** qbittorrent用户名 - **QB_PASSWORD:** qbittorrent密码 + - **QB_CATEGORY:** qbittorrent分类自动管理,`true`/`false`,默认`flase`,开启后会将下载二级分类传递到下载器,由下载器管理下载目录,需要同步开启`DOWNLOAD_CATEGORY` - `transmission`设置项: diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 7338ac33..acb90996 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -235,7 +235,7 @@ class ChainBase(metaclass=ABCMeta): torrent_list=torrent_list, season_episodes=season_episodes) def download(self, torrent_path: Path, download_dir: Path, cookie: str, - episodes: Set[int] = None, + episodes: Set[int] = None, category: str = None ) -> Optional[Tuple[Optional[str], str]]: """ 根据种子文件,选择并添加下载任务 @@ -243,10 +243,11 @@ class ChainBase(metaclass=ABCMeta): :param download_dir: 下载目录 :param cookie: cookie :param episodes: 需要下载的集数 + :param category: 种子分类 :return: 种子Hash,错误信息 """ return self.run_module("download", torrent_path=torrent_path, download_dir=download_dir, - cookie=cookie, episodes=episodes, ) + cookie=cookie, episodes=episodes, category=category) def download_added(self, context: Context, torrent_path: Path, download_dir: Path) -> None: """ diff --git a/app/chain/download.py b/app/chain/download.py index a44554f9..2f19d5c9 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -151,7 +151,8 @@ class DownloadChain(ChainBase): result: Optional[tuple] = self.download(torrent_path=torrent_file, cookie=_torrent.site_cookie, episodes=episodes, - download_dir=download_dir) + download_dir=download_dir, + category=_media.category) if result: _hash, error_msg = result else: diff --git a/app/core/config.py b/app/core/config.py index e803f42b..debf69c0 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -109,6 +109,8 @@ class Settings(BaseSettings): QB_USER: str = None # Qbittorrent密码 QB_PASSWORD: str = None + # Qbittorrent分类自动管理 + QB_CATEGORY: bool = False # Transmission地址,IP:PORT TR_HOST: str = None # Transmission用户名 diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index f2035e78..96d2d64e 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -37,13 +37,14 @@ class QbittorrentModule(_ModuleBase): self.qbittorrent = Qbittorrent() def download(self, torrent_path: Path, download_dir: Path, cookie: str, - episodes: Set[int] = None) -> Optional[Tuple[Optional[str], str]]: + episodes: Set[int] = None, category: str = None) -> Optional[Tuple[Optional[str], str]]: """ 根据种子文件,选择并添加下载任务 :param torrent_path: 种子文件地址 :param download_dir: 下载目录 :param cookie: cookie :param episodes: 需要下载的集数 + :param category: 分类 :return: 种子Hash,错误信息 """ if not torrent_path or not torrent_path.exists(): @@ -61,7 +62,8 @@ class QbittorrentModule(_ModuleBase): download_dir=str(download_dir), is_paused=is_paused, tag=tags, - cookie=cookie) + cookie=cookie, + category=category) if not state: return None, f"添加种子任务失败:{torrent_path}" else: diff --git a/app/modules/qbittorrent/qbittorrent.py b/app/modules/qbittorrent/qbittorrent.py index 8f512037..98279abb 100644 --- a/app/modules/qbittorrent/qbittorrent.py +++ b/app/modules/qbittorrent/qbittorrent.py @@ -177,6 +177,7 @@ class Qbittorrent(metaclass=Singleton): is_paused: bool = False, download_dir: str = None, tag: Union[str, list] = None, + category: str = None, cookie=None ) -> bool: """ @@ -184,6 +185,7 @@ class Qbittorrent(metaclass=Singleton): :param content: 种子urls或文件内容 :param is_paused: 添加后暂停 :param tag: 标签 + :param category: 种子分类 :param download_dir: 下载路径 :param cookie: 站点Cookie用于辅助下载种子 :return: bool @@ -191,6 +193,7 @@ class Qbittorrent(metaclass=Singleton): if not self.qbc or not content: return False + # 下载内容 if isinstance(content, str): urls = content torrent_files = None @@ -198,20 +201,26 @@ class Qbittorrent(metaclass=Singleton): urls = None torrent_files = content + # 保存目录 if download_dir: save_path = download_dir - is_auto = False else: save_path = None - is_auto = None + # 标签 if tag: tags = tag else: tags = None - try: + # 分类自动管理 + if category and settings.QB_CATEGORY: + is_auto = True + else: + is_auto = False + category = None + try: # 添加下载 qbc_ret = self.qbc.torrents_add(urls=urls, torrent_files=torrent_files, @@ -220,7 +229,8 @@ class Qbittorrent(metaclass=Singleton): tags=tags, use_auto_torrent_management=is_auto, is_sequential_download=True, - cookie=cookie) + cookie=cookie, + category=category) return True if qbc_ret and str(qbc_ret).find("Ok") != -1 else False except Exception as err: logger.error(f"添加种子出错:{err}") diff --git a/app/modules/transmission/__init__.py b/app/modules/transmission/__init__.py index 9a738a2b..2d6f7ad1 100644 --- a/app/modules/transmission/__init__.py +++ b/app/modules/transmission/__init__.py @@ -37,13 +37,14 @@ class TransmissionModule(_ModuleBase): self.transmission = Transmission() def download(self, torrent_path: Path, download_dir: Path, cookie: str, - episodes: Set[int] = None) -> Optional[Tuple[Optional[str], str]]: + episodes: Set[int] = None, category: str = None) -> Optional[Tuple[Optional[str], str]]: """ 根据种子文件,选择并添加下载任务 :param torrent_path: 种子文件地址 :param download_dir: 下载目录 :param cookie: cookie :param episodes: 需要下载的集数 + :param category: 分类,TR中未使用 :return: 种子Hash """ # 如果要选择文件则先暂停