This commit is contained in:
jxxghp 2023-06-11 09:01:25 +08:00
parent cf301f11ad
commit 4061fd21c8
8 changed files with 49 additions and 16 deletions

View File

@ -330,7 +330,7 @@ class DownloadChain(ChainBase):
:return: 当前媒体是否缺失各标题总的季集和缺失的季集
"""
def __append_no_exists(_season: int, _episodes: list, _start: int, _total: int):
def __append_no_exists(_season: int, _episodes: list, _total: int, _start: int):
"""
添加不存在的季集信息
"""
@ -367,6 +367,7 @@ class DownloadChain(ChainBase):
mtype=mediainfo.type,
tmdbid=mediainfo.tmdb_id)
if not mediainfo:
logger.error(f"媒体信息识别失败!")
return False, {}
if not mediainfo.seasons:
logger.error(f"媒体信息中没有季集信息:{mediainfo.get_title_string()}")
@ -377,7 +378,7 @@ class DownloadChain(ChainBase):
# 所有剧集均缺失
for season, episodes in mediainfo.seasons.items():
# 全季不存在
__append_no_exists(season, [], len(episodes), min(episodes))
__append_no_exists(_season=season, _episodes=[], _total=len(episodes), _start=min(episodes))
return False, no_exists
else:
# 存在一些,检查缺失的季集
@ -390,10 +391,12 @@ class DownloadChain(ChainBase):
# 全部集存在
continue
# 添加不存在的季集信息
__append_no_exists(season, episodes, len(episodes), min(episodes))
__append_no_exists(_season=season, _episodes=episodes,
_total=len(episodes), _start=min(episodes))
else:
# 全季不存在
__append_no_exists(season, [], len(episodes), min(episodes))
__append_no_exists(_season=season, _episodes=[],
_total=len(episodes), _start=min(episodes))
# 存在不完整的剧集
if no_exists:
logger.info(f"媒体库中已存在部分剧集,缺失:{no_exists}")

View File

@ -39,6 +39,14 @@ class SearchChain(ChainBase):
if not indexer_sites:
logger.warn('未开启任何有效站点,无法搜索资源')
return []
# 补充媒体信息
if not mediainfo.names:
mediainfo: MediaInfo = self.recognize_media(meta=MetaInfo(title=mediainfo.get_title_string()),
mtype=mediainfo.type,
tmdbid=mediainfo.tmdb_id)
if not mediainfo:
logger.error(f'媒体信息识别失败!')
return []
# 缺失的媒体信息
if no_exists:
# 过滤剧集

View File

@ -57,6 +57,27 @@ class SubscribeChain(ChainBase):
return False
# 更新媒体图片
self.obtain_image(mediainfo=mediainfo)
# 总集数
if mediainfo.type == MediaType.TV:
if not kwargs.get('total_episode'):
if not mediainfo.seasons:
# 补充媒体信息
mediainfo: MediaInfo = self.recognize_media(meta=MetaInfo(title=mediainfo.get_title_string()),
mtype=mediainfo.type,
tmdbid=mediainfo.tmdb_id)
if not mediainfo:
logger.error(f"媒体信息识别失败!")
return False
if not mediainfo.seasons:
logger.error(f"媒体信息中没有季集信息,标题:{title}tmdbid{tmdbid}")
return False
total_episode = len(mediainfo.seasons.get(kwargs.get('season') or 1) or [])
if not total_episode:
logger.error(f'未获取到总集数,标题:{title}tmdbid{tmdbid}')
return False
kwargs.update({
'total_episode': total_episode
})
# 添加订阅
state, err_msg = self.subscribes.add(mediainfo, season=season, **kwargs)
if not state:

View File

@ -287,6 +287,7 @@ class UserMessageChain(ChainBase):
if not medias:
self.post_message(title=f"{meta.get_name()} 没有找到对应的媒体信息!", userid=userid)
return
logger.info(f"搜索到 {len(medias)} 条相关媒体信息")
self._user_cache[userid] = {
'type': action,
'items': medias

View File

@ -31,3 +31,7 @@ class Site(Base):
@staticmethod
def get_by_domain(db: Session, domain: str):
return db.query(Site).filter(Site.domain == domain).first()
@staticmethod
def get_actives(db: Session):
return db.query(Site).filter(Site.is_active is True).all()

View File

@ -31,6 +31,12 @@ class Sites:
"""
return Site.list(self._db)
def list_active(self):
"""
按状态获取站点列表
"""
return Site.get_actives(self._db)
def get_by_domain(self, domain: str) -> Site:
"""
按域名获取站点

View File

@ -5,7 +5,6 @@ from sqlalchemy.orm import Session
from app.core.context import MediaInfo
from app.db import SessionLocal
from app.db.models.subscribe import Subscribe
from app.utils.types import MediaType
class Subscribes:
@ -21,15 +20,6 @@ class Subscribes:
"""
新增订阅
"""
# 总集数
if mediainfo.type == MediaType.TV:
if not kwargs.get('total_episode'):
total_episode = len(mediainfo.seasons.get(kwargs.get('season') or 1) or [])
if not total_episode:
return False, "未识别到总集数"
kwargs.update({
'total_episode': total_episode
})
subscribe = Subscribe(name=mediainfo.title,
year=mediainfo.year,
type=mediainfo.type.value,

View File

@ -61,7 +61,7 @@ class TmdbCache(metaclass=Singleton):
expire = info.get(CACHE_EXPIRE_TIMESTAMP_STR)
if not expire or int(time.time()) < expire:
info[CACHE_EXPIRE_TIMESTAMP_STR] = int(time.time()) + EXPIRE_TIMESTAMP
self.update(meta, info)
self._meta_data[key] = info
elif expire and self._tmdb_cache_expire:
self.delete(key)
return info or {}
@ -136,7 +136,7 @@ class TmdbCache(metaclass=Singleton):
if cache_year:
cache_year = cache_year[:4]
self._meta_data[self.__get_key(meta)] = {
"id": str(info.get("id")),
"id": info.get("id"),
"type": info.get("media_type"),
"year": cache_year,
"title": cache_title,