mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-02-02 18:22:39 +08:00
refactor: 统一将布尔判断 if var: 和 if not var: 更改为显式的 if var is not None: 和 if var is None: 以正确处理 None 值。
This commit is contained in:
@@ -54,7 +54,7 @@ async def exists_local(title: Optional[str] = None,
|
|||||||
判断本地是否存在
|
判断本地是否存在
|
||||||
"""
|
"""
|
||||||
meta = MetaInfo(title)
|
meta = MetaInfo(title)
|
||||||
if not season:
|
if season is None:
|
||||||
season = meta.begin_season
|
season = meta.begin_season
|
||||||
# 返回对象
|
# 返回对象
|
||||||
ret_info = {}
|
ret_info = {}
|
||||||
@@ -83,7 +83,7 @@ def exists(media_in: schemas.MediaInfo,
|
|||||||
existsinfo: schemas.ExistMediaInfo = MediaServerChain().media_exists(mediainfo=mediainfo)
|
existsinfo: schemas.ExistMediaInfo = MediaServerChain().media_exists(mediainfo=mediainfo)
|
||||||
if not existsinfo:
|
if not existsinfo:
|
||||||
return {}
|
return {}
|
||||||
if media_in.season:
|
if media_in.season is not None:
|
||||||
return {
|
return {
|
||||||
media_in.season: existsinfo.seasons.get(media_in.season) or []
|
media_in.season: existsinfo.seasons.get(media_in.season) or []
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ def not_exists(media_in: schemas.MediaInfo,
|
|||||||
mtype = MediaType(media_in.type) if media_in.type else None
|
mtype = MediaType(media_in.type) if media_in.type else None
|
||||||
if mtype:
|
if mtype:
|
||||||
meta.type = mtype
|
meta.type = mtype
|
||||||
if media_in.season:
|
if media_in.season is not None:
|
||||||
meta.begin_season = media_in.season
|
meta.begin_season = media_in.season
|
||||||
meta.type = MediaType.TV
|
meta.type = MediaType.TV
|
||||||
if media_in.year:
|
if media_in.year:
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ class MediaChain(ChainBase):
|
|||||||
org_meta.year = year
|
org_meta.year = year
|
||||||
org_meta.begin_season = season_number
|
org_meta.begin_season = season_number
|
||||||
org_meta.begin_episode = episode_number
|
org_meta.begin_episode = episode_number
|
||||||
if org_meta.begin_season or org_meta.begin_episode:
|
if org_meta.begin_season is not None or org_meta.begin_episode is not None:
|
||||||
org_meta.type = MediaType.TV
|
org_meta.type = MediaType.TV
|
||||||
# 重新识别
|
# 重新识别
|
||||||
return self.recognize_media(meta=org_meta)
|
return self.recognize_media(meta=org_meta)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class SearchChain(ChainBase):
|
|||||||
logger.error(f'{tmdbid} 媒体信息识别失败!')
|
logger.error(f'{tmdbid} 媒体信息识别失败!')
|
||||||
return []
|
return []
|
||||||
no_exists = None
|
no_exists = None
|
||||||
if season:
|
if season is not None:
|
||||||
no_exists = {
|
no_exists = {
|
||||||
tmdbid or doubanid: {
|
tmdbid or doubanid: {
|
||||||
season: NotExistMediaInfo(episodes=[])
|
season: NotExistMediaInfo(episodes=[])
|
||||||
@@ -129,7 +129,7 @@ class SearchChain(ChainBase):
|
|||||||
logger.error(f'{tmdbid} 媒体信息识别失败!')
|
logger.error(f'{tmdbid} 媒体信息识别失败!')
|
||||||
return []
|
return []
|
||||||
no_exists = None
|
no_exists = None
|
||||||
if season:
|
if season is not None:
|
||||||
no_exists = {
|
no_exists = {
|
||||||
tmdbid or doubanid: {
|
tmdbid or doubanid: {
|
||||||
season: NotExistMediaInfo(episodes=[])
|
season: NotExistMediaInfo(episodes=[])
|
||||||
@@ -181,7 +181,7 @@ class SearchChain(ChainBase):
|
|||||||
# 过滤剧集
|
# 过滤剧集
|
||||||
season_episodes = {sea: info.episodes
|
season_episodes = {sea: info.episodes
|
||||||
for sea, info in no_exists[mediakey].items()}
|
for sea, info in no_exists[mediakey].items()}
|
||||||
elif mediainfo.season:
|
elif mediainfo.season is not None:
|
||||||
# 豆瓣只搜索当前季
|
# 豆瓣只搜索当前季
|
||||||
season_episodes = {mediainfo.season: []}
|
season_episodes = {mediainfo.season: []}
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ class SubscribeChain(ChainBase):
|
|||||||
metainfo.year = year
|
metainfo.year = year
|
||||||
if mtype:
|
if mtype:
|
||||||
metainfo.type = mtype
|
metainfo.type = mtype
|
||||||
if season:
|
if season is not None:
|
||||||
metainfo.type = MediaType.TV
|
metainfo.type = MediaType.TV
|
||||||
metainfo.begin_season = season
|
metainfo.begin_season = season
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
@@ -174,7 +174,7 @@ class SubscribeChain(ChainBase):
|
|||||||
# 豆瓣标题处理
|
# 豆瓣标题处理
|
||||||
meta = MetaInfo(mediainfo.title)
|
meta = MetaInfo(mediainfo.title)
|
||||||
mediainfo.title = meta.name
|
mediainfo.title = meta.name
|
||||||
if not season:
|
if season is None:
|
||||||
season = meta.begin_season
|
season = meta.begin_season
|
||||||
|
|
||||||
# 使用名称识别兜底
|
# 使用名称识别兜底
|
||||||
@@ -188,7 +188,7 @@ class SubscribeChain(ChainBase):
|
|||||||
|
|
||||||
# 总集数
|
# 总集数
|
||||||
if mediainfo.type == MediaType.TV:
|
if mediainfo.type == MediaType.TV:
|
||||||
if not season:
|
if season is None:
|
||||||
season = 1
|
season = 1
|
||||||
# 总集数
|
# 总集数
|
||||||
if not kwargs.get('total_episode'):
|
if not kwargs.get('total_episode'):
|
||||||
@@ -321,7 +321,7 @@ class SubscribeChain(ChainBase):
|
|||||||
metainfo.year = year
|
metainfo.year = year
|
||||||
if mtype:
|
if mtype:
|
||||||
metainfo.type = mtype
|
metainfo.type = mtype
|
||||||
if season:
|
if season is not None:
|
||||||
metainfo.type = MediaType.TV
|
metainfo.type = MediaType.TV
|
||||||
metainfo.begin_season = season
|
metainfo.begin_season = season
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
@@ -351,7 +351,7 @@ class SubscribeChain(ChainBase):
|
|||||||
# 豆瓣标题处理
|
# 豆瓣标题处理
|
||||||
meta = MetaInfo(mediainfo.title)
|
meta = MetaInfo(mediainfo.title)
|
||||||
mediainfo.title = meta.name
|
mediainfo.title = meta.name
|
||||||
if not season:
|
if season is None:
|
||||||
season = meta.begin_season
|
season = meta.begin_season
|
||||||
|
|
||||||
# 使用名称识别兜底
|
# 使用名称识别兜底
|
||||||
@@ -365,7 +365,7 @@ class SubscribeChain(ChainBase):
|
|||||||
|
|
||||||
# 总集数
|
# 总集数
|
||||||
if mediainfo.type == MediaType.TV:
|
if mediainfo.type == MediaType.TV:
|
||||||
if not season:
|
if season is None:
|
||||||
season = 1
|
season = 1
|
||||||
# 总集数
|
# 总集数
|
||||||
if not kwargs.get('total_episode'):
|
if not kwargs.get('total_episode'):
|
||||||
@@ -530,7 +530,7 @@ class SubscribeChain(ChainBase):
|
|||||||
# 生成元数据
|
# 生成元数据
|
||||||
meta = MetaInfo(subscribe.name)
|
meta = MetaInfo(subscribe.name)
|
||||||
meta.year = subscribe.year
|
meta.year = subscribe.year
|
||||||
meta.begin_season = subscribe.season or None
|
meta.begin_season = subscribe.season if subscribe.season is not None else None
|
||||||
try:
|
try:
|
||||||
meta.type = MediaType(subscribe.type)
|
meta.type = MediaType(subscribe.type)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|||||||
@@ -465,7 +465,7 @@ class MediaInfo:
|
|||||||
for seainfo in info.get('seasons'):
|
for seainfo in info.get('seasons'):
|
||||||
# 季
|
# 季
|
||||||
season = seainfo.get("season_number")
|
season = seainfo.get("season_number")
|
||||||
if not season:
|
if season is None:
|
||||||
continue
|
continue
|
||||||
# 集
|
# 集
|
||||||
episode_count = seainfo.get("episode_count")
|
episode_count = seainfo.get("episode_count")
|
||||||
@@ -545,9 +545,9 @@ class MediaInfo:
|
|||||||
# 识别标题中的季
|
# 识别标题中的季
|
||||||
meta = MetaInfo(info.get("title"))
|
meta = MetaInfo(info.get("title"))
|
||||||
# 季
|
# 季
|
||||||
if not self.season:
|
if self.season is None:
|
||||||
self.season = meta.begin_season
|
self.season = meta.begin_season
|
||||||
if self.season:
|
if self.season is not None:
|
||||||
self.type = MediaType.TV
|
self.type = MediaType.TV
|
||||||
elif not self.type:
|
elif not self.type:
|
||||||
self.type = MediaType.MOVIE
|
self.type = MediaType.MOVIE
|
||||||
@@ -607,13 +607,13 @@ class MediaInfo:
|
|||||||
# 剧集
|
# 剧集
|
||||||
if self.type == MediaType.TV and not self.seasons:
|
if self.type == MediaType.TV and not self.seasons:
|
||||||
meta = MetaInfo(info.get("title"))
|
meta = MetaInfo(info.get("title"))
|
||||||
season = meta.begin_season or 1
|
season = meta.begin_season if meta.begin_season is not None else 1
|
||||||
episodes_count = info.get("episodes_count")
|
episodes_count = info.get("episodes_count")
|
||||||
if episodes_count:
|
if episodes_count:
|
||||||
self.seasons[season] = list(range(1, episodes_count + 1))
|
self.seasons[season] = list(range(1, episodes_count + 1))
|
||||||
# 季年份
|
# 季年份
|
||||||
if self.type == MediaType.TV and not self.season_years:
|
if self.type == MediaType.TV and not self.season_years:
|
||||||
season = self.season or 1
|
season = self.season if self.season is not None else 1
|
||||||
self.season_years = {
|
self.season_years = {
|
||||||
season: self.year
|
season: self.year
|
||||||
}
|
}
|
||||||
@@ -667,7 +667,7 @@ class MediaInfo:
|
|||||||
# 识别标题中的季
|
# 识别标题中的季
|
||||||
meta = MetaInfo(self.title)
|
meta = MetaInfo(self.title)
|
||||||
# 季
|
# 季
|
||||||
if not self.season:
|
if self.season is None:
|
||||||
self.season = meta.begin_season
|
self.season = meta.begin_season
|
||||||
# 评分
|
# 评分
|
||||||
if not self.vote_average:
|
if not self.vote_average:
|
||||||
@@ -703,7 +703,7 @@ class MediaInfo:
|
|||||||
# 剧集
|
# 剧集
|
||||||
if self.type == MediaType.TV and not self.seasons:
|
if self.type == MediaType.TV and not self.seasons:
|
||||||
meta = MetaInfo(self.title)
|
meta = MetaInfo(self.title)
|
||||||
season = meta.begin_season or 1
|
season = meta.begin_season if meta.begin_season is not None else 1
|
||||||
episodes_count = info.get("total_episodes")
|
episodes_count = info.get("total_episodes")
|
||||||
if episodes_count:
|
if episodes_count:
|
||||||
self.seasons[season] = list(range(1, episodes_count + 1))
|
self.seasons[season] = list(range(1, episodes_count + 1))
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class MediaServerOper(DbOper):
|
|||||||
if not item:
|
if not item:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if kwargs.get("season"):
|
if kwargs.get("season") is not None:
|
||||||
# 判断季是否存在
|
# 判断季是否存在
|
||||||
if not item.seasoninfo:
|
if not item.seasoninfo:
|
||||||
return None
|
return None
|
||||||
@@ -75,7 +75,7 @@ class MediaServerOper(DbOper):
|
|||||||
if not item:
|
if not item:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if kwargs.get("season"):
|
if kwargs.get("season") is not None:
|
||||||
# 判断季是否存在
|
# 判断季是否存在
|
||||||
if not item.seasoninfo:
|
if not item.seasoninfo:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -421,7 +421,7 @@ class Emby:
|
|||||||
if str(tmdb_id) != str(item_info.tmdbid):
|
if str(tmdb_id) != str(item_info.tmdbid):
|
||||||
return None, {}
|
return None, {}
|
||||||
# 查集的信息
|
# 查集的信息
|
||||||
if not season:
|
if season is None:
|
||||||
season = None
|
season = None
|
||||||
try:
|
try:
|
||||||
url = f"{self._host}emby/Shows/{item_id}/Episodes"
|
url = f"{self._host}emby/Shows/{item_id}/Episodes"
|
||||||
@@ -437,12 +437,12 @@ class Emby:
|
|||||||
season_episodes = {}
|
season_episodes = {}
|
||||||
for res_item in res_items:
|
for res_item in res_items:
|
||||||
season_index = res_item.get("ParentIndexNumber")
|
season_index = res_item.get("ParentIndexNumber")
|
||||||
if not season_index:
|
if season_index is None:
|
||||||
continue
|
continue
|
||||||
if season and season != season_index:
|
if season is not None and season != season_index:
|
||||||
continue
|
continue
|
||||||
episode_index = res_item.get("IndexNumber")
|
episode_index = res_item.get("IndexNumber")
|
||||||
if not episode_index:
|
if episode_index is None:
|
||||||
continue
|
continue
|
||||||
if season_index not in season_episodes:
|
if season_index not in season_episodes:
|
||||||
season_episodes[season_index] = []
|
season_episodes[season_index] = []
|
||||||
|
|||||||
@@ -409,7 +409,7 @@ class Jellyfin:
|
|||||||
if tmdb_id and item_info.tmdbid:
|
if tmdb_id and item_info.tmdbid:
|
||||||
if str(tmdb_id) != str(item_info.tmdbid):
|
if str(tmdb_id) != str(item_info.tmdbid):
|
||||||
return None, {}
|
return None, {}
|
||||||
if not season:
|
if season is None:
|
||||||
season = None
|
season = None
|
||||||
url = f"{self._host}Shows/{item_id}/Episodes"
|
url = f"{self._host}Shows/{item_id}/Episodes"
|
||||||
params = {
|
params = {
|
||||||
@@ -427,12 +427,12 @@ class Jellyfin:
|
|||||||
season_episodes = {}
|
season_episodes = {}
|
||||||
for res_item in res_items:
|
for res_item in res_items:
|
||||||
season_index = res_item.get("ParentIndexNumber")
|
season_index = res_item.get("ParentIndexNumber")
|
||||||
if not season_index:
|
if season_index is None:
|
||||||
continue
|
continue
|
||||||
if season and season != season_index:
|
if season is not None and season != season_index:
|
||||||
continue
|
continue
|
||||||
episode_index = res_item.get("IndexNumber")
|
episode_index = res_item.get("IndexNumber")
|
||||||
if not episode_index:
|
if episode_index is None:
|
||||||
continue
|
continue
|
||||||
if not season_episodes.get(season_index):
|
if not season_episodes.get(season_index):
|
||||||
season_episodes[season_index] = []
|
season_episodes[season_index] = []
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ class Plex:
|
|||||||
episodes = videos.episodes()
|
episodes = videos.episodes()
|
||||||
season_episodes = {}
|
season_episodes = {}
|
||||||
for episode in episodes:
|
for episode in episodes:
|
||||||
if season and episode.seasonNumber != int(season):
|
if season is not None and episode.seasonNumber != int(season):
|
||||||
continue
|
continue
|
||||||
if episode.seasonNumber not in season_episodes:
|
if episode.seasonNumber not in season_episodes:
|
||||||
season_episodes[episode.seasonNumber] = []
|
season_episodes[episode.seasonNumber] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user