Skip to content

Commit

Permalink
fix 缺失状态识判
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Nov 13, 2023
1 parent 3b99fb5 commit 612271b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
7 changes: 4 additions & 3 deletions app/api/endpoints/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ def exists(media_in: schemas.MediaInfo,
else:
mediainfo = MediaChain().recognize_by_meta(metainfo=meta)
# 查询缺失信息
if not mediainfo or not mediainfo.tmdb_id:
if not mediainfo:
raise HTTPException(status_code=404, detail="媒体信息不存在")
mediakey = mediainfo.tmdb_id or mediainfo.douban_id
exist_flag, no_exists = DownloadChain().get_no_exists_info(meta=meta, mediainfo=mediainfo)
if mediainfo.type == MediaType.MOVIE:
# 电影已存在时返回空列表,存在时返回空对像列表
return [] if exist_flag else [NotExistMediaInfo()]
elif no_exists and no_exists.get(mediainfo.tmdb_id):
elif no_exists and no_exists.get(mediakey):
# 电视剧返回缺失的剧集
return list(no_exists.get(mediainfo.tmdb_id).values())
return list(no_exists.get(mediakey).values())
return []


Expand Down
4 changes: 2 additions & 2 deletions app/chain/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def __append_no_exists(_season: int, _episodes: list, _total: int, _start: int):
if not episodes:
continue
# 全季不存在
if meta.season_list \
if meta.sea \
and season not in meta.season_list:
continue
# 总集数
Expand All @@ -726,7 +726,7 @@ def __append_no_exists(_season: int, _episodes: list, _total: int, _start: int):
else:
# 存在一些,检查每季缺失的季集
for season, episodes in mediainfo.seasons.items():
if meta.begin_season \
if meta.sea \
and season not in meta.season_list:
continue
if not episodes:
Expand Down
4 changes: 2 additions & 2 deletions app/chain/message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
from typing import Any

from app.chain.download import *
Expand Down Expand Up @@ -110,9 +109,10 @@ def process(self, body: Any, form: Any, args: Any) -> None:
# 发送缺失的媒体信息
if no_exists:
# 发送消息
mediakey = mediainfo.tmdb_id or mediainfo.douban_id
messages = [
f"第 {sea} 季缺失 {StringUtils.str_series(no_exist.episodes) if no_exist.episodes else no_exist.total_episode} 集"
for sea, no_exist in no_exists.get(mediainfo.tmdb_id).items()]
for sea, no_exist in no_exists.get(mediakey).items()]
self.post_message(Notification(channel=channel,
title=f"{mediainfo.title_year}\n" + "\n".join(messages),
userid=userid))
Expand Down
61 changes: 37 additions & 24 deletions app/chain/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def search(self, sid: int = None, state: str = 'N', manual: bool = False):
subscribes = self.subscribeoper.list(state)
# 遍历订阅
for subscribe in subscribes:
mediakey = subscribe.tmdbid or subscribe.doubanid
# 校验当前时间减订阅创建时间是否大于1分钟,否则跳过先,留出编辑订阅的时间
if subscribe.date:
now = datetime.now()
Expand All @@ -198,7 +199,7 @@ def search(self, sid: int = None, state: str = 'N', manual: bool = False):
tmdbid=subscribe.tmdbid,
doubanid=subscribe.doubanid)
if not mediainfo:
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
continue

# 非洗版状态
Expand All @@ -220,7 +221,7 @@ def search(self, sid: int = None, state: str = 'N', manual: bool = False):
exist_flag = False
if meta.type == MediaType.TV:
no_exists = {
subscribe.tmdbid: {
mediakey: {
subscribe.season: NotExistMediaInfo(
season=subscribe.season,
episodes=[],
Expand All @@ -242,15 +243,15 @@ def search(self, sid: int = None, state: str = 'N', manual: bool = False):
# 使用订阅的总集数和开始集数替换no_exists
no_exists = self.__get_subscribe_no_exits(
no_exists=no_exists,
tmdb_id=mediainfo.tmdb_id,
mediakey=mediakey,
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 and no_exists.get(mediakey):
no_exists_info = no_exists.get(mediakey).get(subscribe.season)
if no_exists_info:
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')

Expand Down Expand Up @@ -486,6 +487,7 @@ def match(self, torrents: Dict[str, List[Context]]):
# 遍历订阅
for subscribe in subscribes:
logger.info(f'开始匹配订阅,标题:{subscribe.name} ...')
mediakey = subscribe.tmdbid or subscribe.doubanid
# 生成元数据
meta = MetaInfo(subscribe.name)
meta.year = subscribe.year
Expand All @@ -495,7 +497,7 @@ def match(self, torrents: Dict[str, List[Context]]):
mediainfo: MediaInfo = self.recognize_media(meta=meta, mtype=meta.type,
tmdbid=subscribe.tmdbid, doubanid=subscribe.doubanid)
if not mediainfo:
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
continue
# 非洗版
if not subscribe.best_version:
Expand All @@ -516,7 +518,7 @@ def match(self, torrents: Dict[str, List[Context]]):
exist_flag = False
if meta.type == MediaType.TV:
no_exists = {
subscribe.tmdbid: {
mediakey: {
subscribe.season: NotExistMediaInfo(
season=subscribe.season,
episodes=[],
Expand All @@ -538,15 +540,15 @@ def match(self, torrents: Dict[str, List[Context]]):
# 使用订阅的总集数和开始集数替换no_exists
no_exists = self.__get_subscribe_no_exits(
no_exists=no_exists,
tmdb_id=mediainfo.tmdb_id,
mediakey=mediakey,
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 and no_exists.get(mediakey):
no_exists_info = no_exists.get(mediakey).get(subscribe.season)
if no_exists_info:
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')

Expand Down Expand Up @@ -601,9 +603,9 @@ def match(self, torrents: Dict[str, List[Context]]):
# 非洗版
if not subscribe.best_version:
# 不是缺失的剧集不要
if no_exists and no_exists.get(subscribe.tmdbid):
if no_exists and no_exists.get(mediakey):
# 缺失集
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
no_exists_info = no_exists.get(mediakey).get(subscribe.season)
if no_exists_info:
# 是否有交集
if no_exists_info.episodes and \
Expand Down Expand Up @@ -682,7 +684,7 @@ def check(self):
mediainfo: MediaInfo = self.recognize_media(meta=meta, mtype=meta.type,
tmdbid=subscribe.tmdbid, doubanid=subscribe.doubanid)
if not mediainfo:
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
continue
# 对于电视剧,获取当前季的总集数
episodes = mediainfo.seasons.get(subscribe.season) or []
Expand Down Expand Up @@ -724,7 +726,11 @@ def __update_subscribe_note(self, subscribe: Subscribe, downloads: List[Context]
mediainfo = context.media_info
if mediainfo.type != MediaType.TV:
continue
if mediainfo.tmdb_id != subscribe.tmdbid:
if subscribe.tmdbid and mediainfo.tmdb_id \
and mediainfo.tmdb_id != subscribe.tmdbid:
continue
if subscribe.doubanid and mediainfo.douban_id \
and mediainfo.douban_id != subscribe.doubanid:
continue
episodes = meta.episode_list
if not episodes:
Expand Down Expand Up @@ -758,7 +764,8 @@ def __update_lack_episodes(self, lefts: Dict[int, Dict[int, NotExistMediaInfo]],
"""
更新订阅剩余集数
"""
left_seasons = lefts.get(mediainfo.tmdb_id)
mediakey = subscribe.tmdbid or subscribe.doubanid
left_seasons = lefts.get(mediakey)
if left_seasons:
for season_info in left_seasons.values():
season = season_info.season
Expand Down Expand Up @@ -799,11 +806,17 @@ def remote_list(self, channel: MessageChannel, userid: Union[str, int] = None):
messages = []
for subscribe in subscribes:
if subscribe.type == MediaType.MOVIE.value:
tmdb_link = f"https://www.themoviedb.org/movie/{subscribe.tmdbid}"
messages.append(f"{subscribe.id}. [{subscribe.name}{subscribe.year})]({tmdb_link})")
if subscribe.tmdbid:
link = f"https://www.themoviedb.org/movie/{subscribe.tmdbid}"
else:
link = f"https://movie.douban.com/subject/{subscribe.doubanid}"
messages.append(f"{subscribe.id}. [{subscribe.name}{subscribe.year})]({link})")
else:
tmdb_link = f"https://www.themoviedb.org/tv/{subscribe.tmdbid}"
messages.append(f"{subscribe.id}. [{subscribe.name}{subscribe.year})]({tmdb_link}) "
if subscribe.tmdbid:
link = f"https://www.themoviedb.org/tv/{subscribe.tmdbid}"
else:
link = f"https://movie.douban.com/subject/{subscribe.doubanid}"
messages.append(f"{subscribe.id}. [{subscribe.name}{subscribe.year})]({link}) "
f"第{subscribe.season}季 "
f"_{subscribe.total_episode - (subscribe.lack_episode or subscribe.total_episode)}"
f"/{subscribe.total_episode}_")
Expand Down Expand Up @@ -838,24 +851,24 @@ def remote_delete(self, arg_str: str, channel: MessageChannel, userid: Union[str

@staticmethod
def __get_subscribe_no_exits(no_exists: Dict[int, Dict[int, NotExistMediaInfo]],
tmdb_id: int,
mediakey: Union[str, int],
begin_season: int,
total_episode: int,
start_episode: int):
"""
根据订阅开始集数和总集数,结合TMDB信息计算当前订阅的缺失集数
:param no_exists: 缺失季集列表
:param tmdb_id: TMDB ID
:param mediakey: TMDB ID或豆瓣ID
:param begin_season: 开始季
:param total_episode: 订阅设定总集数
:param start_episode: 订阅设定开始集数
"""
# 使用订阅的总集数和开始集数替换no_exists
if no_exists \
and no_exists.get(tmdb_id) \
and no_exists.get(mediakey) \
and (total_episode or start_episode):
# 该季原缺失信息
no_exist_season = no_exists.get(tmdb_id).get(begin_season)
no_exist_season = no_exists.get(mediakey).get(begin_season)
if no_exist_season:
# 原集列表
episode_list = no_exist_season.episodes
Expand Down Expand Up @@ -887,7 +900,7 @@ def __get_subscribe_no_exits(no_exists: Dict[int, Dict[int, NotExistMediaInfo]],
# 与原集列表取交集
episodes = list(set(episode_list).intersection(set(new_episodes)))
# 更新集合
no_exists[tmdb_id][begin_season] = NotExistMediaInfo(
no_exists[mediakey][begin_season] = NotExistMediaInfo(
season=begin_season,
episodes=episodes,
total_episode=total_episode,
Expand Down

0 comments on commit 612271b

Please sign in to comment.