From 01d3014317f192fb22ef487cf5d950ec6567cafd 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, 4 Feb 2024 18:21:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=B7=BB=E5=8A=A0=E7=AB=99=E7=82=B9=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E4=B8=8E=E4=B8=80=E7=BA=A7=E5=88=86=E7=B1=BB=20?= =?UTF-8?q?=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 8 + plugins/downloadsitetag/__init__.py | 302 ++++++++++++++++++++++++++++ 2 files changed, 310 insertions(+) create mode 100644 plugins/downloadsitetag/__init__.py diff --git a/package.json b/package.json index 1e40aa6..bb22788 100644 --- a/package.json +++ b/package.json @@ -334,5 +334,13 @@ "icon": "Pushplus_A.png", "author": "cheng", "level": 1 + }, + "DownloadSiteTag": { + "name": "下载任务分类与标签", + "description": "自动给下载任务分类与打站点标签", + "version": "1.1", + "icon": "nfo.png", + "author": "叮叮当", + "level": 1 } } diff --git a/plugins/downloadsitetag/__init__.py b/plugins/downloadsitetag/__init__.py new file mode 100644 index 0000000..dcf72a6 --- /dev/null +++ b/plugins/downloadsitetag/__init__.py @@ -0,0 +1,302 @@ +from typing import List, Tuple, Dict, Any + +from app.core.context import Context +from app.core.event import eventmanager, Event +from app.schemas.types import EventType, MediaType +from app.core.config import settings +from app.log import logger +from app.plugins import _PluginBase +from app.modules.qbittorrent import Qbittorrent +from app.modules.transmission import Transmission + +class DownloadSiteTag(_PluginBase): + # 插件名称 + plugin_name = "下载任务分类与标签" + # 插件描述 + plugin_desc = "自动给下载任务分类与打站点标签" + # 插件图标 + plugin_icon = "nfo.png" + # 插件版本 + plugin_version = "1.1" + # 插件作者 + plugin_author = "叮叮当" + # 作者主页 + author_url = "https://github.com/cikezhu" + # 插件配置项ID前缀 + plugin_config_prefix = "DownloadSiteTag_" + # 加载顺序 + plugin_order = 2 + # 可使用的用户级别 + auth_level = 1 + + # 私有属性 + downloader_name = None + downloader_example = None + _enabled = False + _enabled_tag = True + _enabled_category = False + _category_movie = None + _category_tv = None + _category_anime = None + + def init_plugin(self, config: dict = None): + # 读取配置 + if config: + self._enabled = config.get("enabled") + self._enabled_tag = config.get("enabled_tag") + self._enabled_category = config.get("enabled_category") + self._category_movie = config.get("category_movie") or "电影" + self._category_tv = config.get("category_tv") or "电视" + self._category_anime = config.get("category_anime") or "动漫" + + def get_state(self) -> bool: + return self._enabled + + @staticmethod + def get_command() -> List[Dict[str, Any]]: + pass + + def get_api(self) -> List[Dict[str, Any]]: + pass + + @eventmanager.register(EventType.DownloadAdded) + def DownloadAdded(self, event: Event): + """ + 添加下载事件 + """ + if not self.get_state(): + return + + if not event.event_data: + return + + DOWNLOADER = getattr(settings, "DOWNLOADER") + if self.downloader_name != DOWNLOADER: + if DOWNLOADER == "qbittorrent": + self.downloader_example = Qbittorrent() + self.downloader_name = DOWNLOADER + elif DOWNLOADER == "transmission": + self.downloader_example = Transmission() + self.downloader_name = DOWNLOADER + else: + self.downloader_example = None + self.downloader_name = None + if self.downloader_name and self.downloader_example: + context: Context = event.event_data.get("context") + _hash = event.event_data.get("hash") + _torrent = context.torrent_info + _media = context.media_info + _media_type = None + + if self.downloader_name == "qbittorrent": + # 设置标签, 如果勾选开关的话 + if self._enabled_tag: + self.downloader_example.set_torrents_tag(ids=_hash, tags=[_torrent.site_name]) + # 设置分类, 如果勾选开关的话