From b80243e2f2714394575a35b2c9276438be85367c Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Wed, 6 Mar 2024 12:07:07 +0800 Subject: [PATCH 01/13] 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 02/13] 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 03/13] 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 1a7c3bda25af838785cb8d17d0bfc060608c1501 Mon Sep 17 00:00:00 2001 From: thsrite Date: Wed, 6 Mar 2024 13:40:16 +0800 Subject: [PATCH 04/13] =?UTF-8?q?fix=20=E4=BA=91=E7=9B=98=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=90=8C=E6=AD=A5=E5=88=A0=E9=99=A4=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=BC=93=E5=AD=98=EF=BC=88=E9=85=8D=E5=90=88?= =?UTF-8?q?=E4=BA=91=E7=9B=98strm=E7=94=9F=E6=88=90=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/clouddiskdel/__init__.py | 37 ++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7da0d81..4e881de 100644 --- a/package.json +++ b/package.json @@ -258,7 +258,7 @@ "CloudDiskDel": { "name": "云盘文件删除", "description": "媒体库删除strm文件后同步删除云盘资源。", - "version": "1.2", + "version": "1.3", "icon": "clouddisk.png", "author": "thsrite", "level": 1 diff --git a/plugins/clouddiskdel/__init__.py b/plugins/clouddiskdel/__init__.py index cb54d19..e827ca0 100644 --- a/plugins/clouddiskdel/__init__.py +++ b/plugins/clouddiskdel/__init__.py @@ -1,3 +1,5 @@ +import json +import os import shutil import time from pathlib import Path @@ -20,7 +22,7 @@ class CloudDiskDel(_PluginBase): # 插件图标 plugin_icon = "clouddisk.png" # 插件版本 - plugin_version = "1.2" + plugin_version = "1.3" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -105,6 +107,7 @@ class CloudDiskDel(_PluginBase): for file in files: Path(file).unlink() logger.info(f"云盘文件 {file} 已删除") + self.__remove_json(file) remove_flag = True if not remove_flag: @@ -113,11 +116,13 @@ class CloudDiskDel(_PluginBase): if Path(file).exists(): Path(file).unlink() logger.info(f"云盘文件 {file} 已删除") + self.__remove_json(file) else: # 非根目录,才删除目录 shutil.rmtree(path) # 删除目录 logger.warn(f"云盘目录 {path} 已删除") + self.__remove_json(path) # 判断当前媒体父路径下是否有媒体文件,如有则无需遍历父级 if not SystemUtils.exits_files(path.parent, settings.RMT_MEDIAEXT): @@ -129,7 +134,7 @@ class CloudDiskDel(_PluginBase): # 当前路径下没有媒体文件则删除 shutil.rmtree(parent_path) logger.warn(f"云盘目录 {parent_path} 已删除") - + self.__remove_json(parent_path) break if cloud_file_flag: @@ -191,6 +196,34 @@ class CloudDiskDel(_PluginBase): # 保存历史 self.save_data("history", history) + def __remove_json(self, path): + """ + 删除json中的文件内容 + """ + try: + # 删除本地缓存文件 + cloud_files_json = os.path.join(settings.PLUGIN_DATA_PATH, "CloudStrm", "cloud_files.json") + if Path(cloud_files_json).exists(): + # 删除json文件中已删除部分文件 + # 尝试加载本地 + with open(cloud_files_json, 'r') as file: + content = file.read() + if content: + __cloud_files = json.loads(content) + if __cloud_files: + if not isinstance(__cloud_files, list): + __cloud_files = [__cloud_files] + if str(path) in __cloud_files: + # 删除已删除文件 + __cloud_files.remove(str(path)) + # 重新写入本地 + file = open(cloud_files_json, 'w') + file.write(json.dumps(__cloud_files)) + file.close() + + except Exception as e: + print(str(e)) + def get_state(self) -> bool: return self._enabled From a5370e2e49f5d91629b58a3d6c28c4eca1d0176c Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Wed, 6 Mar 2024 16:34:16 +0800 Subject: [PATCH 05/13] 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, From 5be3182b048ffe7b16a2fe8a51f3bd058a10942e Mon Sep 17 00:00:00 2001 From: jeblove <249972068@qq.com> Date: Wed, 6 Mar 2024 23:39:34 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E3=80=90=E8=AF=8A?= =?UTF-8?q?=E6=96=AD=E5=8F=82=E6=95=B0=E8=B0=83=E6=95=B4=E3=80=91=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 11 +- plugins/diagparamadjust/__init__.py | 348 ++++++++++++++++++++++++++++ 2 files changed, 358 insertions(+), 1 deletion(-) create mode 100644 plugins/diagparamadjust/__init__.py diff --git a/package.json b/package.json index 7da0d81..924377c 100644 --- a/package.json +++ b/package.json @@ -390,5 +390,14 @@ "icon": "Amule_A.png", "author": "jxxghp", "level": 1 - } + }, + "DiagParamAdjust": { + "name": "诊断参数调整", + "description": "Emby专用插件|暂时性解决emby字幕偏移问题,需要emby安装Diagnostics插件。", + "version": "1.0", + "icon": "Themeengine_A.png", + "author": "jeblove", + "level": 1 + }, + } diff --git a/plugins/diagparamadjust/__init__.py b/plugins/diagparamadjust/__init__.py new file mode 100644 index 0000000..02645d9 --- /dev/null +++ b/plugins/diagparamadjust/__init__.py @@ -0,0 +1,348 @@ +import json +from datetime import datetime, timedelta + +from app.modules.emby import Emby +from app.core.config import settings +from app.plugins import _PluginBase +from app.log import logger +from typing import List, Tuple, Dict, Any, Optional +import pytz + +from apscheduler.triggers.cron import CronTrigger +from apscheduler.schedulers.background import BackgroundScheduler + +class DiagParamAdjust(_PluginBase): + # 插件名称 + plugin_name = "诊断参数调整" + # 插件描述 + plugin_desc = "Emby专用插件|暂时性解决emby字幕偏移问题,需要emby安装Diagnostics插件。" + # 插件图标 + plugin_icon = "Themeengine_A.png" + # 插件版本 + plugin_version = "1.0" + # 插件作者 + plugin_author = "jeblove" + # 作者主页 + author_url = "https://github.com/jeblove" + # 插件配置项ID前缀 + plugin_config_prefix = "dpa_" + # 加载顺序 + plugin_order = 14 + # 可使用的用户级别 + auth_level = 1 + + # 私有属性 + _enabled: bool = False + _offset = True + _onlyonce = False + _base_url = None + _endpoint = None + _api_key = None + _search_text = None + _replace_text = None + _cron = None + # 请求接口 + _url = "[HOST]emby/EncodingDiagnostics/DiagnosticOptions?api_key=[APIKEY]" + # 定时器 + _scheduler: Optional[BackgroundScheduler] = None + + def init_plugin(self, config: dict = None): + # 停止现有任务 + self.stop_service() + + if config: + self._enabled = config.get("enabled") + self._offset = config.get('offset') + self._onlyonce = config.get("onlyonce") + self._search_text = config.get("search") + self._replace_text = config.get("replace") + self._cron = config.get("cron") + + if self._onlyonce: + self._scheduler = BackgroundScheduler(timezone=settings.TZ) + logger.info(f"诊断参数调整服务启动,立刻运行一次") + self._scheduler.add_job(func=self.run, trigger='date', + run_date=datetime.now(tz=pytz.timezone(settings.TZ)) + timedelta(seconds=3), + name="诊断参数调整") + + # 关闭一次性开关 + self._onlyonce = False + self.update_config({ + "enabled": self._enabled, + "offset": self._offset, + "onlyonce": False, + "search": self._search_text, + "replace": self._replace_text, + "cron": self._cron + }) + + # 启动任务 + # self.run() + if self._scheduler.get_jobs(): + self._scheduler.print_jobs() + self._scheduler.start() + + 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 + + def get_service(self) -> List[Dict[str, Any]]: + """ + 注册插件公共服务 + [{ + "id": "服务ID", + "name": "服务名称", + "trigger": "触发器:cron/interval/date/CronTrigger.from_crontab()", + "func": self.xxx, + "kwargs": {} # 定时器参数 + }] + """ + if self._enabled and self._cron: + return [{ + "id": "DiagParamAdjust", + "name": "诊断参数调整定时服务", + "trigger": CronTrigger.from_crontab(self._cron), + "func": self.run, + "kwargs": {} + }] + + def get_form(self) -> Tuple[List[dict], Dict[str, Any]]: + """ + 拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构 + """ + return [ + { + 'component': 'VForm', + 'content': [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'enabled', + 'label': '启用插件', + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'offset', + 'label': '字幕偏移用途', + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'onlyonce', + 'label': '立即运行一次', + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VTextField', + 'props': { + 'model': 'search', + 'label': '搜索文本' + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VTextField', + 'props': { + 'model': 'replace', + 'label': '替换文本' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VTextField', + 'props': { + 'model': 'cron', + 'label': '检测执行周期', + 'placeholder': '*/5 * * * *' + } + } + ] + }, + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'info', + 'variant': 'tonal', + 'text': '暂时性解决emby字幕偏移问题,请在默认参数的基础上修改至适合。\n 此替换文本参数应用于emby-Diagnostics-Parameter Adjustment。\n 默认参数用于修改ffmpeg中字幕覆盖在视频上的位置。\n 方案来源于https://opve.cn/archives/983.html', + 'style': 'white-space: pre-line;' + } + } + ] + } + ] + } + ] + } + ],{ + "enabled": False, + "offset": True, + "onlyonce": False, + "search": "x=(W-w)/2:y=(H-h):repeatlast=0", + "replace": "x=W/4:y=h/4:repeatlast=0", + "cron": "*/5 * * * *" + } + + def detect(self): + ''' + 检测是否存在目标参数 + + :return True: 存在; False: 不存在 + ''' + logger.info('字幕偏移修正,检测目标参数') + replaceText = "" + try: + # req_url = "[HOST]emby/EncodingDiagnostics/DiagnosticOptions?api_key=[APIKEY]" + res = Emby().get_data(self._url) + result = res.json() + data = result['Object']['CommandLineOptions'] + replaceText = data['ReplaceText'] + except json.JSONDecodeError as j: + logger.error('服务停止,Emby请安装【Diagnostics】插件') + return None + except KeyError: + # 以装插件,未设置过该参数 + # logger.info('目标参数为空') + pass + + # 符合所有情况 + if 'repeatlast' in replaceText \ + and 'x=(W-w)/2:y=(H-h):repeatlast=0' in data['SearchText'] \ + and result['Object']['TranscodingOptions']['DisableHardwareSubtitleOverlay']==True: + return True + + return False + + def setOptions(self): + data = { + "CommandLineOptions": { + "SearchText": self._search_text, + "ReplaceText": self._replace_text + }, + "TranscodingOptions": { + "DisableHardwareSubtitleOverlay": True + } + } + data = json.dumps(data) + headers = { + 'Content-Type': 'application/octet-stream' + } + res = Emby().post_data(self._url, data, headers) + if res.status_code // 100 == 2: + logger.info('参数设置成功') + return True + else: + logger.error('参数设置失败 {}'.format(res.status_code)) + + def run(self): + # 字幕偏移修正,则带检测 + if self._offset: + state = self.detect() + if state: + logger.info('参数正常,无需修正') + return True + elif state==None: + return None + + self.setOptions() + + + def get_page(self) -> List[dict]: + pass + + def stop_service(self): + """ + 退出插件 + """ + try: + if self._scheduler: + self._scheduler.remove_all_jobs() + if self._scheduler.running: + self._scheduler.shutdown() + self._scheduler = None + except Exception as e: + logger.error("退出插件失败:%s" % str(e)) + + From bccc46d1c210716eec41c2edd795b80fc3cf1c96 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 7 Mar 2024 07:04:12 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4961fef..73ad7f9 100644 --- a/package.json +++ b/package.json @@ -210,7 +210,7 @@ "BrushFlow": { "name": "站点刷流", "description": "自动托管刷流,将会提高对应站点的访问频率。", - "version": "1.3", + "version": "1.4", "icon": "brush.jpg", "author": "jxxghp", "level": 2 From 61665ff58ac8f01a6f9ddc944ee8f4ee0afeb005 Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 7 Mar 2024 10:56:01 +0800 Subject: [PATCH 08/13] =?UTF-8?q?fix=205be3182b=20json=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 8d63578..b233b3f 100644 --- a/package.json +++ b/package.json @@ -398,6 +398,5 @@ "icon": "Themeengine_A.png", "author": "jeblove", "level": 1 - }, - + } } From edee6d23006fbdee3ac91c4d165a1376e48e829a Mon Sep 17 00:00:00 2001 From: jeblove <249972068@qq.com> Date: Thu, 7 Mar 2024 17:09:39 +0800 Subject: [PATCH 09/13] =?UTF-8?q?add=20=E9=80=9A=E8=BF=87webhooks=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/diagparamadjust/__init__.py | 109 +++++++++++++++++++++++++--- 2 files changed, 100 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 924377c..36e57a6 100644 --- a/package.json +++ b/package.json @@ -394,7 +394,7 @@ "DiagParamAdjust": { "name": "诊断参数调整", "description": "Emby专用插件|暂时性解决emby字幕偏移问题,需要emby安装Diagnostics插件。", - "version": "1.0", + "version": "1.1", "icon": "Themeengine_A.png", "author": "jeblove", "level": 1 diff --git a/plugins/diagparamadjust/__init__.py b/plugins/diagparamadjust/__init__.py index 02645d9..08d8a42 100644 --- a/plugins/diagparamadjust/__init__.py +++ b/plugins/diagparamadjust/__init__.py @@ -7,6 +7,9 @@ from app.plugins import _PluginBase from app.log import logger from typing import List, Tuple, Dict, Any, Optional import pytz +from app.schemas import WebhookEventInfo +from app.schemas.types import EventType +from app.core.event import eventmanager, Event from apscheduler.triggers.cron import CronTrigger from apscheduler.schedulers.background import BackgroundScheduler @@ -19,7 +22,7 @@ class DiagParamAdjust(_PluginBase): # 插件图标 plugin_icon = "Themeengine_A.png" # 插件版本 - plugin_version = "1.0" + plugin_version = "1.1" # 插件作者 plugin_author = "jeblove" # 作者主页 @@ -41,11 +44,19 @@ class DiagParamAdjust(_PluginBase): _search_text = None _replace_text = None _cron = None + _cron_switch = False + _login_play = False # 请求接口 _url = "[HOST]emby/EncodingDiagnostics/DiagnosticOptions?api_key=[APIKEY]" # 定时器 _scheduler: Optional[BackgroundScheduler] = None + # 目标消息 + _webhook_actions = { + "playback.start": "开始播放", + "user.authenticated": "登录成功" + } + def init_plugin(self, config: dict = None): # 停止现有任务 self.stop_service() @@ -57,6 +68,8 @@ class DiagParamAdjust(_PluginBase): self._search_text = config.get("search") self._replace_text = config.get("replace") self._cron = config.get("cron") + self._cron_switch = config.get("cron_switch") + self._login_play = config.get("login_play") if self._onlyonce: self._scheduler = BackgroundScheduler(timezone=settings.TZ) @@ -73,7 +86,9 @@ class DiagParamAdjust(_PluginBase): "onlyonce": False, "search": self._search_text, "replace": self._replace_text, - "cron": self._cron + "cron": self._cron, + "cron_switch": self._cron_switch, + "login_play": self._login_play }) # 启动任务 @@ -103,7 +118,7 @@ class DiagParamAdjust(_PluginBase): "kwargs": {} # 定时器参数 }] """ - if self._enabled and self._cron: + if self._enabled and self._cron and self._cron_switch: return [{ "id": "DiagParamAdjust", "name": "诊断参数调整定时服务", @@ -230,6 +245,38 @@ class DiagParamAdjust(_PluginBase): } ] }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 3 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'cron_switch', + 'label': '周期模式', + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 3 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'login_play', + 'label': '用户登录|播放时执行', + } + } + ] + } ] }, { @@ -246,7 +293,29 @@ class DiagParamAdjust(_PluginBase): 'props': { 'type': 'info', 'variant': 'tonal', - 'text': '暂时性解决emby字幕偏移问题,请在默认参数的基础上修改至适合。\n 此替换文本参数应用于emby-Diagnostics-Parameter Adjustment。\n 默认参数用于修改ffmpeg中字幕覆盖在视频上的位置。\n 方案来源于https://opve.cn/archives/983.html', + 'text': '暂时性解决emby字幕偏移问题,如默认参数不合适请在基础上修改x、y至适合,如[x=W/4:y=h/5]。\n 【用户登录|播放时执行】需要emby配置webhooks消息通知:勾选[播放-开始]、[用户-已验证用户身份](具体可参考【媒体库服务器通知】插件)', + 'style': 'white-space: pre-line;' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'info', + 'variant': 'tonal', + 'text': '此替换文本参数应用于emby-Diagnostics-Parameter Adjustment。\n 默认参数用于修改ffmpeg中字幕覆盖在视频上的位置。\n 方案来源于https://opve.cn/archives/983.html', 'style': 'white-space: pre-line;' } } @@ -262,7 +331,9 @@ class DiagParamAdjust(_PluginBase): "onlyonce": False, "search": "x=(W-w)/2:y=(H-h):repeatlast=0", "replace": "x=W/4:y=h/4:repeatlast=0", - "cron": "*/5 * * * *" + "cron": "*/5 * * * *", + "cron_switch": True, + "login_play": False } def detect(self): @@ -274,7 +345,6 @@ class DiagParamAdjust(_PluginBase): logger.info('字幕偏移修正,检测目标参数') replaceText = "" try: - # req_url = "[HOST]emby/EncodingDiagnostics/DiagnosticOptions?api_key=[APIKEY]" res = Emby().get_data(self._url) result = res.json() data = result['Object']['CommandLineOptions'] @@ -283,7 +353,7 @@ class DiagParamAdjust(_PluginBase): logger.error('服务停止,Emby请安装【Diagnostics】插件') return None except KeyError: - # 以装插件,未设置过该参数 + # 已装插件,未设置过该参数 # logger.info('目标参数为空') pass @@ -295,7 +365,7 @@ class DiagParamAdjust(_PluginBase): return False - def setOptions(self): + def set_options(self): data = { "CommandLineOptions": { "SearchText": self._search_text, @@ -315,7 +385,26 @@ class DiagParamAdjust(_PluginBase): return True else: logger.error('参数设置失败 {}'.format(res.status_code)) - + return False + + @eventmanager.register(EventType.WebhookMessage) + def get_msg(self, event: Event): + # 消息方式开关 + if not self._enabled or not self._login_play: + return + + # 消息获取 + event_info: WebhookEventInfo = event.event_data + if not event_info: + return + + # 非目标消息 + if not self._webhook_actions.get(event_info.event): + return + + self.run() + + def run(self): # 字幕偏移修正,则带检测 if self._offset: @@ -326,7 +415,7 @@ class DiagParamAdjust(_PluginBase): elif state==None: return None - self.setOptions() + self.set_options() def get_page(self) -> List[dict]: From a6742d1f322a08ddbd8055c86aa176889c319f2d Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 7 Mar 2024 17:28:55 +0800 Subject: [PATCH 10/13] fix ide warning --- plugins/diagparamadjust/__init__.py | 44 +++++++++++++---------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/plugins/diagparamadjust/__init__.py b/plugins/diagparamadjust/__init__.py index 08d8a42..74b28fd 100644 --- a/plugins/diagparamadjust/__init__.py +++ b/plugins/diagparamadjust/__init__.py @@ -14,6 +14,7 @@ from app.core.event import eventmanager, Event from apscheduler.triggers.cron import CronTrigger from apscheduler.schedulers.background import BackgroundScheduler + class DiagParamAdjust(_PluginBase): # 插件名称 plugin_name = "诊断参数调整" @@ -50,13 +51,13 @@ class DiagParamAdjust(_PluginBase): _url = "[HOST]emby/EncodingDiagnostics/DiagnosticOptions?api_key=[APIKEY]" # 定时器 _scheduler: Optional[BackgroundScheduler] = None - + # 目标消息 _webhook_actions = { "playback.start": "开始播放", "user.authenticated": "登录成功" } - + def init_plugin(self, config: dict = None): # 停止现有任务 self.stop_service() @@ -90,7 +91,7 @@ class DiagParamAdjust(_PluginBase): "cron_switch": self._cron_switch, "login_play": self._login_play }) - + # 启动任务 # self.run() if self._scheduler.get_jobs(): @@ -99,7 +100,7 @@ class DiagParamAdjust(_PluginBase): def get_state(self) -> bool: return self._enabled - + @staticmethod def get_command() -> List[Dict[str, Any]]: pass @@ -325,7 +326,7 @@ class DiagParamAdjust(_PluginBase): } ] } - ],{ + ], { "enabled": False, "offset": True, "onlyonce": False, @@ -335,36 +336,35 @@ class DiagParamAdjust(_PluginBase): "cron_switch": True, "login_play": False } - + def detect(self): - ''' + """ 检测是否存在目标参数 - :return True: 存在; False: 不存在 - ''' + :return True: 存在; False: 不存在 + """ logger.info('字幕偏移修正,检测目标参数') - replaceText = "" try: res = Emby().get_data(self._url) result = res.json() data = result['Object']['CommandLineOptions'] replaceText = data['ReplaceText'] - except json.JSONDecodeError as j: + except json.JSONDecodeError: logger.error('服务停止,Emby请安装【Diagnostics】插件') return None except KeyError: # 已装插件,未设置过该参数 # logger.info('目标参数为空') - pass + return None # 符合所有情况 if 'repeatlast' in replaceText \ - and 'x=(W-w)/2:y=(H-h):repeatlast=0' in data['SearchText'] \ - and result['Object']['TranscodingOptions']['DisableHardwareSubtitleOverlay']==True: + and 'x=(W-w)/2:y=(H-h):repeatlast=0' in data['SearchText'] \ + and result['Object']['TranscodingOptions']['DisableHardwareSubtitleOverlay'] is True: return True - + return False - + def set_options(self): data = { "CommandLineOptions": { @@ -392,7 +392,7 @@ class DiagParamAdjust(_PluginBase): # 消息方式开关 if not self._enabled or not self._login_play: return - + # 消息获取 event_info: WebhookEventInfo = event.event_data if not event_info: @@ -401,9 +401,8 @@ class DiagParamAdjust(_PluginBase): # 非目标消息 if not self._webhook_actions.get(event_info.event): return - + self.run() - def run(self): # 字幕偏移修正,则带检测 @@ -412,11 +411,10 @@ class DiagParamAdjust(_PluginBase): if state: logger.info('参数正常,无需修正') return True - elif state==None: + elif state is None: return None - - self.set_options() + self.set_options() def get_page(self) -> List[dict]: pass @@ -433,5 +431,3 @@ class DiagParamAdjust(_PluginBase): self._scheduler = None except Exception as e: logger.error("退出插件失败:%s" % str(e)) - - From f1092719b26de89eb589d786c0d89777168fb191 Mon Sep 17 00:00:00 2001 From: jeblove <249972068@qq.com> Date: Thu, 7 Mar 2024 18:18:47 +0800 Subject: [PATCH 11/13] =?UTF-8?q?fix=20=E8=AF=AD=E6=B3=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/diagparamadjust/__init__.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 4cc27bb..42a44a9 100644 --- a/package.json +++ b/package.json @@ -394,7 +394,7 @@ "DiagParamAdjust": { "name": "诊断参数调整", "description": "Emby专用插件|暂时性解决emby字幕偏移问题,需要emby安装Diagnostics插件。", - "version": "1.1", + "version": "1.2", "icon": "Themeengine_A.png", "author": "jeblove", "level": 1 diff --git a/plugins/diagparamadjust/__init__.py b/plugins/diagparamadjust/__init__.py index 74b28fd..07e20ca 100644 --- a/plugins/diagparamadjust/__init__.py +++ b/plugins/diagparamadjust/__init__.py @@ -23,7 +23,7 @@ class DiagParamAdjust(_PluginBase): # 插件图标 plugin_icon = "Themeengine_A.png" # 插件版本 - plugin_version = "1.1" + plugin_version = "1.2" # 插件作者 plugin_author = "jeblove" # 作者主页 @@ -355,7 +355,7 @@ class DiagParamAdjust(_PluginBase): except KeyError: # 已装插件,未设置过该参数 # logger.info('目标参数为空') - return None + return False # 符合所有情况 if 'repeatlast' in replaceText \ @@ -412,6 +412,7 @@ class DiagParamAdjust(_PluginBase): logger.info('参数正常,无需修正') return True elif state is None: + logger.info('插件退出') return None self.set_options() From 05cfee0b93c9d84ca4260b7d282ba9ba6545b94e Mon Sep 17 00:00:00 2001 From: thsrite Date: Fri, 8 Mar 2024 10:08:48 +0800 Subject: [PATCH 12/13] =?UTF-8?q?fix=20=E5=88=A0=E9=99=A4=E4=BA=91?= =?UTF-8?q?=E7=9B=98=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/clouddiskdel/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/clouddiskdel/__init__.py b/plugins/clouddiskdel/__init__.py index e827ca0..7769171 100644 --- a/plugins/clouddiskdel/__init__.py +++ b/plugins/clouddiskdel/__init__.py @@ -220,7 +220,18 @@ class CloudDiskDel(_PluginBase): file = open(cloud_files_json, 'w') file.write(json.dumps(__cloud_files)) file.close() - + else: + remove_flag = False + # 删除目录下文件 + for cloud_file in __cloud_files: + if str(cloud_file).startswith(str(path)): + __cloud_files.remove(cloud_file) + remove_flag = True + if remove_flag: + # 重新写入本地 + file = open(cloud_files_json, 'w') + file.write(json.dumps(__cloud_files)) + file.close() except Exception as e: print(str(e)) From 2db9a7d9b0ca80a039d00e790bff733645bb013d Mon Sep 17 00:00:00 2001 From: jeblove <249972068@qq.com> Date: Fri, 8 Mar 2024 16:03:07 +0800 Subject: [PATCH 13/13] =?UTF-8?q?fix=20=E5=85=BC=E5=AE=B9=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/diagparamadjust/__init__.py | 103 +++++++++++++++++----------- 2 files changed, 63 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 42a44a9..d7b90e2 100644 --- a/package.json +++ b/package.json @@ -394,7 +394,7 @@ "DiagParamAdjust": { "name": "诊断参数调整", "description": "Emby专用插件|暂时性解决emby字幕偏移问题,需要emby安装Diagnostics插件。", - "version": "1.2", + "version": "1.3", "icon": "Themeengine_A.png", "author": "jeblove", "level": 1 diff --git a/plugins/diagparamadjust/__init__.py b/plugins/diagparamadjust/__init__.py index 07e20ca..665983c 100644 --- a/plugins/diagparamadjust/__init__.py +++ b/plugins/diagparamadjust/__init__.py @@ -1,4 +1,4 @@ -import json +import json,re from datetime import datetime, timedelta from app.modules.emby import Emby @@ -23,7 +23,7 @@ class DiagParamAdjust(_PluginBase): # 插件图标 plugin_icon = "Themeengine_A.png" # 插件版本 - plugin_version = "1.2" + plugin_version = "1.3" # 插件作者 plugin_author = "jeblove" # 作者主页 @@ -37,7 +37,8 @@ class DiagParamAdjust(_PluginBase): # 私有属性 _enabled: bool = False - _offset = True + # 修正字幕偏移用途(播放时执行) + _offset_play = True _onlyonce = False _base_url = None _endpoint = None @@ -46,7 +47,7 @@ class DiagParamAdjust(_PluginBase): _replace_text = None _cron = None _cron_switch = False - _login_play = False + # 请求接口 _url = "[HOST]emby/EncodingDiagnostics/DiagnosticOptions?api_key=[APIKEY]" # 定时器 @@ -55,22 +56,28 @@ class DiagParamAdjust(_PluginBase): # 目标消息 _webhook_actions = { "playback.start": "开始播放", - "user.authenticated": "登录成功" } + # 分辨率标识 + _resolution = None + # 分辨率改动 + _last_resolution = None + # 目标参数 + _target_search_text = None + _target_replace_text = None + def init_plugin(self, config: dict = None): # 停止现有任务 self.stop_service() if config: self._enabled = config.get("enabled") - self._offset = config.get('offset') + self._offset_play = config.get("offset_play") self._onlyonce = config.get("onlyonce") self._search_text = config.get("search") self._replace_text = config.get("replace") self._cron = config.get("cron") self._cron_switch = config.get("cron_switch") - self._login_play = config.get("login_play") if self._onlyonce: self._scheduler = BackgroundScheduler(timezone=settings.TZ) @@ -83,17 +90,15 @@ class DiagParamAdjust(_PluginBase): self._onlyonce = False self.update_config({ "enabled": self._enabled, - "offset": self._offset, + "offset_play": self._offset_play, "onlyonce": False, "search": self._search_text, "replace": self._replace_text, "cron": self._cron, "cron_switch": self._cron_switch, - "login_play": self._login_play }) # 启动任务 - # self.run() if self._scheduler.get_jobs(): self._scheduler.print_jobs() self._scheduler.start() @@ -165,8 +170,8 @@ class DiagParamAdjust(_PluginBase): { 'component': 'VSwitch', 'props': { - 'model': 'offset', - 'label': '字幕偏移用途', + 'model': 'offset_play', + 'label': '修正字幕偏移(播放时执行)', } } ] @@ -261,22 +266,6 @@ class DiagParamAdjust(_PluginBase): } } ] - }, - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 3 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'login_play', - 'label': '用户登录|播放时执行', - } - } - ] } ] }, @@ -294,7 +283,7 @@ class DiagParamAdjust(_PluginBase): 'props': { 'type': 'info', 'variant': 'tonal', - 'text': '暂时性解决emby字幕偏移问题,如默认参数不合适请在基础上修改x、y至适合,如[x=W/4:y=h/5]。\n 【用户登录|播放时执行】需要emby配置webhooks消息通知:勾选[播放-开始]、[用户-已验证用户身份](具体可参考【媒体库服务器通知】插件)', + 'text': '- 暂时性解决emby字幕偏移问题,如默认参数不合适请在基础上修改【替换文本】x、y至适合(4K视频情况下!),如[x=W/4:y=h/5]。\n - 【修正字幕偏移(播放时执行)】需要emby配置webhooks消息通知:勾选[播放-开始](具体可参考【媒体库服务器通知】插件)', 'style': 'white-space: pre-line;' } } @@ -316,7 +305,7 @@ class DiagParamAdjust(_PluginBase): 'props': { 'type': 'info', 'variant': 'tonal', - 'text': '此替换文本参数应用于emby-Diagnostics-Parameter Adjustment。\n 默认参数用于修改ffmpeg中字幕覆盖在视频上的位置。\n 方案来源于https://opve.cn/archives/983.html', + 'text': '- 播放视频分辨率与上次视频分辨率不一致时,在通知延迟和已加载旧位置字幕影响下,需要片刻后才会加载到新位置字幕,或关闭视频再次打开(建议)。\n - 此替换文本参数应用于emby-Diagnostics-Parameter Adjustment。\n - 默认参数用于修改ffmpeg中字幕覆盖在视频上的位置。\n - 方案来源于https://opve.cn/archives/983.html', 'style': 'white-space: pre-line;' } } @@ -328,18 +317,17 @@ class DiagParamAdjust(_PluginBase): } ], { "enabled": False, - "offset": True, + "offset_play": True, "onlyonce": False, "search": "x=(W-w)/2:y=(H-h):repeatlast=0", "replace": "x=W/4:y=h/4:repeatlast=0", "cron": "*/5 * * * *", - "cron_switch": True, - "login_play": False + "cron_switch": False, } def detect(self): """ - 检测是否存在目标参数 + 检测是否存在目标参数(修正字幕偏移用途) :return True: 存在; False: 不存在 """ @@ -348,6 +336,7 @@ class DiagParamAdjust(_PluginBase): res = Emby().get_data(self._url) result = res.json() data = result['Object']['CommandLineOptions'] + searchText = data['SearchText'] replaceText = data['ReplaceText'] except json.JSONDecodeError: logger.error('服务停止,Emby请安装【Diagnostics】插件') @@ -358,18 +347,37 @@ class DiagParamAdjust(_PluginBase): return False # 符合所有情况 - if 'repeatlast' in replaceText \ - and 'x=(W-w)/2:y=(H-h):repeatlast=0' in data['SearchText'] \ - and result['Object']['TranscodingOptions']['DisableHardwareSubtitleOverlay'] is True: + if (('repeatlast' in replaceText \ + and 'x=(W-w)/2:y=(H-h):repeatlast=0' in searchText \ + and result['Object']['TranscodingOptions']['DisableHardwareSubtitleOverlay'] is True) \ + or (searchText == "" and replaceText == "")) \ + and self._resolution == self._last_resolution: + # (A or B) and C return True return False def set_options(self): + """ + 向Emby发送请求设置参数 + """ + + # 根据分辨率情况而选择是否替换 + if self._resolution == 0 and self._offset_play is True: + # 1080p,不替换(清空文本) + self._target_search_text = "" + self._target_replace_text = "" + logger.info('清空替换参数') + else: + # >1080p or 非字幕偏移用途 + self._target_search_text = self._search_text + self._target_replace_text = self._replace_text + logger.info("替换值为:{}".format(self._target_replace_text)) + data = { "CommandLineOptions": { - "SearchText": self._search_text, - "ReplaceText": self._replace_text + "SearchText": self._target_search_text, + "ReplaceText": self._target_replace_text }, "TranscodingOptions": { "DisableHardwareSubtitleOverlay": True @@ -390,7 +398,7 @@ class DiagParamAdjust(_PluginBase): @eventmanager.register(EventType.WebhookMessage) def get_msg(self, event: Event): # 消息方式开关 - if not self._enabled or not self._login_play: + if not self._enabled or not self._offset_play: return # 消息获取 @@ -402,11 +410,24 @@ class DiagParamAdjust(_PluginBase): if not self._webhook_actions.get(event_info.event): return + # 根据视频名获得分辨率信息 + item_path = event_info.item_path + video_resolution = re.findall(r"\d{3,4}p", item_path) + video_width = int(video_resolution[0][:-1]) + logger.info('视频分辨率:{}'.format(video_width)) + + self._last_resolution = self._resolution + # 分辨率变化情况 + if video_width > 1080: + # 2160p/4k + self._resolution = 1 + else: + self._resolution = 0 self.run() def run(self): # 字幕偏移修正,则带检测 - if self._offset: + if self._offset_play: state = self.detect() if state: logger.info('参数正常,无需修正')