From 685f3cb7cb9c1bd71b3759e09167adbd14bbc4db Mon Sep 17 00:00:00 2001 From: thsrite Date: Tue, 2 Jul 2024 13:06:28 +0800 Subject: [PATCH] =?UTF-8?q?feat=20Emby=E5=85=83=E6=95=B0=E6=8D=AE=E5=88=B7?= =?UTF-8?q?=E6=96=B0v1.2=20=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96Emby?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E5=AA=92=E4=BD=93=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.json | 3 +- plugins/embymetarefresh/__init__.py | 84 ++++++++++++++++++++--------- 3 files changed, 63 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 908d011..b943ddc 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - 插件彻底卸载 v1.0 - 实时软连接 v1.8 - 订阅规则自动填充 v2.7 -- Emby元数据刷新 v1.1 +- Emby元数据刷新 v1.2 - Emby媒体标签 v1.2 - 热门媒体订阅 v1.7 - [HomePage v1.2](docs%2FHomePage.md) diff --git a/package.json b/package.json index fde1693..865aa8d 100644 --- a/package.json +++ b/package.json @@ -425,11 +425,12 @@ "name": "Emby元数据刷新", "description": "定时刷新Emby媒体库元数据。", "labels": "Emby", - "version": "1.1", + "version": "1.2", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/emby-icon.png", "author": "thsrite", "level": 1, "history": { + "v1.2": "支持获取Emby最新媒体刷新", "v1.1": "添加远程交互命令", "v1.0": "定时刷新Emby媒体库元数据" } diff --git a/plugins/embymetarefresh/__init__.py b/plugins/embymetarefresh/__init__.py index 627a330..1714972 100644 --- a/plugins/embymetarefresh/__init__.py +++ b/plugins/embymetarefresh/__init__.py @@ -23,7 +23,7 @@ class EmbyMetaRefresh(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/emby-icon.png" # 插件版本 - plugin_version = "1.1" + plugin_version = "1.2" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -39,7 +39,8 @@ class EmbyMetaRefresh(_PluginBase): _enabled = False _onlyonce = False _cron = None - _days = None + _num = None + _refresh_type = None _EMBY_HOST = settings.EMBY_HOST _EMBY_APIKEY = settings.EMBY_API_KEY _scheduler: Optional[BackgroundScheduler] = None @@ -52,7 +53,8 @@ class EmbyMetaRefresh(_PluginBase): self._enabled = config.get("enabled") self._onlyonce = config.get("onlyonce") self._cron = config.get("cron") - self._days = config.get("days") or 5 + self._num = config.get("num") or 5 + self._refresh_type = config.get("refresh_type") or "历史记录" if self._EMBY_HOST: if not self._EMBY_HOST.endswith("/"): @@ -104,7 +106,8 @@ class EmbyMetaRefresh(_PluginBase): "onlyonce": self._onlyonce, "cron": self._cron, "enabled": self._enabled, - "days": self._days + "num": self._num, + "refresh_type": self._refresh_type } ) @@ -116,19 +119,31 @@ class EmbyMetaRefresh(_PluginBase): logger.error("未配置Emby媒体服务器") return - # 获取days内入库的媒体 - current_date = datetime.now() - # 计算几天前的日期 - target_date = current_date - timedelta(days=int(self._days)) - transferhistorys = TransferHistoryOper().list_by_date(target_date.strftime('%Y-%m-%d')) - if not transferhistorys: - logger.error(f"{self._days}天内没有媒体库入库记录") - return + if str(self._refresh_type) == "历史记录": + # 获取days内入库的媒体 + current_date = datetime.now() + # 计算几天前的日期 + target_date = current_date - timedelta(days=int(self._num)) + transferhistorys = TransferHistoryOper().list_by_date(target_date.strftime('%Y-%m-%d')) + if not transferhistorys: + logger.error(f"{self._num}天内没有媒体库入库记录") + return - logger.info(f"开始刷新媒体库元数据,最近{self._days}天内入库媒体:{len(transferhistorys)}个") - # 刷新媒体库 - for transferinfo in transferhistorys: - self.__refresh_emby(transferinfo) + logger.info(f"开始刷新媒体库元数据,最近{self._num}天内入库媒体:{len(transferhistorys)}个") + # 刷新媒体库 + for transferinfo in transferhistorys: + self.__refresh_emby(transferinfo) + else: + latest = Emby().get_latest(num=int(self._num)) + if not latest: + logger.error(f"Emby中没有最新媒体") + return + + logger.info(f"开始刷新媒体库元数据,最新媒体:{len(latest)}个") + # 刷新媒体库 + for item in latest: + logger.info(f"开始刷新媒体库元数据,最新媒体:{item.type} {item.title} ({item.subtitle})") + self.__refresh_emby_library_by_id(item.id) logger.info(f"刷新媒体库元数据完成") @eventmanager.register(EventType.PluginAction) @@ -301,7 +316,7 @@ class EmbyMetaRefresh(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 6 + 'md': 4 }, 'content': [ { @@ -317,7 +332,7 @@ class EmbyMetaRefresh(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 6 + 'md': 4 }, 'content': [ { @@ -338,7 +353,7 @@ class EmbyMetaRefresh(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 6 + 'md': 4 }, 'content': [ { @@ -355,14 +370,34 @@ class EmbyMetaRefresh(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 6 + 'md': 4 + }, + 'content': [ + { + 'component': 'VSelect', + 'props': { + 'model': 'refresh_type', + 'label': '刷新方式', + 'items': [ + {'title': '历史记录', 'value': '历史记录'}, + {'title': '最新入库', 'value': '最新入库'}, + ] + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 }, 'content': [ { 'component': 'VTextField', 'props': { - 'model': 'days', - 'label': '最新入库天数' + 'model': 'num', + 'label': '最新入库数量/历史记录天数' } } ] @@ -383,7 +418,7 @@ class EmbyMetaRefresh(_PluginBase): 'props': { 'type': 'info', 'variant': 'tonal', - 'text': '查询入库记录,周期请求媒体服务器元数据刷新接口。注:只支持Emby。' + 'text': '周期请求媒体服务器元数据刷新接口。注:只支持Emby。' } } ] @@ -396,7 +431,8 @@ class EmbyMetaRefresh(_PluginBase): "enabled": False, "onlyonce": False, "cron": "5 1 * * *", - "days": 5 + "refresh_type": "历史记录", + "num": 5 } def get_page(self) -> List[dict]: