This commit is contained in:
jxxghp
2023-06-13 14:35:02 +08:00
parent 2b9975b9b2
commit 8776e51b22
11 changed files with 60 additions and 49 deletions

View File

@ -36,9 +36,9 @@ async def read_subscribes(
@router.post("/", response_model=schemas.Response)
async def create_subscribe(
*,
subscribe_in: schemas.Subscribe,
_: User = Depends(get_current_active_superuser),
*,
subscribe_in: schemas.Subscribe,
_: User = Depends(get_current_active_superuser),
) -> Any:
"""
新增订阅
@ -49,10 +49,10 @@ async def create_subscribe(
@router.post("/update", response_model=schemas.Subscribe)
async def update_subscribe(
*,
db: Session = Depends(get_db),
subscribe_in: schemas.Subscribe,
_: User = Depends(get_current_active_superuser),
*,
db: Session = Depends(get_db),
subscribe_in: schemas.Subscribe,
_: User = Depends(get_current_active_superuser),
) -> Any:
"""
更新订阅信息
@ -67,6 +67,20 @@ async def update_subscribe(
return subscribe
@router.post("/delete", response_model=schemas.Response)
async def delete_subscribe(
*,
db: Session = Depends(get_db),
subscribe_in: schemas.Subscribe,
_: User = Depends(get_current_active_superuser),
) -> Any:
"""
删除订阅信息
"""
Subscribe.delete(db, subscribe_in.id)
return {"success": True}
@router.post("/seerr", response_model=schemas.Response)
async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
authorization: str = Header(None)):

View File

@ -199,7 +199,7 @@ class DownloadChain(ChainBase):
media = context.media_info
meta = context.meta_info
torrent = context.torrent_info
if media.type == MediaType.MOVIE:
if media.type != MediaType.TV:
continue
item_season = meta.get_season_list()
if meta.get_episode_list():
@ -246,7 +246,7 @@ class DownloadChain(ChainBase):
for context in contexts:
media = context.media_info
meta = context.meta_info
if media.type == MediaType.MOVIE:
if media.type != MediaType.TV:
continue
if media.tmdb_id == need_tmdbid:
if context in downloaded_list:
@ -286,7 +286,7 @@ class DownloadChain(ChainBase):
media = context.media_info
meta = context.meta_info
torrent = context.torrent_info
if media.type == MediaType.MOVIE:
if media.type != MediaType.TV:
continue
if context in downloaded_list:
continue

View File

@ -59,6 +59,8 @@ class SubscribeChain(ChainBase):
self.obtain_image(mediainfo=mediainfo)
# 总集数
if mediainfo.type == MediaType.TV:
if not season:
season = 1
if not kwargs.get('total_episode'):
if not mediainfo.seasons:
# 补充媒体信息
@ -71,7 +73,7 @@ class SubscribeChain(ChainBase):
if not mediainfo.seasons:
logger.error(f"媒体信息中没有季集信息,标题:{title}tmdbid{tmdbid}")
return False
total_episode = len(mediainfo.seasons.get(kwargs.get('season') or 1) or [])
total_episode = len(mediainfo.seasons.get(season) or [])
if not total_episode:
logger.error(f'未获取到总集数,标题:{title}tmdbid{tmdbid}')
return False
@ -81,7 +83,7 @@ class SubscribeChain(ChainBase):
# 添加订阅
state, err_msg = self.subscribes.add(mediainfo, season=season, **kwargs)
if not state:
logger.info(f'{mediainfo.get_title_string()} {err_msg}')
logger.error(f'{mediainfo.get_title_string()} {err_msg}')
# 发回原用户
self.post_message(title=f"{mediainfo.get_title_string()}{metainfo.get_season_string()} "
f"添加订阅失败!",
@ -89,7 +91,7 @@ class SubscribeChain(ChainBase):
image=mediainfo.get_message_image(),
userid=userid)
else:
logger.error(f'{mediainfo.get_title_string()}{metainfo.get_season_string()} 添加订阅成功')
logger.info(f'{mediainfo.get_title_string()}{metainfo.get_season_string()} 添加订阅成功')
# 广而告之
self.post_message(title=f"{mediainfo.get_title_string()}{metainfo.get_season_string()} 已添加订阅",
text=f"评分:{mediainfo.vote_average},来自用户:{username or userid}",
@ -279,7 +281,7 @@ class SubscribeChain(ChainBase):
season = season_info.get('season')
if season == subscribe.season:
left_episodes = season_info.get('episodes')
logger.info(f'{mediainfo.get_title_string()}{season} 未下载完整,'
logger.info(f'{mediainfo.get_title_string()}{season} 未下载完整,'
f'更新缺失集数为{len(left_episodes)} ...')
self.subscribes.update(subscribe.id, {
"lack_episode": len(left_episodes)

View File

@ -290,8 +290,6 @@ class UserMessageChain(ChainBase):
# 合并信息
if mtype:
meta.type = mtype
elif meta.type != MediaType.TV:
meta.type = None
if season_num:
meta.begin_season = season_num
if episode_num:

View File

@ -18,7 +18,7 @@ class MetaBase(object):
# 副标题
subtitle: Optional[str] = None
# 类型 电影、电视剧
type: Optional[MediaType] = None
type: MediaType = MediaType.UNKNOWN
# 识别的中文名
cn_name: Optional[str] = None
# 识别的英文名
@ -231,10 +231,10 @@ class MetaBase(object):
(str(self.begin_season).rjust(2, "0"),
str(self.end_season).rjust(2, "0"))
else:
if self.type == MediaType.MOVIE:
return ""
else:
if self.type == MediaType.TV:
return "S01"
else:
return ""
def get_season(self) -> str:
"""
@ -243,7 +243,7 @@ class MetaBase(object):
if self.begin_season is not None:
return self.get_season_string()
else:
return "S01"
return ""
def get_begin_season_string(self) -> str:
"""
@ -252,10 +252,10 @@ class MetaBase(object):
if self.begin_season is not None:
return "S%s" % str(self.begin_season).rjust(2, "0")
else:
if self.type == MediaType.MOVIE:
return ""
else:
if self.type == MediaType.TV:
return "S01"
else:
return ""
def get_season_seq(self) -> str:
"""
@ -264,20 +264,20 @@ class MetaBase(object):
if self.begin_season is not None:
return str(self.begin_season)
else:
if self.type == MediaType.MOVIE:
return ""
else:
if self.type == MediaType.TV:
return "1"
else:
return ""
def get_season_list(self) -> List[int]:
"""
返回季的数组
"""
if self.begin_season is None:
if self.type == MediaType.MOVIE:
return []
else:
if self.type == MediaType.TV:
return [1]
else:
return []
elif self.end_season is not None:
return [season for season in range(self.begin_season, self.end_season + 1)]
else:
@ -377,9 +377,7 @@ class MetaBase(object):
"""
返回季集字符串
"""
if self.type == MediaType.MOVIE:
return ""
else:
if self.type == MediaType.TV:
seaion = self.get_season_string()
episode = self.get_episode_string()
if seaion and episode:
@ -388,6 +386,8 @@ class MetaBase(object):
return "%s" % seaion
elif episode:
return "%s" % episode
else:
return ""
return ""
def get_resource_type_string(self) -> str:

View File

@ -122,9 +122,6 @@ class MetaVideo(MetaBase):
self.init_subtitle(self.org_string)
if not self._subtitle_flag and self.subtitle:
self.init_subtitle(self.subtitle)
# 没有识别出类型时默认为电影
if not self.type:
self.type = MediaType.MOVIE
# 去掉名字中不需要的干扰字符,过短的纯数字不要
self.cn_name = self.__fix_name(self.cn_name)
self.en_name = StringUtils.str_title(self.__fix_name(self.en_name))

View File

@ -207,7 +207,7 @@ class TorrentHelper:
# 控重的主链是名称、年份、季、集
meta = context.meta_info
media = context.media_info
if media.type != MediaType.MOVIE:
if media.type == MediaType.TV:
media_name = "%s%s" % (media.get_title_string(),
meta.get_season_episode_string())
else:

View File

@ -63,7 +63,7 @@ class FanartModule(_ModuleBase):
@classmethod
@lru_cache(maxsize=256)
def __request_fanart(cls, media_type: MediaType, queryid: str) -> Optional[dict]:
def __request_fanart(cls, media_type: MediaType, queryid: Union[str, int]) -> Optional[dict]:
if media_type == MediaType.MOVIE:
image_url = cls._movie_url % queryid
else:

View File

@ -344,8 +344,8 @@ class FileTransferModule(_ModuleBase):
target_dir = target_dir / meidainfo.type.value / meidainfo.category
# 重命名格式
rename_format = settings.MOVIE_RENAME_FORMAT \
if meidainfo.type == MediaType.MOVIE else settings.TV_RENAME_FORMAT
rename_format = settings.TV_RENAME_FORMAT \
if meidainfo.type == MediaType.TV else settings.MOVIE_RENAME_FORMAT
# 判断是否为蓝光原盘
bluray_flag = self.__is_bluray_dir(in_path)

View File

@ -167,10 +167,10 @@ class TorrentSpider:
})
# 分类条件
if self.category:
if self.mtype == MediaType.MOVIE:
cats = self.category.get("movie") or []
elif self.mtype:
if self.mtype == MediaType.TV:
cats = self.category.get("tv") or []
elif self.mtype == MediaType.MOVIE:
cats = self.category.get("movie") or []
else:
cats = (self.category.get("movie") or []) + (self.category.get("tv") or [])
for cat in cats:

View File

@ -61,7 +61,7 @@ class TheMovieDbModule(_ModuleBase):
info = self.tmdb.get_info(mtype=mtype, tmdbid=tmdbid)
else:
logger.info(f"正在识别 {meta.get_name()} ...")
if meta.type != MediaType.TV and not meta.year:
if meta.type == MediaType.UNKNOWN and not meta.year:
info = self.tmdb.match_multi(meta.get_name())
else:
if meta.type == MediaType.TV:
@ -111,10 +111,10 @@ class TheMovieDbModule(_ModuleBase):
if info:
# 确定二级分类
if info.get('media_type') == MediaType.MOVIE:
cat = self.category.get_movie_category(info)
else:
if info.get('media_type') == MediaType.TV:
cat = self.category.get_tv_category(info)
else:
cat = self.category.get_movie_category(info)
# 赋值TMDB信息并返回
mediainfo = MediaInfo(tmdb_info=info)
mediainfo.set_category(cat)
@ -139,10 +139,10 @@ class TheMovieDbModule(_ModuleBase):
if not meta.get_name():
return []
if not meta.type and not meta.year:
if meta.type == MediaType.UNKNOWN and not meta.year:
results = self.tmdb.search_multiis(meta.get_name())
else:
if not meta.type:
if meta.type == MediaType.UNKNOWN:
results = list(
set(self.tmdb.search_movies(meta.get_name(), meta.year))
.union(set(self.tmdb.search_tv_tmdbinfos(meta.get_name(), meta.year)))