From bd9066271d1fbe65d817027a8396de1dfcf97e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Sun, 18 Feb 2024 13:12:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=A1=A5=E5=85=A8=E5=88=B7?= =?UTF-8?q?=E6=B5=81=E4=B8=8E=E8=BE=85=E7=A7=8D=E7=9A=84=E7=A7=8D=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/downloadsitetag/__init__.py | 131 ++++++++++++++++++++++++---- 2 files changed, 117 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index ccd6475..86c5be3 100644 --- a/package.json +++ b/package.json @@ -338,7 +338,7 @@ "DownloadSiteTag": { "name": "下载任务分类与标签", "description": "自动给下载任务分类与打站点标签、剧集名称标签", - "version": "1.3", + "version": "1.5", "icon": "Youtube-dl_B.png", "author": "叮叮当", "level": 1 diff --git a/plugins/downloadsitetag/__init__.py b/plugins/downloadsitetag/__init__.py index 4aa089a..df9d6e2 100644 --- a/plugins/downloadsitetag/__init__.py +++ b/plugins/downloadsitetag/__init__.py @@ -11,8 +11,11 @@ from app.plugins import _PluginBase from app.modules.qbittorrent import Qbittorrent from app.modules.transmission import Transmission from app.db.downloadhistory_oper import DownloadHistoryOper +from app.db.models.downloadhistory import DownloadHistory from app.modules.themoviedb.tmdbapi import TmdbHelper from apscheduler.schedulers.background import BackgroundScheduler +from app.helper.sites import SitesHelper +from app.utils.string import StringUtils class DownloadSiteTag(_PluginBase): # 插件名称 @@ -22,7 +25,7 @@ class DownloadSiteTag(_PluginBase): # 插件图标 plugin_icon = "Youtube-dl_B.png" # 插件版本 - plugin_version = "1.3" + plugin_version = "1.5" # 插件作者 plugin_author = "叮叮当" # 作者主页 @@ -103,6 +106,8 @@ class DownloadSiteTag(_PluginBase): 补全下载历史的标签与分类 """ logger.info(f"{self.LOG_TAG}开始执行: 补全下载历史的标签与分类 ...") + # 记录处理的种子, 供辅种(无下载历史)使用 + dispose_history = {} for DOWNLOADER in ["qbittorrent", "transmission"]: logger.info(f"{self.LOG_TAG}开始扫描下载器 {DOWNLOADER} ...") # 获取下载器中的种子 @@ -116,39 +121,68 @@ class DownloadSiteTag(_PluginBase): continue else: logger.info(f"{self.LOG_TAG}下载器 {DOWNLOADER} 种子数:{len(torrents)}") + # 按添加时间进行排序, 时间靠前的按大小和名称加入处理历史, 判定为原始种子, 其他为辅种 + torrents = self._torrents_sort(torrents=torrents, dl_type=DOWNLOADER) for torrent in torrents: + # 获取已处理种子的key (size, name) + _key = self._torrent_key(torrent=torrent, dl_type=DOWNLOADER) # 获取种子hash _hash = self._get_hash(torrent=torrent, dl_type=DOWNLOADER) if not _hash: continue # 提取种子hash对应的下载历史 - history = self.downloadhistory_oper.get_by_hash(_hash) + history: DownloadHistory = self.downloadhistory_oper.get_by_hash(_hash) if not history: - continue + # 如果找到已处理种子的历史, 表明当前种子是辅种, 否则创建一个空DownloadHistory + if _key and _key in dispose_history: + history = dispose_history[_key] + # 因为辅种站点必定不同, 所以需要更新站点名字 history.torrent_site + history.torrent_site = None + else: + history = DownloadHistory( + torrent_site=None, + title=None, + type=None, + tmdbid=None) + else: + # 加入历史记录 + if _key: + dispose_history[_key] = history + # 如果站点名称为空, 尝试通过trackers识别 + if not history.torrent_site: + trackers = self._get_trackers(torrent=torrent, dl_type=DOWNLOADER) + for tracker in trackers: + domain = StringUtils.get_url_domain(tracker) + site_info = SitesHelper().get_indexer(domain) + if site_info: + history.torrent_site = site_info.get("name") + break + # 如果通过tracker还是无法获取站点名称, 且tmdbid, type, title都是空的, 那么跳过当前种子 + if not history.torrent_site and not history.tmdbid and not history.type and not history.title: + continue # 获取种子当前标签 torrent_tags = self._get_label(torrent=torrent, dl_type=DOWNLOADER) torrent_cat = self._get_category(torrent=torrent, dl_type=DOWNLOADER) # 按设置生成需要写入的标签与分类 _tags = [] _cat = None - tmdbid = history.tmdbid - mtype = history.type - # 站点标签, 如果勾选开关的话 + # 站点标签, 如果勾选开关的话 因允许torrent_site为空时运行到此, 因此需要判断torrent_site不为空 if self._enabled_tag and history.torrent_site: _tags.append(history.torrent_site) - # 媒体标题标签, 如果勾选开关的话 + # 媒体标题标签, 如果勾选开关的话 因允许title为空时运行到此, 因此需要判断title不为空 if self._enabled_media_tag and history.title: _tags.append(history.title) - # 分类, 如果勾选开关的话