fix 订阅总集数、开始集数问题
This commit is contained in:
parent
b546bce8b8
commit
2d829208e4
@ -74,7 +74,7 @@ class DoubanSyncChain(ChainBase):
|
|||||||
# 加入缓存
|
# 加入缓存
|
||||||
caches.append(douban_id)
|
caches.append(douban_id)
|
||||||
# 查询缺失的媒体信息
|
# 查询缺失的媒体信息
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(mediainfo=mediainfo)
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{mediainfo.get_title_string()} 媒体库中已存在')
|
logger.info(f'{mediainfo.get_title_string()} 媒体库中已存在')
|
||||||
continue
|
continue
|
||||||
|
@ -322,9 +322,11 @@ class DownloadChain(ChainBase):
|
|||||||
# 返回下载的资源,剩下没下完的
|
# 返回下载的资源,剩下没下完的
|
||||||
return downloaded_list, need_tvs
|
return downloaded_list, need_tvs
|
||||||
|
|
||||||
def get_no_exists_info(self, mediainfo: MediaInfo, no_exists: dict = None) -> Tuple[bool, dict]:
|
def get_no_exists_info(self, meta: MetaBase,
|
||||||
|
mediainfo: MediaInfo, no_exists: dict = None) -> Tuple[bool, dict]:
|
||||||
"""
|
"""
|
||||||
检查媒体库,查询是否存在,对于剧集同时返回不存在的季集信息
|
检查媒体库,查询是否存在,对于剧集同时返回不存在的季集信息
|
||||||
|
:param meta: 元数据
|
||||||
:param mediainfo: 已识别的媒体信息
|
:param mediainfo: 已识别的媒体信息
|
||||||
:param no_exists: 在调用该方法前已经存储的不存在的季集信息,有传入时该函数搜索的内容将会叠加后输出
|
:param no_exists: 在调用该方法前已经存储的不存在的季集信息,有传入时该函数搜索的内容将会叠加后输出
|
||||||
:return: 当前媒体是否缺失,各标题总的季集和缺失的季集
|
:return: 当前媒体是否缺失,各标题总的季集和缺失的季集
|
||||||
@ -333,6 +335,12 @@ class DownloadChain(ChainBase):
|
|||||||
def __append_no_exists(_season: int, _episodes: list, _total: int, _start: int):
|
def __append_no_exists(_season: int, _episodes: list, _total: int, _start: int):
|
||||||
"""
|
"""
|
||||||
添加不存在的季集信息
|
添加不存在的季集信息
|
||||||
|
{tmdbid: [
|
||||||
|
"season": int,
|
||||||
|
"episodes": list,
|
||||||
|
"total_episodes": int,
|
||||||
|
"start_episode": int
|
||||||
|
]}
|
||||||
"""
|
"""
|
||||||
if not no_exists.get(mediainfo.tmdb_id):
|
if not no_exists.get(mediainfo.tmdb_id):
|
||||||
no_exists[mediainfo.tmdb_id] = [
|
no_exists[mediainfo.tmdb_id] = [
|
||||||
@ -378,11 +386,17 @@ class DownloadChain(ChainBase):
|
|||||||
# 所有剧集均缺失
|
# 所有剧集均缺失
|
||||||
for season, episodes in mediainfo.seasons.items():
|
for season, episodes in mediainfo.seasons.items():
|
||||||
# 全季不存在
|
# 全季不存在
|
||||||
|
if meta.get_season_list() \
|
||||||
|
and season not in meta.get_season_list():
|
||||||
|
continue
|
||||||
__append_no_exists(_season=season, _episodes=[], _total=len(episodes), _start=min(episodes))
|
__append_no_exists(_season=season, _episodes=[], _total=len(episodes), _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.get_season_list() \
|
||||||
|
and season not in meta.get_season_list():
|
||||||
|
continue
|
||||||
exist_seasons = exists_tvs.get("seasons")
|
exist_seasons = exists_tvs.get("seasons")
|
||||||
if exist_seasons.get(season):
|
if exist_seasons.get(season):
|
||||||
# 取差集
|
# 取差集
|
||||||
|
@ -89,7 +89,7 @@ class SubscribeChain(ChainBase):
|
|||||||
image=mediainfo.get_message_image(),
|
image=mediainfo.get_message_image(),
|
||||||
userid=userid)
|
userid=userid)
|
||||||
else:
|
else:
|
||||||
logger.error(f'{mediainfo.get_title_string()} 添加订阅成功')
|
logger.error(f'{mediainfo.get_title_string()}{metainfo.get_season_string()} 添加订阅成功')
|
||||||
# 广而告之
|
# 广而告之
|
||||||
self.post_message(title=f"{mediainfo.get_title_string()}{metainfo.get_season_string()} 已添加订阅",
|
self.post_message(title=f"{mediainfo.get_title_string()}{metainfo.get_season_string()} 已添加订阅",
|
||||||
text=f"来自用户:{username or userid}",
|
text=f"来自用户:{username or userid}",
|
||||||
@ -125,7 +125,7 @@ class SubscribeChain(ChainBase):
|
|||||||
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
|
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
|
||||||
continue
|
continue
|
||||||
# 查询缺失的媒体信息
|
# 查询缺失的媒体信息
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(mediainfo=mediainfo)
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{mediainfo.get_title_string()} 媒体库中已存在,完成订阅')
|
logger.info(f'{mediainfo.get_title_string()} 媒体库中已存在,完成订阅')
|
||||||
self.subscribes.delete(subscribe.id)
|
self.subscribes.delete(subscribe.id)
|
||||||
@ -133,6 +133,15 @@ class SubscribeChain(ChainBase):
|
|||||||
self.post_message(title=f'{mediainfo.get_title_string()}{meta.get_season_string()} 已完成订阅',
|
self.post_message(title=f'{mediainfo.get_title_string()}{meta.get_season_string()} 已完成订阅',
|
||||||
image=mediainfo.get_message_image())
|
image=mediainfo.get_message_image())
|
||||||
continue
|
continue
|
||||||
|
# 使用订阅的总集数和开始集数替换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,
|
||||||
|
|
||||||
|
)
|
||||||
# 搜索
|
# 搜索
|
||||||
contexts = self.searchchain.process(meta=meta,
|
contexts = self.searchchain.process(meta=meta,
|
||||||
mediainfo=mediainfo,
|
mediainfo=mediainfo,
|
||||||
@ -212,7 +221,7 @@ class SubscribeChain(ChainBase):
|
|||||||
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
|
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
|
||||||
continue
|
continue
|
||||||
# 查询缺失的媒体信息
|
# 查询缺失的媒体信息
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(mediainfo=mediainfo)
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{mediainfo.get_title_string()} 媒体库中已存在,完成订阅')
|
logger.info(f'{mediainfo.get_title_string()} 媒体库中已存在,完成订阅')
|
||||||
self.subscribes.delete(subscribe.id)
|
self.subscribes.delete(subscribe.id)
|
||||||
@ -220,6 +229,15 @@ class SubscribeChain(ChainBase):
|
|||||||
self.post_message(title=f'{mediainfo.get_title_string()}{meta.get_season_string()} 已完成订阅',
|
self.post_message(title=f'{mediainfo.get_title_string()}{meta.get_season_string()} 已完成订阅',
|
||||||
image=mediainfo.get_message_image())
|
image=mediainfo.get_message_image())
|
||||||
continue
|
continue
|
||||||
|
# 使用订阅的总集数和开始集数替换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,
|
||||||
|
|
||||||
|
)
|
||||||
# 遍历缓存种子
|
# 遍历缓存种子
|
||||||
_match_context = []
|
_match_context = []
|
||||||
for domain, contexts in self._torrents_cache.items():
|
for domain, contexts in self._torrents_cache.items():
|
||||||
@ -253,3 +271,59 @@ class SubscribeChain(ChainBase):
|
|||||||
self.subscribes.update(subscribe.id, {
|
self.subscribes.update(subscribe.id, {
|
||||||
"lack_episode": len(left_episodes)
|
"lack_episode": len(left_episodes)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __get_subscribe_no_exits(no_exists: Dict[int, List[dict]],
|
||||||
|
tmdb_id: int,
|
||||||
|
begin_season: int,
|
||||||
|
total_episode: int,
|
||||||
|
start_episode: int):
|
||||||
|
"""
|
||||||
|
根据订阅开始集数和总结数,结合TMDB信息计算当前订阅的缺失集数
|
||||||
|
:param no_exists: 缺失季集列表
|
||||||
|
:param tmdb_id: TMDB ID
|
||||||
|
:param begin_season: 开始季
|
||||||
|
:param total_episode: 总集数
|
||||||
|
:param start_episode: 开始集数
|
||||||
|
"""
|
||||||
|
# 使用订阅的总集数和开始集数替换no_exists
|
||||||
|
if no_exists \
|
||||||
|
and no_exists.get(tmdb_id) \
|
||||||
|
and (total_episode or start_episode):
|
||||||
|
# 原缺失集列表
|
||||||
|
episode_list = no_exists.get(tmdb_id)[0].get("episodes")
|
||||||
|
if total_episode and start_episode:
|
||||||
|
# 有开始集和总集数
|
||||||
|
episodes = list(range(start_episode, total_episode + 1))
|
||||||
|
no_exists[tmdb_id] = [
|
||||||
|
{
|
||||||
|
"season": begin_season,
|
||||||
|
"episodes": episodes,
|
||||||
|
"total_episodes": total_episode,
|
||||||
|
"start_episode": start_episode
|
||||||
|
}
|
||||||
|
]
|
||||||
|
elif not start_episode:
|
||||||
|
# 有总集数没有开始集
|
||||||
|
episodes = list(range(min(episode_list), total_episode + 1))
|
||||||
|
no_exists[tmdb_id] = [
|
||||||
|
{
|
||||||
|
"season": begin_season,
|
||||||
|
"episodes": episodes,
|
||||||
|
"total_episodes": total_episode,
|
||||||
|
"start_episode": min(episode_list)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
# 有开始集没有总集数
|
||||||
|
episodes = list(range(start_episode, max(episode_list) + 1))
|
||||||
|
no_exists[tmdb_id] = [
|
||||||
|
{
|
||||||
|
"season": begin_season,
|
||||||
|
"episodes": episodes,
|
||||||
|
"total_episodes": max(episode_list),
|
||||||
|
"start_episode": start_episode
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return no_exists
|
||||||
|
@ -21,7 +21,7 @@ class UserMessageChain(ChainBase):
|
|||||||
# 当前页面
|
# 当前页面
|
||||||
_current_page: int = 0
|
_current_page: int = 0
|
||||||
# 当前元数据
|
# 当前元数据
|
||||||
_current_meta: Optional[MetaInfo] = None
|
_current_meta: Optional[MetaBase] = None
|
||||||
# 当前媒体信息
|
# 当前媒体信息
|
||||||
_current_media: Optional[MediaInfo] = None
|
_current_media: Optional[MediaInfo] = None
|
||||||
|
|
||||||
@ -82,9 +82,11 @@ class UserMessageChain(ChainBase):
|
|||||||
mediainfo: MediaInfo = cache_list[int(text) + self._current_page * self._page_size - 1]
|
mediainfo: MediaInfo = cache_list[int(text) + self._current_page * self._page_size - 1]
|
||||||
self._current_media = mediainfo
|
self._current_media = mediainfo
|
||||||
# 查询缺失的媒体信息
|
# 查询缺失的媒体信息
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(mediainfo=self._current_media)
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=self._current_meta,
|
||||||
|
mediainfo=self._current_media)
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
self.post_message(title=f"{self._current_media.get_title_string()} 媒体库中已存在",
|
self.post_message(title=f"{self._current_media.get_title_string()}"
|
||||||
|
f"{self._current_meta.get_season_string()} 媒体库中已存在",
|
||||||
userid=userid)
|
userid=userid)
|
||||||
return
|
return
|
||||||
# 发送缺失的媒体信息
|
# 发送缺失的媒体信息
|
||||||
@ -134,9 +136,11 @@ class UserMessageChain(ChainBase):
|
|||||||
if int(text) == 0:
|
if int(text) == 0:
|
||||||
# 自动选择下载
|
# 自动选择下载
|
||||||
# 查询缺失的媒体信息
|
# 查询缺失的媒体信息
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(mediainfo=self._current_media)
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=self._current_meta,
|
||||||
|
mediainfo=self._current_media)
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
self.post_message(title=f"{self._current_media.get_title_string()} 媒体库中已存在",
|
self.post_message(title=f"{self._current_media.get_title_string()}"
|
||||||
|
f"{self._current_meta.get_season_string()} 媒体库中已存在",
|
||||||
userid=userid)
|
userid=userid)
|
||||||
return
|
return
|
||||||
# 批量下载
|
# 批量下载
|
||||||
|
@ -106,7 +106,7 @@ class Slack:
|
|||||||
"type": "section",
|
"type": "section",
|
||||||
"text": {
|
"text": {
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": f"*{title}*\n{text}"
|
"text": f"*{title}*\n{text or ''}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# 消息图片
|
# 消息图片
|
||||||
|
@ -4,6 +4,7 @@ from unittest import TestCase
|
|||||||
|
|
||||||
from app.chain.download import DownloadChain
|
from app.chain.download import DownloadChain
|
||||||
from app.chain.identify import IdentifyChain
|
from app.chain.identify import IdentifyChain
|
||||||
|
from app.core.metainfo import MetaInfo
|
||||||
|
|
||||||
|
|
||||||
class RecognizeTest(TestCase):
|
class RecognizeTest(TestCase):
|
||||||
@ -16,5 +17,5 @@ class RecognizeTest(TestCase):
|
|||||||
def test_recognize(self):
|
def test_recognize(self):
|
||||||
result = IdentifyChain().process(title="我和我的祖国 2019")
|
result = IdentifyChain().process(title="我和我的祖国 2019")
|
||||||
self.assertEqual(result.media_info.tmdb_id, 612845)
|
self.assertEqual(result.media_info.tmdb_id, 612845)
|
||||||
exists = DownloadChain().get_no_exists_info(result.media_info)
|
exists = DownloadChain().get_no_exists_info(MetaInfo("我和我的祖国 2019"), result.media_info)
|
||||||
self.assertTrue(exists[0])
|
self.assertTrue(exists[0])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user