fix bug
This commit is contained in:
parent
e835feb056
commit
ac3009d58f
@ -176,58 +176,63 @@ class SubscribeChain(ChainBase):
|
|||||||
totals = {
|
totals = {
|
||||||
subscribe.season: subscribe.total_episode
|
subscribe.season: subscribe.total_episode
|
||||||
}
|
}
|
||||||
# 查询缺失的媒体信息
|
# 查询媒体库缺失的媒体信息
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(
|
||||||
meta=meta,
|
meta=meta,
|
||||||
mediainfo=mediainfo,
|
mediainfo=mediainfo,
|
||||||
totals=totals
|
totals=totals
|
||||||
)
|
)
|
||||||
if exist_flag:
|
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
|
||||||
self.subscribeoper.delete(subscribe.id)
|
|
||||||
# 发送通知
|
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
|
||||||
title=f'{mediainfo.title_year} {meta.season} 已完成订阅',
|
|
||||||
image=mediainfo.get_message_image()))
|
|
||||||
continue
|
|
||||||
# 电视剧订阅
|
|
||||||
if meta.type == MediaType.TV:
|
|
||||||
# 使用订阅的总集数和开始集数替换no_exists
|
|
||||||
no_exists = self.__get_subscribe_no_exits(
|
|
||||||
no_exists=no_exists,
|
|
||||||
tmdb_id=mediainfo.tmdb_id,
|
|
||||||
begin_season=meta.begin_season,
|
|
||||||
total_episode=subscribe.total_episode,
|
|
||||||
start_episode=subscribe.start_episode,
|
|
||||||
|
|
||||||
)
|
|
||||||
# 打印缺失集信息
|
|
||||||
if no_exists and no_exists.get(subscribe.tmdbid):
|
|
||||||
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
|
||||||
if no_exists_info:
|
|
||||||
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
|
||||||
else:
|
else:
|
||||||
# 洗版状态
|
# 洗版状态
|
||||||
|
exist_flag = False
|
||||||
if meta.type == MediaType.TV:
|
if meta.type == MediaType.TV:
|
||||||
no_exists = {
|
no_exists = {
|
||||||
subscribe.season: NotExistMediaInfo(
|
subscribe.tmdbid: {
|
||||||
season=subscribe.season,
|
subscribe.season: NotExistMediaInfo(
|
||||||
episodes=[],
|
season=subscribe.season,
|
||||||
total_episode=subscribe.total_episode,
|
episodes=[],
|
||||||
start_episode=subscribe.start_episode or 1)
|
total_episode=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode or 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
no_exists = {}
|
no_exists = {}
|
||||||
|
|
||||||
|
# 已存在
|
||||||
|
if exist_flag:
|
||||||
|
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
||||||
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 电视剧订阅处理缺失集
|
||||||
|
if meta.type == MediaType.TV:
|
||||||
|
# 使用订阅的总集数和开始集数替换no_exists
|
||||||
|
no_exists = self.__get_subscribe_no_exits(
|
||||||
|
no_exists=no_exists,
|
||||||
|
tmdb_id=mediainfo.tmdb_id,
|
||||||
|
begin_season=meta.begin_season,
|
||||||
|
total_episode=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode,
|
||||||
|
|
||||||
|
)
|
||||||
|
# 打印缺失集信息
|
||||||
|
if no_exists and no_exists.get(subscribe.tmdbid):
|
||||||
|
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
||||||
|
if no_exists_info:
|
||||||
|
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
||||||
|
|
||||||
# 站点范围
|
# 站点范围
|
||||||
if subscribe.sites:
|
if subscribe.sites:
|
||||||
sites = json.loads(subscribe.sites)
|
sites = json.loads(subscribe.sites)
|
||||||
else:
|
else:
|
||||||
sites = None
|
sites = None
|
||||||
|
|
||||||
# 优先级过滤规则
|
# 优先级过滤规则
|
||||||
if subscribe.best_version:
|
if subscribe.best_version:
|
||||||
priority_rule = self.systemconfig.get(SystemConfigKey.BestVersionFilterRules)
|
priority_rule = self.systemconfig.get(SystemConfigKey.BestVersionFilterRules)
|
||||||
else:
|
else:
|
||||||
priority_rule = self.systemconfig.get(SystemConfigKey.SubscribeFilterRules)
|
priority_rule = self.systemconfig.get(SystemConfigKey.SubscribeFilterRules)
|
||||||
|
|
||||||
# 默认过滤规则
|
# 默认过滤规则
|
||||||
if subscribe.include or subscribe.exclude:
|
if subscribe.include or subscribe.exclude:
|
||||||
filter_rule = {
|
filter_rule = {
|
||||||
@ -236,6 +241,7 @@ class SubscribeChain(ChainBase):
|
|||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
filter_rule = self.systemconfig.get(SystemConfigKey.DefaultFilterRules)
|
filter_rule = self.systemconfig.get(SystemConfigKey.DefaultFilterRules)
|
||||||
|
|
||||||
# 搜索,同时电视剧会过滤掉不需要的剧集
|
# 搜索,同时电视剧会过滤掉不需要的剧集
|
||||||
contexts = self.searchchain.process(mediainfo=mediainfo,
|
contexts = self.searchchain.process(mediainfo=mediainfo,
|
||||||
keyword=subscribe.keyword,
|
keyword=subscribe.keyword,
|
||||||
@ -247,8 +253,10 @@ class SubscribeChain(ChainBase):
|
|||||||
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
|
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
|
||||||
if meta.type == MediaType.TV:
|
if meta.type == MediaType.TV:
|
||||||
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
||||||
self.__update_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo)
|
self.__update_lack_episodes(lefts=no_exists, subscribe=subscribe,
|
||||||
|
meta=meta, mediainfo=mediainfo)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 过滤
|
# 过滤
|
||||||
matched_contexts = []
|
matched_contexts = []
|
||||||
for context in contexts:
|
for context in contexts:
|
||||||
@ -278,8 +286,10 @@ class SubscribeChain(ChainBase):
|
|||||||
logger.warn(f'订阅 {subscribe.name} 没有符合过滤条件的资源')
|
logger.warn(f'订阅 {subscribe.name} 没有符合过滤条件的资源')
|
||||||
# 非洗版未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
# 非洗版未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
||||||
if meta.type == MediaType.TV and not subscribe.best_version:
|
if meta.type == MediaType.TV and not subscribe.best_version:
|
||||||
self.__update_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo)
|
self.__update_lack_episodes(lefts=no_exists, subscribe=subscribe,
|
||||||
|
meta=meta, mediainfo=mediainfo)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 自动下载
|
# 自动下载
|
||||||
downloads, lefts = self.downloadchain.batch_download(contexts=matched_contexts,
|
downloads, lefts = self.downloadchain.batch_download(contexts=matched_contexts,
|
||||||
no_exists=no_exists)
|
no_exists=no_exists)
|
||||||
@ -299,8 +309,9 @@ class SubscribeChain(ChainBase):
|
|||||||
if meta.type == MediaType.TV and not subscribe.best_version:
|
if meta.type == MediaType.TV and not subscribe.best_version:
|
||||||
# 更新订阅剩余集数和时间
|
# 更新订阅剩余集数和时间
|
||||||
update_date = True if downloads else False
|
update_date = True if downloads else False
|
||||||
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe,
|
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe, meta=meta,
|
||||||
mediainfo=mediainfo, update_date=update_date)
|
mediainfo=mediainfo, update_date=update_date)
|
||||||
|
|
||||||
# 手动触发时发送系统消息
|
# 手动触发时发送系统消息
|
||||||
if manual:
|
if manual:
|
||||||
if sid:
|
if sid:
|
||||||
@ -309,19 +320,19 @@ class SubscribeChain(ChainBase):
|
|||||||
self.message.put('所有订阅搜索完成!')
|
self.message.put('所有订阅搜索完成!')
|
||||||
|
|
||||||
def finish_subscribe_or_not(self, subscribe: Subscribe, meta: MetaInfo,
|
def finish_subscribe_or_not(self, subscribe: Subscribe, meta: MetaInfo,
|
||||||
mediainfo: MediaInfo, downloads: List[Context]):
|
mediainfo: MediaInfo, downloads: List[Context] = None):
|
||||||
"""
|
"""
|
||||||
判断是否应完成订阅
|
判断是否应完成订阅
|
||||||
"""
|
"""
|
||||||
if not subscribe.best_version:
|
if not subscribe.best_version:
|
||||||
# 全部下载完成
|
# 全部下载完成
|
||||||
logger.info(f'{mediainfo.title_year} 下载完成,完成订阅')
|
logger.info(f'{mediainfo.title_year} 完成订阅')
|
||||||
self.subscribeoper.delete(subscribe.id)
|
self.subscribeoper.delete(subscribe.id)
|
||||||
# 发送通知
|
# 发送通知
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
||||||
title=f'{mediainfo.title_year} {meta.season} 已完成订阅',
|
title=f'{mediainfo.title_year} {meta.season} 已完成订阅',
|
||||||
image=mediainfo.get_message_image()))
|
image=mediainfo.get_message_image()))
|
||||||
else:
|
elif downloads:
|
||||||
# 当前下载资源的优先级
|
# 当前下载资源的优先级
|
||||||
priority = max([item.torrent_info.pri_order for item in downloads])
|
priority = max([item.torrent_info.pri_order for item in downloads])
|
||||||
if priority == 100:
|
if priority == 100:
|
||||||
@ -411,46 +422,50 @@ class SubscribeChain(ChainBase):
|
|||||||
mediainfo=mediainfo,
|
mediainfo=mediainfo,
|
||||||
totals=totals
|
totals=totals
|
||||||
)
|
)
|
||||||
if exist_flag:
|
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
|
||||||
self.subscribeoper.delete(subscribe.id)
|
|
||||||
# 发送通知
|
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
|
||||||
title=f'{mediainfo.title_year} {meta.season} 已完成订阅',
|
|
||||||
image=mediainfo.get_message_image()))
|
|
||||||
continue
|
|
||||||
# 电视剧订阅
|
|
||||||
if meta.type == MediaType.TV:
|
|
||||||
# 使用订阅的总集数和开始集数替换no_exists
|
|
||||||
no_exists = self.__get_subscribe_no_exits(
|
|
||||||
no_exists=no_exists,
|
|
||||||
tmdb_id=mediainfo.tmdb_id,
|
|
||||||
begin_season=meta.begin_season,
|
|
||||||
total_episode=subscribe.total_episode,
|
|
||||||
start_episode=subscribe.start_episode,
|
|
||||||
|
|
||||||
)
|
|
||||||
# 打印缺失集信息
|
|
||||||
if no_exists and no_exists.get(subscribe.tmdbid):
|
|
||||||
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
|
||||||
if no_exists_info:
|
|
||||||
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
|
||||||
else:
|
else:
|
||||||
# 洗版
|
# 洗版
|
||||||
|
exist_flag = False
|
||||||
if meta.type == MediaType.TV:
|
if meta.type == MediaType.TV:
|
||||||
no_exists = {
|
no_exists = {
|
||||||
subscribe.season: NotExistMediaInfo(
|
subscribe.tmdbid: {
|
||||||
season=subscribe.season,
|
subscribe.season: NotExistMediaInfo(
|
||||||
episodes=[],
|
season=subscribe.season,
|
||||||
total_episode=subscribe.total_episode,
|
episodes=[],
|
||||||
start_episode=subscribe.start_episode or 1)
|
total_episode=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode or 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
no_exists = {}
|
no_exists = {}
|
||||||
|
|
||||||
|
# 已存在
|
||||||
|
if exist_flag:
|
||||||
|
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
||||||
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 电视剧订阅
|
||||||
|
if meta.type == MediaType.TV:
|
||||||
|
# 使用订阅的总集数和开始集数替换no_exists
|
||||||
|
no_exists = self.__get_subscribe_no_exits(
|
||||||
|
no_exists=no_exists,
|
||||||
|
tmdb_id=mediainfo.tmdb_id,
|
||||||
|
begin_season=meta.begin_season,
|
||||||
|
total_episode=subscribe.total_episode,
|
||||||
|
start_episode=subscribe.start_episode,
|
||||||
|
|
||||||
|
)
|
||||||
|
# 打印缺失集信息
|
||||||
|
if no_exists and no_exists.get(subscribe.tmdbid):
|
||||||
|
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
||||||
|
if no_exists_info:
|
||||||
|
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
||||||
|
|
||||||
# 默认过滤规则
|
# 默认过滤规则
|
||||||
default_filter = self.systemconfig.get(SystemConfigKey.DefaultFilterRules) or {}
|
default_filter = self.systemconfig.get(SystemConfigKey.DefaultFilterRules) or {}
|
||||||
include = subscribe.include or default_filter.get("include")
|
include = subscribe.include or default_filter.get("include")
|
||||||
exclude = subscribe.exclude or default_filter.get("exclude")
|
exclude = subscribe.exclude or default_filter.get("exclude")
|
||||||
|
|
||||||
# 遍历缓存种子
|
# 遍历缓存种子
|
||||||
_match_context = []
|
_match_context = []
|
||||||
for domain, contexts in torrents.items():
|
for domain, contexts in torrents.items():
|
||||||
@ -537,6 +552,7 @@ class SubscribeChain(ChainBase):
|
|||||||
# 匹配成功
|
# 匹配成功
|
||||||
logger.info(f'{mediainfo.title_year} 匹配成功:{torrent_info.title}')
|
logger.info(f'{mediainfo.title_year} 匹配成功:{torrent_info.title}')
|
||||||
_match_context.append(context)
|
_match_context.append(context)
|
||||||
|
|
||||||
# 开始下载
|
# 开始下载
|
||||||
logger.info(f'{mediainfo.title_year} 匹配完成,共匹配到{len(_match_context)}个资源')
|
logger.info(f'{mediainfo.title_year} 匹配完成,共匹配到{len(_match_context)}个资源')
|
||||||
if _match_context:
|
if _match_context:
|
||||||
@ -554,12 +570,13 @@ class SubscribeChain(ChainBase):
|
|||||||
if meta.type == MediaType.TV and not subscribe.best_version:
|
if meta.type == MediaType.TV and not subscribe.best_version:
|
||||||
update_date = True if downloads else False
|
update_date = True if downloads else False
|
||||||
# 未完成下载,计算剩余集数
|
# 未完成下载,计算剩余集数
|
||||||
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe,
|
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe, meta=meta,
|
||||||
mediainfo=mediainfo, update_date=update_date)
|
mediainfo=mediainfo, update_date=update_date)
|
||||||
else:
|
else:
|
||||||
if meta.type == MediaType.TV:
|
if meta.type == MediaType.TV:
|
||||||
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
||||||
self.__update_lack_episodes(lefts=no_exists, subscribe=subscribe, mediainfo=mediainfo)
|
self.__update_lack_episodes(lefts=no_exists, subscribe=subscribe,
|
||||||
|
meta=meta, mediainfo=mediainfo)
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
"""
|
"""
|
||||||
@ -651,31 +668,36 @@ class SubscribeChain(ChainBase):
|
|||||||
|
|
||||||
def __update_lack_episodes(self, lefts: Dict[int, Dict[int, NotExistMediaInfo]],
|
def __update_lack_episodes(self, lefts: Dict[int, Dict[int, NotExistMediaInfo]],
|
||||||
subscribe: Subscribe,
|
subscribe: Subscribe,
|
||||||
|
meta: MetaBase,
|
||||||
mediainfo: MediaInfo,
|
mediainfo: MediaInfo,
|
||||||
update_date: bool = False):
|
update_date: bool = False):
|
||||||
"""
|
"""
|
||||||
更新订阅剩余集数
|
更新订阅剩余集数
|
||||||
"""
|
"""
|
||||||
left_seasons = lefts.get(mediainfo.tmdb_id) or {}
|
left_seasons = lefts.get(mediainfo.tmdb_id)
|
||||||
for season_info in left_seasons.values():
|
if left_seasons:
|
||||||
season = season_info.season
|
for season_info in left_seasons.values():
|
||||||
if season == subscribe.season:
|
season = season_info.season
|
||||||
left_episodes = season_info.episodes
|
if season == subscribe.season:
|
||||||
if not left_episodes:
|
left_episodes = season_info.episodes
|
||||||
lack_episode = season_info.total_episode
|
if not left_episodes:
|
||||||
else:
|
lack_episode = season_info.total_episode
|
||||||
lack_episode = len(left_episodes)
|
else:
|
||||||
logger.info(f'{mediainfo.title_year} 季 {season} 更新缺失集数为{lack_episode} ...')
|
lack_episode = len(left_episodes)
|
||||||
if update_date:
|
logger.info(f'{mediainfo.title_year} 季 {season} 更新缺失集数为{lack_episode} ...')
|
||||||
# 同时更新最后时间
|
if update_date:
|
||||||
self.subscribeoper.update(subscribe.id, {
|
# 同时更新最后时间
|
||||||
"lack_episode": lack_episode,
|
self.subscribeoper.update(subscribe.id, {
|
||||||
"last_update": datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
"lack_episode": lack_episode,
|
||||||
})
|
"last_update": datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||||
else:
|
})
|
||||||
self.subscribeoper.update(subscribe.id, {
|
else:
|
||||||
"lack_episode": lack_episode
|
self.subscribeoper.update(subscribe.id, {
|
||||||
})
|
"lack_episode": lack_episode
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
# 判断是否应完成订阅
|
||||||
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo)
|
||||||
|
|
||||||
def remote_list(self, channel: MessageChannel, userid: Union[str, int] = None):
|
def remote_list(self, channel: MessageChannel, userid: Union[str, int] = None):
|
||||||
"""
|
"""
|
||||||
|
@ -172,6 +172,9 @@ class TMDb(object):
|
|||||||
else:
|
else:
|
||||||
req = self.request(method, url, data, json)
|
req = self.request(method, url, data, json)
|
||||||
|
|
||||||
|
if req is None:
|
||||||
|
raise TMDbException("Failed to establish a new connection: no response from the server.")
|
||||||
|
|
||||||
headers = req.headers
|
headers = req.headers
|
||||||
|
|
||||||
if "X-RateLimit-Remaining" in headers:
|
if "X-RateLimit-Remaining" in headers:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user