fix SubscribeReminder v1.2

可选订阅类型、推送类型,随机获取订阅图片
This commit is contained in:
thsrite
2024-10-28 14:33:39 +08:00
parent ca2c33bfea
commit c4c858359a
2 changed files with 93 additions and 23 deletions

View File

@@ -202,12 +202,13 @@
"name": "订阅提醒",
"description": "推送当天订阅更新内容。",
"labels": "订阅",
"version": "1.1",
"version": "1.2",
"icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/subscribe_reminder.png",
"author": "thsrite",
"level": 1,
"v2": true,
"history": {
"v1.2": "可选订阅类型、推送类型,随机获取订阅图片",
"v1.1": "fix icon",
"v1.0": "推送当天订阅更新内容"
}

View File

@@ -1,3 +1,4 @@
import random
from datetime import datetime, timedelta
import pytz
@@ -22,7 +23,7 @@ class SubscribeReminder(_PluginBase):
# 插件图标
plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/subscribe_reminder.png"
# 插件版本
plugin_version = "1.1"
plugin_version = "1.2"
# 插件作者
plugin_author = "thsrite"
# 作者主页
@@ -40,6 +41,8 @@ class SubscribeReminder(_PluginBase):
_time = None
tmdb = None
media = None
_subtype = None
_msgtype = None
subscribe_oper = None
_scheduler: Optional[BackgroundScheduler] = None
@@ -55,6 +58,8 @@ class SubscribeReminder(_PluginBase):
self._enabled = config.get("enabled")
self._onlyonce = config.get("onlyonce")
self._time = config.get("time")
self._subtype = config.get("subtype")
self._msgtype = config.get("msgtype")
if self._enabled or self._onlyonce:
# 周期运行
@@ -93,7 +98,9 @@ class SubscribeReminder(_PluginBase):
self.update_config({
"enabled": self._enabled,
"onlyonce": self._onlyonce,
"time": self._time
"time": self._time,
"subtype": self._subtype,
"msgtype": self._msgtype
})
def __send_notify(self):
@@ -103,7 +110,11 @@ class SubscribeReminder(_PluginBase):
logger.error("当前没有订阅,跳过处理")
return
# 当前日期
if not self._subtype:
logger.error("订阅类型不能为空")
return
# 当前日期
current_date = datetime.now().date().strftime("%Y-%m-%d")
current_tv_subscribe = []
@@ -111,7 +122,7 @@ class SubscribeReminder(_PluginBase):
# 遍历订阅查询tmdb
for subscribe in subscribes:
# 电视剧
if subscribe.type == "电视剧":
if "tv" in self._subtype and subscribe.type == "电视剧":
if not subscribe.tmdbid or not subscribe.season:
continue
@@ -131,11 +142,12 @@ class SubscribeReminder(_PluginBase):
'name': f"{subscribe.name} ({subscribe.year})",
'season': f"S{str(subscribe.season).rjust(2, '0')}",
'episode': f"E{str(episodes[0]).rjust(2, '0')}-E{str(episodes[-1]).rjust(2, '0')}" if len(
episodes) > 1 else f"E{str(episodes[0]).rjust(2, '0')}"
episodes) > 1 else f"E{str(episodes[0]).rjust(2, '0')}",
"image": subscribe.backdrop or subscribe.poster
})
# 电影
else:
if "movie" in self._subtype and subscribe.type == "电影":
if not subscribe.tmdbid:
continue
mediainfo = self.media.recognize_media(tmdbid=subscribe.tmdbid, mtype=MediaType.MOVIE)
@@ -143,24 +155,30 @@ class SubscribeReminder(_PluginBase):
continue
if str(mediainfo.release_date) == current_date:
current_movie_subscribe.append({
'name': f"{subscribe.name} ({subscribe.year})"
'name': f"{subscribe.name} ({subscribe.year})",
"image": subscribe.backdrop or subscribe.poster
})
# 如当前日期匹配到订阅,则发送通知
text = ""
for sub in current_tv_subscribe:
text += sub.get("name") + "\n"
text += sub.get("season") + sub.get("episode") + "\n"
text += "\n"
if "tv" in self._subtype and current_tv_subscribe:
text = ""
for sub in current_tv_subscribe:
text += f"📺︎{sub.get('name')} {sub.get('season')}{sub.get('episode')}\n"
for sub in current_movie_subscribe:
text += sub.get("name") + "\n"
text += "\n"
if text:
self.post_message(mtype=NotificationType.Subscribe,
title=f"{current_date}订阅提醒",
text=text)
if text:
self.post_message(mtype=NotificationType.Subscribe,
title="电视剧更新",
text=text,
image=random.choice(current_tv_subscribe)["image"])
if "movie" in self._subtype and current_movie_subscribe:
text = ""
for sub in current_movie_subscribe:
text += f"📽︎{sub.get('name')}\n"
if text:
self.post_message(mtype=NotificationType.Subscribe,
title="电影更新",
text=text,
image=random.choice(current_movie_subscribe)["image"])
def get_state(self) -> bool:
return self._enabled
@@ -176,6 +194,13 @@ class SubscribeReminder(_PluginBase):
"""
拼装插件配置页面需要返回两块数据1、页面配置2、数据结构
"""
# 编历 NotificationType 枚举,生成消息类型选项
MsgTypeOptions = []
for item in NotificationType:
MsgTypeOptions.append({
"title": item.value,
"value": item.name
})
return [
{
'component': 'VForm',
@@ -187,7 +212,7 @@ class SubscribeReminder(_PluginBase):
'component': 'VCol',
'props': {
'cols': 12,
'md': 6
'md': 4
},
'content': [
{
@@ -203,7 +228,7 @@ class SubscribeReminder(_PluginBase):
'component': 'VCol',
'props': {
'cols': 12,
'md': 6
'md': 4
},
'content': [
{
@@ -224,6 +249,7 @@ class SubscribeReminder(_PluginBase):
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
@@ -236,6 +262,47 @@ class SubscribeReminder(_PluginBase):
}
]
},
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSelect',
'props': {
'multiple': True,
'chips': True,
'model': 'subtype',
'label': '订阅类型',
'items': [
{"title": "电影", "value": "movie"},
{"title": "电视剧", "value": "tv"}
]
}
}
]
},
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSelect',
'props': {
'multiple': False,
'chips': True,
'model': 'msgtype',
'label': '消息类型',
'items': MsgTypeOptions
}
}
]
}
]
},
{
@@ -264,6 +331,8 @@ class SubscribeReminder(_PluginBase):
], {
"enabled": False,
"onlyonce": False,
"subtype": ["movie", "tv"],
"msgtype": "Plugin",
"time": 9,
}