diff --git a/package.json b/package.json index b233b3f..4cc27bb 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]: