From b80243e2f2714394575a35b2c9276438be85367c Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Wed, 6 Mar 2024 12:07:07 +0800 Subject: [PATCH 1/4] allow mp to download torrents and send to qb Signed-off-by: d0zingcat --- plugins/brushflow/__init__.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/plugins/brushflow/__init__.py b/plugins/brushflow/__init__.py index 147b639..be85573 100644 --- a/plugins/brushflow/__init__.py +++ b/plugins/brushflow/__init__.py @@ -1,4 +1,5 @@ import re +import requests import threading import time from datetime import datetime, timedelta @@ -117,6 +118,7 @@ class BrushFlow(_PluginBase): self._dl_speed = config.get("dl_speed") self._save_path = config.get("save_path") self._clear_task = config.get("clear_task") + self._offline_mode = config.get("offline_mode") # 过滤掉已删除的站点 self._brushsites = [site.get("id") for site in self.sites.get_indexers() if @@ -348,6 +350,22 @@ class BrushFlow(_PluginBase): } } ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'offline_mode', + 'label': '离线下载种子', + } + } + ] } ] }, @@ -801,6 +819,7 @@ class BrushFlow(_PluginBase): "enabled": False, "notify": True, "onlyonce": False, + "offline_mode": False, "clear_task": False, "freeleech": "free", "hr": "yes", @@ -1641,7 +1660,15 @@ class BrushFlow(_PluginBase): down_speed = down_speed * 1024 if down_speed else None # 生成随机Tag tag = StringUtils.generate_random_str(10) - state = self.qb.add_torrent(content=torrent.enclosure, + content = torrent.enclosure + if self._offline_mode: + torrent_resp = requests.get(content, + headers={'User-Agent': torrent.site_ua.strip(), 'cookie': torrent.site_cookie.strip()}) + if torrent_resp.ok: + content = torrent_resp.content + else: + logger.error('下载种子文件失败,继续提交种子链接进行下载') + state = self.qb.add_torrent(content=content, download_dir=self._save_path or None, cookie=torrent.site_cookie, tag=["已整理", "刷流", tag], From dddfc0d69ad10a4018ff30ca06ad9187bca77b45 Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Wed, 6 Mar 2024 12:18:11 +0800 Subject: [PATCH 2/4] fix config update Signed-off-by: d0zingcat --- plugins/brushflow/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/brushflow/__init__.py b/plugins/brushflow/__init__.py index be85573..a809c26 100644 --- a/plugins/brushflow/__init__.py +++ b/plugins/brushflow/__init__.py @@ -1315,7 +1315,8 @@ class BrushFlow(_PluginBase): "up_speed": self._up_speed, "dl_speed": self._dl_speed, "save_path": self._save_path, - "clear_task": self._clear_task + "clear_task": self._clear_task, + "offline_mode": self._offline_mode, }) def brush(self): From d3a067ed48b64ce2bb51c55d515c38ae1fe2bde0 Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Wed, 6 Mar 2024 12:57:56 +0800 Subject: [PATCH 3/4] typo Signed-off-by: d0zingcat --- plugins/brushflow/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/brushflow/__init__.py b/plugins/brushflow/__init__.py index a809c26..35ca9a3 100644 --- a/plugins/brushflow/__init__.py +++ b/plugins/brushflow/__init__.py @@ -32,7 +32,7 @@ class BrushFlow(_PluginBase): # 插件图标 plugin_icon = "brush.jpg" # 插件版本 - plugin_version = "1.3" + plugin_version = "1.4" # 插件作者 plugin_author = "jxxghp" # 作者主页 @@ -1316,7 +1316,7 @@ class BrushFlow(_PluginBase): "dl_speed": self._dl_speed, "save_path": self._save_path, "clear_task": self._clear_task, - "offline_mode": self._offline_mode, + "offline_mode": self._offline_mode }) def brush(self): From a5370e2e49f5d91629b58a3d6c28c4eca1d0176c Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Wed, 6 Mar 2024 16:34:16 +0800 Subject: [PATCH 4/4] use requestutils instead Signed-off-by: d0zingcat --- plugins/brushflow/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/brushflow/__init__.py b/plugins/brushflow/__init__.py index 35ca9a3..c1453b9 100644 --- a/plugins/brushflow/__init__.py +++ b/plugins/brushflow/__init__.py @@ -1,5 +1,4 @@ import re -import requests import threading import time from datetime import datetime, timedelta @@ -19,6 +18,7 @@ from app.modules.qbittorrent import Qbittorrent from app.modules.transmission import Transmission from app.plugins import _PluginBase from app.schemas import Notification, NotificationType, TorrentInfo +from app.utils.http import RequestUtils from app.utils.string import StringUtils lock = threading.Lock() @@ -1663,10 +1663,10 @@ class BrushFlow(_PluginBase): tag = StringUtils.generate_random_str(10) content = torrent.enclosure if self._offline_mode: - torrent_resp = requests.get(content, - headers={'User-Agent': torrent.site_ua.strip(), 'cookie': torrent.site_cookie.strip()}) - if torrent_resp.ok: - content = torrent_resp.content + torrent_res = RequestUtils(cookies=torrent.site_cookie, + ua=torrent.site_ua).get_res(url=content) + if torrent_res.ok: + content = torrent_res.content else: logger.error('下载种子文件失败,继续提交种子链接进行下载') state = self.qb.add_torrent(content=content,