fix plugins

This commit is contained in:
jxxghp
2025-06-09 14:40:58 +08:00
parent 1ec1285563
commit b38ca9c653
8 changed files with 138 additions and 145 deletions

View File

@@ -67,7 +67,6 @@ class BangumiColl(_PluginBase):
_group_select_order: list = []
def init_plugin(self, config: dict = None):
self.subscribeoper = SubscribeOper()
# 停止现有任务
self.stop_service()
@@ -108,8 +107,7 @@ class BangumiColl(_PluginBase):
self._scheduler.add_job(
func=self.bangumi_coll,
trigger='date',
run_date=datetime.datetime.now(tz=pytz.timezone(settings.TZ))
+ datetime.timedelta(seconds=3),
run_date=datetime.datetime.now(tz=pytz.timezone(settings.TZ)) + datetime.timedelta(seconds=3),
)
self._scheduler.start()
@@ -275,9 +273,8 @@ class BangumiColl(_PluginBase):
'content': [
{
'component': 'div',
'props': {'innerHTML':
'提示:<strong>剧集组优先级</strong>越靠前优先级越高。'
}
'props': {
'innerHTML': '提示:<strong>剧集组优先级</strong>越靠前优先级越高。'}
}
]
}
@@ -385,9 +382,8 @@ class BangumiColl(_PluginBase):
'content': [
{
'component': 'div',
'props': {'innerHTML':
'注意: 该插件仅会将<strong>公开</strong>的收藏添加到<strong>订阅</strong>。'
}
'props': {
'innerHTML': '注意: 该插件仅会将<strong>公开</strong>的收藏添加到<strong>订阅</strong>。'}
}
]
}
@@ -414,9 +410,8 @@ class BangumiColl(_PluginBase):
'content': [
{
'component': 'div',
'props': {'innerHTML':
'注意: 开启<strong>自动取消订阅并通知</strong>后,已添加的订阅在下一次执行时若不在已选择的<strong>收藏类型</strong>中,将会被取消订阅。'
}
'props': {
'innerHTML': '注意: 开启<strong>自动取消订阅并通知</strong>后,已添加的订阅在下一次执行时若不在已选择的<strong>收藏类型</strong>中,将会被取消订阅。'}
}
]
}
@@ -443,8 +438,8 @@ class BangumiColl(_PluginBase):
'content': [
{
'component': 'div',
'props': {'innerHTML':
'注意: 开启<strong>固定总集数</strong>后,从<a href="https://bangumi.github.io/api/#/%E7%AB%A0%E8%8A%82/getEpisodes" target="_blank"><u>Bangumi API</u></a>获取到总集数将不会因<strong>订阅元数据更新</strong>改变。'
'props': {
'innerHTML': '注意: 开启<strong>固定总集数</strong>后,从<a href="https://bangumi.github.io/api/#/%E7%AB%A0%E8%8A%82/getEpisodes" target="_blank"><u>Bangumi API</u></a>获取到总集数将不会因<strong>订阅元数据更新</strong>改变。'
}
}
]
@@ -551,7 +546,7 @@ class BangumiColl(_PluginBase):
if not self._uid:
logger.error("未设置UID")
return "未设置UID"
msg = ""
try:
res = self.get_bgm_res(addr="UserCollections", id=self._uid)
items = self.parse_collection_items(res)
@@ -582,9 +577,8 @@ class BangumiColl(_PluginBase):
"tags": [tag.get('name') for tag in item['subject'].get('tags', [{}])]
}
for item in data
if item.get("type") in self._collection_type and item['subject'].get('date')\
# 只添加未来30天内放送的条目
and self.is_date_in_range(item['subject'].get('date'), threshold_days=30)[0]
if item.get("type") in self._collection_type and item['subject'].get('date') and self.is_date_in_range(item['subject'].get('date'), threshold_days=30)[0]
}
def manage_subscriptions(self, items: Dict[int, Dict[str, Any]]):
@@ -592,7 +586,7 @@ class BangumiColl(_PluginBase):
# 查询订阅
db_sub = {
i.bangumiid: i.id
for i in self.subscribeoper.list()
for i in SubscribeOper().list()
if i.bangumiid
}
# bangumi 条目
@@ -627,6 +621,7 @@ class BangumiColl(_PluginBase):
"""添加订阅"""
fail_items = {}
subscribeoper = SubscribeOper()
for subid, item in items.items():
if item.get("name_cn"):
meta = MetaInfo(item.get("name_cn"))
@@ -671,6 +666,7 @@ class BangumiColl(_PluginBase):
and not self.is_date_in_range(sub_air_date, mediainfo.release_date)[0]:
# 识别剧集组标志
group_flag: bool = True
season_info = []
if "OVA" in item.get("tags"):
# 季0 处理
if tmdb_info := self.chain.tmdb_info(mediainfo.tmdb_id, mediainfo.type, 0):
@@ -683,7 +679,8 @@ class BangumiColl(_PluginBase):
else:
# 过滤信息不完整和第0季
season_info = [info for info in mediainfo.season_info if info.get("season_number") and info.get("air_date") and info.get("episode_count")]
season_info = [info for info in mediainfo.season_info if
info.get("season_number") and info.get("air_date") and info.get("episode_count")]
# 获取 bangumi 信息
meta = self.get_eps(meta, subid)
# 先通过season_info处理三季及以上的情况, tmdb存在第二季也不能保证不会被合并
@@ -718,13 +715,13 @@ class BangumiColl(_PluginBase):
season_list = []
for info in mediainfo.season_info:
if info.get("season_number") == 0:
season_list.append((len(season_info)+1, len(mediainfo.seasons[1])+info.get("episode_count")))
season_list.append(
(len(season_info) + 1, len(mediainfo.seasons[1]) + info.get("episode_count")))
season_list.append((len(season_info), len(mediainfo.seasons[1])))
# 预匹配剧集组
candidate_groups = (
group for group in mediainfo.episode_groups
if any(
group.get("group_count") == s[0] and
if any(group.get("group_count") == s[0] and
group.get("episode_count") == s[1]
for s in season_list
)
@@ -738,7 +735,8 @@ class BangumiColl(_PluginBase):
else:
mediainfo = self._match_group(air_date, meta, mediainfo)
# 非续作
elif mediainfo.type == MediaType.TV: mediainfo.season = 1
elif mediainfo.type == MediaType.TV:
mediainfo.season = 1
# 检查本地媒体
exist_flag, no_exists = DownloadChain().get_no_exists_info(meta=meta, mediainfo=mediainfo)
if exist_flag:
@@ -751,13 +749,13 @@ class BangumiColl(_PluginBase):
self.update_data(key="exclude", value=subid)
logger.info(f'{mediainfo.title_year} 媒体库中已存在 第 {mediainfo.season}')
continue
sid = self.subscribeoper.list_by_tmdbid(
sid = subscribeoper.list_by_tmdbid(
mediainfo.tmdb_id, mediainfo.season
)
if sid:
logger.info(f"{mediainfo.title_year} 正在订阅中")
if len(sid) == 1:
self.subscribeoper.update(
subscribeoper.update(
sid=sid[0].id, payload={"bangumiid": subid}
)
logger.info(f"{mediainfo.title_year} Bangumi条目id更新成功")
@@ -773,6 +771,7 @@ class BangumiColl(_PluginBase):
"""
将tmdb多季合并的季信息进行拆分
"""
season_data = {}
if tmdb_info := self.chain.tmdb_info(mediainfo.tmdb_id, mediainfo.type, season):
season = 1
air_date = tmdb_info.get("air_date")
@@ -947,10 +946,11 @@ class BangumiColl(_PluginBase):
# 移除订阅
def delete_subscribe(self, del_items: dict[int, int]):
"""删除订阅"""
subscribeoper = SubscribeOper()
for subscribe_id in del_items.keys():
try:
if subscribe := self.subscribeoper.get(subscribe_id):
self.subscribeoper.delete(subscribe_id)
if subscribe := subscribeoper.get(subscribe_id):
subscribeoper.delete(subscribe_id)
SubscribeHelper().sub_done_async(
{"tmdbid": subscribe.tmdbid, "doubanid": subscribe.doubanid}
)
@@ -1030,4 +1030,3 @@ class BangumiColl(_PluginBase):
except Exception as e:
logger.error(f"获取订阅历史失败: {str(e)}")
return set()

View File

@@ -69,8 +69,6 @@ class ContractCheck(_PluginBase):
self.date: datetime = date
# 私有属性
sites = None
siteoper = None
statistic_sites: list = []
contract_infos: list[ContractInfo] = []
_scheduler: Optional[BackgroundScheduler] = None
@@ -87,8 +85,7 @@ class ContractCheck(_PluginBase):
_dashboard_type: str = "brief"
def init_plugin(self, config: dict = None):
self.sites = SitesHelper()
self.siteoper = SiteOper()
# 停止现有任务
self.stop_service()
# 配置
@@ -123,8 +120,7 @@ class ContractCheck(_PluginBase):
self._scheduler.add_job(
self.refresh_all_site_data,
"date",
run_date=datetime.now(tz=pytz.timezone(settings.TZ))
+ timedelta(seconds=3),
run_date=datetime.now(tz=pytz.timezone(settings.TZ)) + timedelta(seconds=3),
)
# 关闭一次性开关
self._onlyonce = False
@@ -162,7 +158,7 @@ class ContractCheck(_PluginBase):
self.statistic_sites.append(site_id)
def _get_site_id(self, name):
all_sites = [site for site in self.siteoper.list_order_by_pri()] + [
all_sites = [site for site in SiteOper().list_order_by_pri()] + [
site for site in self.__custom_sites()
]
for site in all_sites:
@@ -505,9 +501,7 @@ class ContractCheck(_PluginBase):
}
]
def get_dashboard(
self,
) -> Optional[Tuple[Dict[str, Any], Dict[str, Any], List[dict]]]:
def get_dashboard(self, **kwargs) -> Optional[Tuple[Dict[str, Any], Dict[str, Any], List[dict]]]:
"""
获取插件仪表盘页面需要返回1、仪表板col配置字典2、全局配置自动刷新等3、仪表板页面元素配置json含数据
1、col配置参考
@@ -783,7 +777,7 @@ class ContractCheck(_PluginBase):
i = html_text.find("window.location")
if i == -1:
return None
tmp_url = url + html_text[i : html_text.find(";")].replace(
tmp_url = url + html_text[i: html_text.find(";")].replace(
'"', ""
).replace("+", "").replace(" ", "").replace(
"window.location=", ""
@@ -975,7 +969,7 @@ class ContractCheck(_PluginBase):
"""
多线程刷新站点下载上传量默认间隔6小时
"""
if not self.sites.get_indexers():
if not SitesHelper().get_indexers():
return
logger.info("开始刷新站点数据 ...")
@@ -983,7 +977,7 @@ class ContractCheck(_PluginBase):
with lock:
all_sites = [
site for site in self.sites.get_indexers() if not site.get("public")
site for site in SitesHelper().get_indexers() if not site.get("public")
] + self.__custom_sites()
# 没有指定站点,默认使用全部站点
if not self.statistic_sites:

View File

@@ -28,12 +28,11 @@ class CustomIndexer(_PluginBase):
auth_level = 2
# 私有属性
siteshelper = None
_enabled = False
_confstr = ""
def init_plugin(self, config: dict = None):
self.siteshelper = SitesHelper()
# 读取配置
if config:
self._enabled = config.get("enabled")
@@ -49,7 +48,7 @@ class CustomIndexer(_PluginBase):
if not domain or not jsonstr:
continue
jsonstr = base64.b64decode(jsonstr).decode('utf-8')
self.siteshelper.add_indexer(domain, json.loads(jsonstr))
SitesHelper().add_indexer(domain, json.loads(jsonstr))
except Exception as err:
logger.error(f"自定义索引站点配置错误:{err}")
self.systemmessage.put(f"自定义索引站点配置错误:{err}", title="自定义索引站点")

View File

@@ -37,10 +37,8 @@ class DownloadingMsg(_PluginBase):
_seconds = None
_type = None
_adminuser = None
_downloadhis = None
def init_plugin(self, config: dict = None):
self._downloadhis = DownloadHistoryOper()
# 停止现有任务
self.stop_service()
@@ -71,8 +69,9 @@ class DownloadingMsg(_PluginBase):
if self._type == "user" or self._type == "both":
user_torrents = {}
# 根据正在下载种子hash获取下载历史
_downloadhis = DownloadHistoryOper()
for torrent in torrents:
downloadhis = self._downloadhis.get_by_hash(download_hash=torrent.hash)
downloadhis = _downloadhis.get_by_hash(download_hash=torrent.hash)
if not downloadhis:
logger.warn(f"种子 {torrent.hash} 未获取到MoviePilot下载历史无法推送下载进度")
continue
@@ -115,13 +114,14 @@ class DownloadingMsg(_PluginBase):
messages = []
index = 1
channel_value = None
_downloadhis = DownloadHistoryOper()
for torrent in torrents:
year = None
name = None
se = None
ep = None
# 先查询下载记录,没有再识别
downloadhis = self._downloadhis.get_by_hash(download_hash=torrent.hash)
downloadhis = _downloadhis.get_by_hash(download_hash=torrent.hash)
if downloadhis:
name = downloadhis.title
year = downloadhis.year

View File

@@ -23,6 +23,7 @@ from app.utils.common import retry
from app.utils.http import RequestUtils
from app.db.models import PluginData
class ExistMediaInfo(BaseModel):
# 季, 集
groupep: Optional[Dict[int, list]] = {}
@@ -673,8 +674,10 @@ class EpisodeGroupMeta(_PluginBase):
self.log_warn(f"{mediainfo.title_year} 在媒体库 {server} 中没有数据")
continue
else:
self.log_info(f"{mediainfo.title_year} 在媒体库 {existsinfo.server} 中找到了这些季集:{existsinfo.groupep}")
_bool = self.__start_rt_mediaserver(mediainfo=mediainfo, existsinfo=existsinfo, episode_groups=episode_groups, group_id=group_id)
self.log_info(
f"{mediainfo.title_year} 在媒体库 {existsinfo.server} 中找到了这些季集:{existsinfo.groupep}")
_bool = self.__start_rt_mediaserver(mediainfo=mediainfo, existsinfo=existsinfo,
episode_groups=episode_groups, group_id=group_id)
relust_bool = relust_bool or _bool
else:
# v2版本 遍历所有媒体服务器的方式
@@ -696,8 +699,11 @@ class EpisodeGroupMeta(_PluginBase):
self.log_warn(f"{mediainfo.title_year} 在 ({info.type}){name} 媒体服务器中没有数据")
continue
else:
self.log_info(f"{mediainfo.title_year} 在媒体库 ({existsinfo.server_type}){existsinfo.server} 中找到了这些季集:{existsinfo.groupep}")
_bool = self.__start_rt_mediaserver(mediainfo=mediainfo, existsinfo=existsinfo, episode_groups=episode_groups, group_id=group_id, mediaserver_instance=info.instance)
self.log_info(
f"{mediainfo.title_year} 在媒体库 ({existsinfo.server_type}){existsinfo.server} 中找到了这些季集:{existsinfo.groupep}")
_bool = self.__start_rt_mediaserver(mediainfo=mediainfo, existsinfo=existsinfo,
episode_groups=episode_groups, group_id=group_id,
mediaserver_instance=info.instance)
relust_bool = relust_bool or _bool
return relust_bool
@@ -762,7 +768,8 @@ class EpisodeGroupMeta(_PluginBase):
ep_num = ep[_index]
for _id in _ids:
# 获取媒体服务器媒体项
iteminfo = self.get_iteminfo(server_type=existsinfo.server_type, itemid=_id, mediaserver_instance=mediaserver_instance)
iteminfo = self.get_iteminfo(server_type=existsinfo.server_type, itemid=_id,
mediaserver_instance=mediaserver_instance)
if not iteminfo:
self.log_info(f"未找到媒体项 - itemid: {_id}, 第 {order} 季, 第 {ep_num}")
continue
@@ -771,7 +778,8 @@ class EpisodeGroupMeta(_PluginBase):
if iteminfo.get("LockData") or (
"Name" in iteminfo.get("LockedFields", [])
and "Overview" in iteminfo.get("LockedFields", [])):
self.log_warn(f"已锁定媒体项 - itemid: {_id}, 第 {order} 季, 第 {ep_num} 集, 如果需要刮削请打开设置中的“锁定的剧集也刮削”选项")
self.log_warn(
f"已锁定媒体项 - itemid: {_id}, 第 {order} 季, 第 {ep_num} 集, 如果需要刮削请打开设置中的“锁定的剧集也刮削”选项")
continue
# 替换项目数据
episode = episodes[ep_num - 1]
@@ -789,7 +797,8 @@ class EpisodeGroupMeta(_PluginBase):
self.__append_to_list(new_dict["LockedFields"], "Name")
self.__append_to_list(new_dict["LockedFields"], "Overview")
# 更新数据
self.set_iteminfo(server_type=existsinfo.server_type, itemid=_id, iteminfo=new_dict, mediaserver_instance=mediaserver_instance)
self.set_iteminfo(server_type=existsinfo.server_type, itemid=_id, iteminfo=new_dict,
mediaserver_instance=mediaserver_instance)
# still_path 图片
if episode.get("still_path"):
self.set_item_image(server_type=existsinfo.server_type, itemid=_id,
@@ -812,7 +821,8 @@ class EpisodeGroupMeta(_PluginBase):
if item not in list:
list.append(item)
def __media_exists(self, mediainfo: schemas.MediaInfo, server: str, server_type: str, mediaserver_instance: Any = None) -> ExistMediaInfo:
def __media_exists(self, mediainfo: schemas.MediaInfo, server: str, server_type: str,
mediaserver_instance: Any = None) -> ExistMediaInfo:
"""
根据媒体信息返回是否存在于指定媒体服务器中剧集列表与剧集ID列表
:param mediainfo: 媒体信息
@@ -1323,7 +1333,7 @@ class EpisodeGroupMeta(_PluginBase):
self.jellyfin = Jellyfin()
return None
services = self.mediaserver_helper.get_services(type_filter=type_filter)#, name_filters=self._mediaservers)
services = self.mediaserver_helper.get_services(type_filter=type_filter) #, name_filters=self._mediaservers)
if not services:
self.log_warn("获取媒体服务器实例失败,请检查配置")
return None

View File

@@ -9,7 +9,6 @@ from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
from app.chain.download import DownloadChain
from app.chain.search import SearchChain
from app.chain.subscribe import SubscribeChain
from app.core.config import settings
from app.core.event import Event
@@ -49,9 +48,6 @@ class NeoDBSync(_PluginBase):
_scheduler: Optional[BackgroundScheduler] = None
_cache_path: Optional[Path] = None
downloadchain = None
searchchain = None
subscribechain = None
# 配置属性
_enabled: bool = False
@@ -64,9 +60,6 @@ class NeoDBSync(_PluginBase):
_tokens: str = ""
def init_plugin(self, config: dict = None):
self.downloadchain = DownloadChain()
self.searchchain = SearchChain()
self.subscribechain = SubscribeChain()
# 停止现有任务
self.stop_service()
@@ -510,6 +503,8 @@ class NeoDBSync(_PluginBase):
logger.info(f"用户 {username} 没有想看数据")
continue
# 遍历该用户的所有想看条目
downloadchain = DownloadChain()
subscribechain = SubscribeChain()
for result in results:
try:
# Take the url as the unique identifier. For example: /movie/2fEdnxYWozPayayizQmk5M
@@ -539,13 +534,13 @@ class NeoDBSync(_PluginBase):
logger.warn(f'未识别到媒体信息,标题:{title}')
continue
# 查询缺失的媒体信息
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
exist_flag, no_exists = downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
if exist_flag:
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
else:
# 添加订阅
logger.info(f'{mediainfo.title_year} 媒体库中不存在或不完整,添加订阅 ...')
self.subscribechain.add(title=mediainfo.title,
subscribechain.add(title=mediainfo.title,
year=mediainfo.year,
mtype=mediainfo.type,
tmdbid=mediainfo.tmdb_id,

View File

@@ -139,14 +139,12 @@ class RemoveLink(_PluginBase):
_delete_scrap_infos = False
_delete_torrents = False
_delete_history = False
_transferhistory = None
_observer = []
# 监控目录的文件列表
state_set: Dict[str, int] = {}
def init_plugin(self, config: dict = None):
logger.info(f"Hello, RemoveLink! config {config}")
self._transferhistory = TransferHistoryOper()
if config:
self._enabled = config.get("enabled")
self._notify = config.get("notify")
@@ -491,10 +489,11 @@ class RemoveLink(_PluginBase):
if not self._delete_history:
return
# 查找历史记录
transfer_history = self._transferhistory.get_by_src(path)
_transferhistory = TransferHistoryOper()
transfer_history = _transferhistory.get_by_src(path)
if transfer_history:
# 删除历史记录
self._transferhistory.delete(transfer_history.id)
_transferhistory.delete(transfer_history.id)
logger.info(f"删除历史记录:{transfer_history.id}")
def delete_empty_folders(self, path):

View File

@@ -29,9 +29,6 @@ class SiteRefresh(_PluginBase):
# 可使用的用户级别
auth_level = 2
# 私有属性
siteoper: SiteOper = None
# 配置属性
_enabled: bool = False
_notify: bool = False
@@ -42,7 +39,7 @@ class SiteRefresh(_PluginBase):
_siteconf: list = []
def init_plugin(self, config: dict = None):
self.siteoper = SiteOper()
# 配置
if config:
self._enabled = config.get("enabled")
@@ -70,7 +67,7 @@ class SiteRefresh(_PluginBase):
logger.error(f"未获取到site_id")
return
site = self.siteoper.get(site_id)
site = SiteOper().get(site_id)
if not site:
logger.error(f"未获取到site_id {site_id} 对应的站点数据")
return