From a7fa4ad7a6741c7ef3e3aa410c772e8eafb882b0 Mon Sep 17 00:00:00 2001 From: thsrite Date: Sun, 12 May 2024 10:28:18 +0800 Subject: [PATCH] =?UTF-8?q?feat=20HomePage=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + docs/HomePage.md | 31 +++++ icons/homepage.png | Bin 0 -> 1184 bytes package.json | 12 ++ plugins/homepage/__init__.py | 211 +++++++++++++++++++++++++++++++++++ 5 files changed, 255 insertions(+) create mode 100644 docs/HomePage.md create mode 100644 icons/homepage.png create mode 100644 plugins/homepage/__init__.py 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 0000000000000000000000000000000000000000..aa475b5ff2a2db0f09e96bc6abfdc4f44e065ea6 GIT binary patch literal 1184 zcmV;R1Yi4!P)Px#u24)=MNDaN2x+K4sokN^?JJ$t7jCE^jmWFh?nbBC z3xmgYzUIN)^Am5ZFQ3*Ro7Nqe)Ch317<#zN-}H;c>KbjRFr?dgz~)x6;TxINMy%du zxZ^pe+-@W$Tr0Cc>++w!{E@c?YG0A!>a>NR-)000zp zQchCnZF|-fOK_W!{D6P#kP!EG#Xm~00Rw4L_t(|+U?ujQrb`yhGBjJhBgFn zLJ_c(pcac(kQxd1e`Af|Co7Zy$$mZP%=*q`1fTi#3JE({DrqztjYgx@8y0=LU^1MSHL(x@cKQB4g%S&RiYS&Od{f+>&4M4IUgMRvb zPp0_6R+R-A^wV#qK#u818~1YnDw~0f=cnJFr$IHthK&1}&+8nB=x06zK}0`85=8Vv zf{=cOT@1wZ(?vl*KPZUkhXf)0bVnG7>1RZOh<->A($8p$ftY@#CcJRpei{J=nv2L%xx5`=g_5aZ!MkmsRQj^k`%nSc<_Lj&6F ztU?|R1bIjh;sHU7=Qjp|JSd3pkRZeZf*216f;_)K5aIzrj0XdKfjlG#@qi%4!+{{r zBM3q~Ac*mBAjpG)2oDKDJRpeia3IFx`y2@H_$258kJ~)AUOoys=V{ud*13L2knmW^ zms~1)PwV5?DrfouL9!q5iQL+GD%+n=^z#UVlJ!b~HlF=MwtK1{5+vqFf?|&=9S zkM|Q`po)Ayl%R}FIlF$e9~6|lKVP&nSU>0|ph4n%aoJX74!pMF4)JilMOyKJ}pbU#7JfyDJjj_vMFs-H0AK=S%0&;ENO@q{oa zxgN`PL%{L3s}&ang2eSV99E)X;6W2P9JPAXw)?Q--j9sDmu=o z(FQ@q$2m3H9LQo`$8t& zaB^>EX>4U6ba`-PAZc)PV*mhnoa6Eg2ys>@D9TUE%t_@^00ScnE@KN5BNI!L6ay0= yM1VBIWCJ6!R3OXP)X2ol#2my2%YaCrN-hBE7ZG&wLN%2D0000 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