diff --git a/README.md b/README.md index 67acc06..22050c3 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,4 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - Emby元数据刷新 1.1 - Emby媒体标签 1.1 - 热门媒体订阅 1.5 +- [HomePage 1.0](docs%2FHomePage.md) diff --git a/docs/HomePage.md b/docs/HomePage.md new file mode 100644 index 0000000..a7ae5ba --- /dev/null +++ b/docs/HomePage.md @@ -0,0 +1,31 @@ +# HomePage自定义API + +HomePage services.yaml配置 + +```angular2html + - MoviePilot: + icon: /icons/icon/MoviePilot.png + href: http://ip:port + ping: http://ip:port + widget: + type: customapi + url: http://ip:port/api/v1/plugin/HomePage/statistic?apikey=your apikey + method: GET + mappings: + - field: movie_subscribes + label: 电影订阅 + - field: tv_subscribes + label: 电视剧订阅 + - field: movie_count + label: 电影数量 + - field: tv_count + label: 电视剧数量 +``` + +### 自定义API Response + + + + +### HomePage自定义API文档 +https://gethomepage.dev/latest/widgets/services/customapi/#custom-request-body \ No newline at end of file diff --git a/icons/homepage.png b/icons/homepage.png new file mode 100644 index 0000000..aa475b5 Binary files /dev/null and b/icons/homepage.png differ diff --git a/package.json b/package.json index 667b0bd..b391a9a 100644 --- a/package.json +++ b/package.json @@ -421,5 +421,17 @@ "v1.1": "修正流行度校验", "v1.0": "自定添加热门媒体到订阅" } + }, + "HomePage": { + "name": "HomePage", + "description": "HomePage自定义API。", + "labels": "工具", + "version": "1.0", + "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/homepage.png", + "author": "thsrite", + "level": 1, + "history": { + "v1.0": "HomePage自定义API" + } } } diff --git a/plugins/homepage/__init__.py b/plugins/homepage/__init__.py new file mode 100644 index 0000000..6b57cc6 --- /dev/null +++ b/plugins/homepage/__init__.py @@ -0,0 +1,211 @@ +from app.chain.dashboard import DashboardChain +from app.core.config import settings +from app.db.subscribe_oper import SubscribeOper +from app.plugins import _PluginBase +from typing import Any, List, Dict, Tuple, Optional +from app.schemas import NotificationType +from app import schemas +from app.utils.system import SystemUtils + + +class HomePage(_PluginBase): + # 插件名称 + plugin_name = "HomePage" + # 插件描述 + plugin_desc = "HomePage自定义API。" + # 插件图标 + plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/homepage.png" + # 插件版本 + plugin_version = "1.0" + # 插件作者 + plugin_author = "thsrite" + # 作者主页 + author_url = "https://github.com/thsrite" + # 插件配置项ID前缀 + plugin_config_prefix = "homepage_" + # 加载顺序 + plugin_order = 30 + # 可使用的用户级别 + auth_level = 1 + + # 任务执行间隔 + _enabled = False + + def init_plugin(self, config: dict = None): + if config: + self._enabled = config.get("enabled") + + def get_state(self) -> bool: + return self._enabled + + def statistic(self, apikey: str) -> Any: + """ + 订阅、剩余空间等信息 + """ + if apikey != settings.API_TOKEN: + return schemas.Response(success=False, message="API密钥错误") + + # 媒体统计 + movie_count = 0 + tv_count = 0 + episode_count = 0 + user_count = 0 + media_statistics: Optional[List[schemas.Statistic]] = DashboardChain().media_statistic() + if media_statistics: + # 汇总各媒体库统计信息 + for media_statistic in media_statistics: + movie_count += media_statistic.movie_count + tv_count += media_statistic.tv_count + episode_count += media_statistic.episode_count + user_count += media_statistic.user_count + + # 磁盘统计 + total_storage, free_storage = SystemUtils.space_usage(settings.LIBRARY_PATHS) + + # 订阅统计 + movie_subscribes = 0 + tv_subscribes = 0 + subscribes = SubscribeOper().list() + for subscribe in subscribes: + if str(subscribe.type) == '电影': + movie_subscribes += 1 + else: + tv_subscribes += 1 + return schemas.Response(success=True, data={ + 'movie_count': movie_count, + 'tv_count': tv_count, + 'episode_count': episode_count, + 'user_count': user_count, + 'total_storage': total_storage, + 'free_storage': free_storage, + 'movie_subscribes': movie_subscribes, + 'tv_subscribes': tv_subscribes, + }) + + @staticmethod + def get_command() -> List[Dict[str, Any]]: + pass + + def get_api(self) -> List[Dict[str, Any]]: + """ + 获取插件API + [{ + "path": "/xx", + "endpoint": self.xxx, + "methods": ["GET", "POST"], + "summary": "API说明" + }] + """ + return [{ + "path": "/statistic", + "endpoint": self.statistic, + "methods": ["GET"], + "summary": "数据统计", + "description": "订阅数量等统计数量", + }] + + def get_form(self) -> Tuple[List[dict], Dict[str, Any]]: + """ + 拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构 + """ + # 编历 NotificationType 枚举,生成消息类型选项 + MsgTypeOptions = [] + for item in NotificationType: + MsgTypeOptions.append({ + "title": item.value, + "value": item.name + }) + return [ + { + 'component': 'VForm', + 'content': [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'enabled', + 'label': '启用插件', + } + } + ] + }, + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'success', + 'variant': 'tonal' + }, + 'content': [ + { + 'component': 'span', + 'text': '配置教程请参考:' + }, + { + 'component': 'a', + 'props': { + 'href': 'https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/docs/HomePage.md', + 'target': '_blank' + }, + 'text': 'https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/docs/HomePage.md' + } + ] + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'info', + 'variant': 'tonal', + 'text': '如安装完启用插件后,HomePage提示404,重启MoviePilot即可。' + } + } + ] + } + ] + } + ] + } + ], { + "enabled": False, + } + + def get_page(self) -> List[dict]: + pass + + def stop_service(self): + """ + 退出插件 + """ + pass