From a06279927a263beee1dc3a7b0660a0b15ec0e21e Mon Sep 17 00:00:00 2001 From: miRemid Date: Mon, 13 Nov 2023 15:54:35 +0800 Subject: [PATCH 1/2] feat: support qbittorrent to use category as download path Signed-off-by: miRemid --- .config/download_provider.yaml | 1 + .../qbittorrent_download_provider/README.md | 2 ++ .../qbittorrent_download_provider/provider.py | 12 ++++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.config/download_provider.yaml b/.config/download_provider.yaml index b290af1a..fc658f57 100644 --- a/.config/download_provider.yaml +++ b/.config/download_provider.yaml @@ -31,6 +31,7 @@ qbittorrent: username: admin password: adminadmin verify_webui_certificate: false + use_auto_torrent_management: false priority: 3 tags: - kubespider diff --git a/docs/zh/user_guide/qbittorrent_download_provider/README.md b/docs/zh/user_guide/qbittorrent_download_provider/README.md index 7fdd5dca..9bc528b0 100644 --- a/docs/zh/user_guide/qbittorrent_download_provider/README.md +++ b/docs/zh/user_guide/qbittorrent_download_provider/README.md @@ -79,6 +79,7 @@ qbittorrent: tags: - kubespider category: kubespider + use_auto_torrent_management: false ``` 其中: @@ -95,6 +96,7 @@ qbittorrent: * `priority`: 下载提供器优先级,数字越小,优先级越高,下载资源时按优先级尝试,无法下载或下载失败时切换下载器。 * `tags`: 触发下载时使用的tag,可用于资源分类,不需要时可留空或不设置。 * `category`: 触发下载时使用的category,可用于资源分类,不需要时可留空或不设置。 +* `use_auto_torrent_management`: 必须配置category选项,触发下载时,使用category作为保存目录 #### 3.1 来自订阅源的配置 diff --git a/kubespider/download_provider/qbittorrent_download_provider/provider.py b/kubespider/download_provider/qbittorrent_download_provider/provider.py index 9b6669bc..129c73a9 100644 --- a/kubespider/download_provider/qbittorrent_download_provider/provider.py +++ b/kubespider/download_provider/qbittorrent_download_provider/provider.py @@ -24,6 +24,7 @@ def __init__(self, name: str, config_reader: AbsConfigReader) -> None: self.verify_webui_certificate = False self.download_tags = [''] self.download_category = '' + self.use_auto_torrent_management = False def get_provider_type(self) -> str: return self.provider_type @@ -65,10 +66,13 @@ def send_torrent_task(self, task: Task) -> TypeError: logging.info('Start torrent download:%s, path:%s', task.url, download_path) tags = task.extra_param('tags', self.download_tags) category = task.extra_param('category', self.download_category) + use_auto_torrent_management = task.extra_param('auto_management', self.use_auto_torrent_management) + if not category: + use_auto_torrent_management = False try: logging.info('Create download task category:%s, tags:%s', category, tags) ret = self.client.torrents_add(torrent_files=task.url, save_path=download_path, category=category, - tags=tags) + tags=tags, use_auto_torrent_management=use_auto_torrent_management) logging.info('Create download task results:%s', ret) return None except Exception as err: @@ -81,9 +85,12 @@ def send_magnet_task(self, task: Task) -> TypeError: download_path = os.path.join(self.download_base_path, task.path) tags = task.extra_param('tags', self.download_tags) category = task.extra_param('category', self.download_category) + use_auto_torrent_management = task.extra_param('auto_management', self.use_auto_torrent_management) + if not category: + use_auto_torrent_management = False try: logging.info('Create download task category:%s, tags:%s', category, tags) - ret = self.client.torrents_add(urls=task.url, save_path=download_path, category=category, tags=tags) + ret = self.client.torrents_add(urls=task.url, save_path=download_path, category=category, tags=tags, use_auto_torrent_management=use_auto_torrent_management) logging.info('Create download task results:%s', ret) return None except Exception as err: @@ -111,6 +118,7 @@ def load_config(self) -> TypeError: self.verify_webui_certificate = cfg['verify_webui_certificate'] self.download_tags = cfg.get('tags', []) self.download_category = cfg.get('category') + self.use_auto_torrent_management = cfg['use_auto_torrent_management'] self.client = qbittorrentapi.Client( self.http_endpoint_host, self.http_endpoint_port, From 23856411c9d1e0f10e460a60db5f007f8dd4db0c Mon Sep 17 00:00:00 2001 From: miRemid Date: Mon, 13 Nov 2023 16:27:39 +0800 Subject: [PATCH 2/2] fix: the bug of send magnet link Signed-off-by: miRemid --- .../qbittorrent_download_provider/provider.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kubespider/download_provider/qbittorrent_download_provider/provider.py b/kubespider/download_provider/qbittorrent_download_provider/provider.py index 129c73a9..8a34b236 100644 --- a/kubespider/download_provider/qbittorrent_download_provider/provider.py +++ b/kubespider/download_provider/qbittorrent_download_provider/provider.py @@ -66,7 +66,7 @@ def send_torrent_task(self, task: Task) -> TypeError: logging.info('Start torrent download:%s, path:%s', task.url, download_path) tags = task.extra_param('tags', self.download_tags) category = task.extra_param('category', self.download_category) - use_auto_torrent_management = task.extra_param('auto_management', self.use_auto_torrent_management) + use_auto_torrent_management = task.extra_param('use_auto_torrent_management', self.use_auto_torrent_management) if not category: use_auto_torrent_management = False try: @@ -85,7 +85,7 @@ def send_magnet_task(self, task: Task) -> TypeError: download_path = os.path.join(self.download_base_path, task.path) tags = task.extra_param('tags', self.download_tags) category = task.extra_param('category', self.download_category) - use_auto_torrent_management = task.extra_param('auto_management', self.use_auto_torrent_management) + use_auto_torrent_management = task.extra_param('use_auto_torrent_management', self.use_auto_torrent_management) if not category: use_auto_torrent_management = False try: