fix #313 检查本地存在时未应用订阅总集数的问题
This commit is contained in:
parent
05a0026ea4
commit
fa6f2c01e0
@ -490,13 +490,15 @@ class DownloadChain(ChainBase):
|
|||||||
|
|
||||||
def get_no_exists_info(self, meta: MetaBase,
|
def get_no_exists_info(self, meta: MetaBase,
|
||||||
mediainfo: MediaInfo,
|
mediainfo: MediaInfo,
|
||||||
no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None
|
no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None,
|
||||||
|
totals: Dict[int, int] = None
|
||||||
) -> Tuple[bool, Dict[int, Dict[int, NotExistMediaInfo]]]:
|
) -> Tuple[bool, Dict[int, Dict[int, NotExistMediaInfo]]]:
|
||||||
"""
|
"""
|
||||||
检查媒体库,查询是否存在,对于剧集同时返回不存在的季集信息
|
检查媒体库,查询是否存在,对于剧集同时返回不存在的季集信息
|
||||||
:param meta: 元数据
|
:param meta: 元数据
|
||||||
:param mediainfo: 已识别的媒体信息
|
:param mediainfo: 已识别的媒体信息
|
||||||
:param no_exists: 在调用该方法前已经存储的不存在的季集信息,有传入时该函数搜索的内容将会叠加后输出
|
:param no_exists: 在调用该方法前已经存储的不存在的季集信息,有传入时该函数搜索的内容将会叠加后输出
|
||||||
|
:param totals: 电视剧每季的总集数
|
||||||
:return: 当前媒体是否缺失,各标题总的季集和缺失的季集
|
:return: 当前媒体是否缺失,各标题总的季集和缺失的季集
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -529,6 +531,10 @@ class DownloadChain(ChainBase):
|
|||||||
|
|
||||||
if not no_exists:
|
if not no_exists:
|
||||||
no_exists = {}
|
no_exists = {}
|
||||||
|
|
||||||
|
if not totals:
|
||||||
|
totals = {}
|
||||||
|
|
||||||
if mediainfo.type == MediaType.MOVIE:
|
if mediainfo.type == MediaType.MOVIE:
|
||||||
# 电影
|
# 电影
|
||||||
itemid = self.mediaserver.get_item_id(mtype=mediainfo.type.value,
|
itemid = self.mediaserver.get_item_id(mtype=mediainfo.type.value,
|
||||||
@ -563,30 +569,42 @@ class DownloadChain(ChainBase):
|
|||||||
if meta.begin_season \
|
if meta.begin_season \
|
||||||
and season not in meta.season_list:
|
and season not in meta.season_list:
|
||||||
continue
|
continue
|
||||||
__append_no_exists(_season=season, _episodes=[], _total=len(episodes), _start=min(episodes))
|
# 总集数
|
||||||
|
total_ep = totals.get(season) or len(episodes)
|
||||||
|
__append_no_exists(_season=season, _episodes=[],
|
||||||
|
_total=total_ep, _start=min(episodes))
|
||||||
return False, no_exists
|
return False, no_exists
|
||||||
else:
|
else:
|
||||||
# 存在一些,检查缺失的季集
|
# 存在一些,检查每季缺失的季集
|
||||||
for season, episodes in mediainfo.seasons.items():
|
for season, episodes in mediainfo.seasons.items():
|
||||||
if meta.begin_season \
|
if meta.begin_season \
|
||||||
and season not in meta.season_list:
|
and season not in meta.season_list:
|
||||||
continue
|
continue
|
||||||
if not episodes:
|
if not episodes:
|
||||||
continue
|
continue
|
||||||
exist_seasons = exists_tvs.seasons
|
# 该季总集数
|
||||||
if exist_seasons.get(season):
|
season_total = totals.get(season) or len(episodes)
|
||||||
# 取差集
|
# 该季已存在的集
|
||||||
lack_episodes = list(set(episodes).difference(set(exist_seasons[season])))
|
exist_episodes = exists_tvs.seasons.get(season)
|
||||||
|
if exist_episodes:
|
||||||
|
# 已存在取差集
|
||||||
|
if totals.get(season):
|
||||||
|
# 按总集数计算缺失集(开始集为TMDB中的最小集)
|
||||||
|
lack_episodes = list(set(range(min(episodes),
|
||||||
|
season_total + 1)).difference(set(exist_episodes)))
|
||||||
|
else:
|
||||||
|
# 按TMDB集数计算缺失集
|
||||||
|
lack_episodes = list(set(episodes).difference(set(exist_episodes)))
|
||||||
if not lack_episodes:
|
if not lack_episodes:
|
||||||
# 全部集存在
|
# 全部集存在
|
||||||
continue
|
continue
|
||||||
# 添加不存在的季集信息
|
# 添加不存在的季集信息
|
||||||
__append_no_exists(_season=season, _episodes=lack_episodes,
|
__append_no_exists(_season=season, _episodes=lack_episodes,
|
||||||
_total=len(episodes), _start=min(episodes))
|
_total=season_total, _start=min(episodes))
|
||||||
else:
|
else:
|
||||||
# 全季不存在
|
# 全季不存在
|
||||||
__append_no_exists(_season=season, _episodes=[],
|
__append_no_exists(_season=season, _episodes=[],
|
||||||
_total=len(episodes), _start=min(episodes))
|
_total=season_total, _start=min(episodes))
|
||||||
# 存在不完整的剧集
|
# 存在不完整的剧集
|
||||||
if no_exists:
|
if no_exists:
|
||||||
logger.debug(f"媒体库中已存在部分剧集,缺失:{no_exists}")
|
logger.debug(f"媒体库中已存在部分剧集,缺失:{no_exists}")
|
||||||
|
@ -219,6 +219,13 @@ class RssChain(ChainBase):
|
|||||||
rss_meta.year = rss_task.year
|
rss_meta.year = rss_task.year
|
||||||
rss_meta.begin_season = rss_task.season
|
rss_meta.begin_season = rss_task.season
|
||||||
rss_meta.type = MediaType(rss_task.type)
|
rss_meta.type = MediaType(rss_task.type)
|
||||||
|
# 每季总集数
|
||||||
|
totals = {}
|
||||||
|
if rss_task.season and rss_task.total_episode:
|
||||||
|
totals = {
|
||||||
|
rss_task.season: rss_task.total_episode
|
||||||
|
}
|
||||||
|
# 检查缺失
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(
|
||||||
meta=rss_meta,
|
meta=rss_meta,
|
||||||
mediainfo=MediaInfo(
|
mediainfo=MediaInfo(
|
||||||
@ -227,6 +234,7 @@ class RssChain(ChainBase):
|
|||||||
tmdb_id=rss_task.tmdbid,
|
tmdb_id=rss_task.tmdbid,
|
||||||
season=rss_task.season
|
season=rss_task.season
|
||||||
),
|
),
|
||||||
|
totals=totals
|
||||||
)
|
)
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{rss_task.name} 媒体库中已存在,完成订阅')
|
logger.info(f'{rss_task.name} 媒体库中已存在,完成订阅')
|
||||||
|
@ -202,8 +202,18 @@ class SubscribeChain(ChainBase):
|
|||||||
|
|
||||||
# 非洗版状态
|
# 非洗版状态
|
||||||
if not subscribe.best_version:
|
if not subscribe.best_version:
|
||||||
|
# 每季总集数
|
||||||
|
totals = {}
|
||||||
|
if subscribe.season and subscribe.total_episode:
|
||||||
|
totals = {
|
||||||
|
subscribe.season: subscribe.total_episode
|
||||||
|
}
|
||||||
# 查询缺失的媒体信息
|
# 查询缺失的媒体信息
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(
|
||||||
|
meta=meta,
|
||||||
|
mediainfo=mediainfo,
|
||||||
|
totals=totals
|
||||||
|
)
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
||||||
self.subscribeoper.delete(subscribe.id)
|
self.subscribeoper.delete(subscribe.id)
|
||||||
@ -394,8 +404,18 @@ class SubscribeChain(ChainBase):
|
|||||||
continue
|
continue
|
||||||
# 非洗版
|
# 非洗版
|
||||||
if not subscribe.best_version:
|
if not subscribe.best_version:
|
||||||
|
# 每季总集数
|
||||||
|
totals = {}
|
||||||
|
if subscribe.season and subscribe.total_episode:
|
||||||
|
totals = {
|
||||||
|
subscribe.season: subscribe.total_episode
|
||||||
|
}
|
||||||
# 查询缺失的媒体信息
|
# 查询缺失的媒体信息
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(
|
||||||
|
meta=meta,
|
||||||
|
mediainfo=mediainfo,
|
||||||
|
totals=totals
|
||||||
|
)
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
logger.info(f'{mediainfo.title_year} 媒体库中已存在,完成订阅')
|
||||||
self.subscribeoper.delete(subscribe.id)
|
self.subscribeoper.delete(subscribe.id)
|
||||||
@ -677,32 +697,38 @@ class SubscribeChain(ChainBase):
|
|||||||
if no_exists \
|
if no_exists \
|
||||||
and no_exists.get(tmdb_id) \
|
and no_exists.get(tmdb_id) \
|
||||||
and (total_episode or start_episode):
|
and (total_episode or start_episode):
|
||||||
|
# 该季原缺失信息
|
||||||
no_exist_season = no_exists.get(tmdb_id).get(begin_season)
|
no_exist_season = no_exists.get(tmdb_id).get(begin_season)
|
||||||
if no_exist_season:
|
if no_exist_season:
|
||||||
# 原季集列表
|
# 原集列表
|
||||||
episode_list = no_exist_season.episodes
|
episode_list = no_exist_season.episodes
|
||||||
# 原总集数
|
# 原总集数
|
||||||
total = no_exist_season.total_episode
|
total = no_exist_season.total_episode
|
||||||
|
# 原开始集数
|
||||||
|
start = no_exist_season.start_episode
|
||||||
|
|
||||||
# 更新剧集列表、开始集数、总集数
|
# 更新剧集列表、开始集数、总集数
|
||||||
if not episode_list and not start_episode:
|
if not episode_list:
|
||||||
# 整季缺失且没有开始集
|
# 整季缺失
|
||||||
episodes = []
|
episodes = []
|
||||||
start_episode = 1
|
start_episode = start_episode or start
|
||||||
total_episode = total_episode or total
|
total_episode = total_episode or total
|
||||||
elif total_episode and start_episode:
|
|
||||||
# 有开始集和总集数
|
|
||||||
episodes = list(range(start_episode, total_episode + 1))
|
|
||||||
elif not start_episode:
|
|
||||||
# 有总集数没有开始集
|
|
||||||
episodes = list(range(min(episode_list or [1]), total_episode + 1))
|
|
||||||
start_episode = min(episode_list or [1])
|
|
||||||
elif not total_episode:
|
|
||||||
# 有开始集没有总集数
|
|
||||||
episodes = list(range(start_episode, max(episode_list or [total]) + 1))
|
|
||||||
total_episode = no_exist_season.total_episode
|
|
||||||
else:
|
else:
|
||||||
return no_exists
|
# 部分缺失
|
||||||
# 处理集合
|
if not start_episode \
|
||||||
|
and not total_episode:
|
||||||
|
# 无需调整
|
||||||
|
return no_exists
|
||||||
|
if not start_episode:
|
||||||
|
# 没有自定义开始集
|
||||||
|
start_episode = start
|
||||||
|
if not total_episode:
|
||||||
|
# 没有自定义总集数
|
||||||
|
total_episode = total
|
||||||
|
# 新的集列表
|
||||||
|
episodes = list(range(start_episode, total_episode + 1))
|
||||||
|
|
||||||
|
# 更新集合
|
||||||
no_exists[tmdb_id][begin_season] = NotExistMediaInfo(
|
no_exists[tmdb_id][begin_season] = NotExistMediaInfo(
|
||||||
season=begin_season,
|
season=begin_season,
|
||||||
episodes=episodes,
|
episodes=episodes,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user