fix: 统一了数据库查询中 season 参数的非空判断逻辑,以正确处理 season=0 的情况。

This commit is contained in:
jxxghp
2026-02-02 14:23:51 +08:00
parent d469c2d3f9
commit 17773913ae
5 changed files with 19 additions and 19 deletions
+4 -4
View File
@@ -104,14 +104,14 @@ class DownloadHistory(Base):
# TMDBID + 类型 # TMDBID + 类型
if tmdbid and mtype: if tmdbid and mtype:
# 电视剧某季某集 # 电视剧某季某集
if season and episode: if season is not None and episode:
return db.query(DownloadHistory).filter(DownloadHistory.tmdbid == tmdbid, return db.query(DownloadHistory).filter(DownloadHistory.tmdbid == tmdbid,
DownloadHistory.type == mtype, DownloadHistory.type == mtype,
DownloadHistory.seasons == season, DownloadHistory.seasons == season,
DownloadHistory.episodes == episode).order_by( DownloadHistory.episodes == episode).order_by(
DownloadHistory.id.desc()).all() DownloadHistory.id.desc()).all()
# 电视剧某季 # 电视剧某季
elif season: elif season is not None:
return db.query(DownloadHistory).filter(DownloadHistory.tmdbid == tmdbid, return db.query(DownloadHistory).filter(DownloadHistory.tmdbid == tmdbid,
DownloadHistory.type == mtype, DownloadHistory.type == mtype,
DownloadHistory.seasons == season).order_by( DownloadHistory.seasons == season).order_by(
@@ -124,14 +124,14 @@ class DownloadHistory(Base):
# 标题 + 年份 # 标题 + 年份
elif title and year: elif title and year:
# 电视剧某季某集 # 电视剧某季某集
if season and episode: if season is not None and episode:
return db.query(DownloadHistory).filter(DownloadHistory.title == title, return db.query(DownloadHistory).filter(DownloadHistory.title == title,
DownloadHistory.year == year, DownloadHistory.year == year,
DownloadHistory.seasons == season, DownloadHistory.seasons == season,
DownloadHistory.episodes == episode).order_by( DownloadHistory.episodes == episode).order_by(
DownloadHistory.id.desc()).all() DownloadHistory.id.desc()).all()
# 电视剧某季 # 电视剧某季
elif season: elif season is not None:
return db.query(DownloadHistory).filter(DownloadHistory.title == title, return db.query(DownloadHistory).filter(DownloadHistory.title == title,
DownloadHistory.year == year, DownloadHistory.year == year,
DownloadHistory.seasons == season).order_by( DownloadHistory.seasons == season).order_by(
+6 -6
View File
@@ -93,7 +93,7 @@ class Subscribe(Base):
def exists(cls, db: Session, tmdbid: Optional[int] = None, doubanid: Optional[str] = None, def exists(cls, db: Session, tmdbid: Optional[int] = None, doubanid: Optional[str] = None,
season: Optional[int] = None): season: Optional[int] = None):
if tmdbid: if tmdbid:
if season: if season is not None:
return db.query(cls).filter(cls.tmdbid == tmdbid, return db.query(cls).filter(cls.tmdbid == tmdbid,
cls.season == season).first() cls.season == season).first()
return db.query(cls).filter(cls.tmdbid == tmdbid).first() return db.query(cls).filter(cls.tmdbid == tmdbid).first()
@@ -106,7 +106,7 @@ class Subscribe(Base):
async def async_exists(cls, db: AsyncSession, tmdbid: Optional[int] = None, doubanid: Optional[str] = None, async def async_exists(cls, db: AsyncSession, tmdbid: Optional[int] = None, doubanid: Optional[str] = None,
season: Optional[int] = None): season: Optional[int] = None):
if tmdbid: if tmdbid:
if season: if season is not None:
result = await db.execute( result = await db.execute(
select(cls).filter(cls.tmdbid == tmdbid, cls.season == season) select(cls).filter(cls.tmdbid == tmdbid, cls.season == season)
) )
@@ -148,7 +148,7 @@ class Subscribe(Base):
@classmethod @classmethod
@db_query @db_query
def get_by_title(cls, db: Session, title: str, season: Optional[int] = None): def get_by_title(cls, db: Session, title: str, season: Optional[int] = None):
if season: if season is not None:
return db.query(cls).filter(cls.name == title, return db.query(cls).filter(cls.name == title,
cls.season == season).first() cls.season == season).first()
return db.query(cls).filter(cls.name == title).first() return db.query(cls).filter(cls.name == title).first()
@@ -156,7 +156,7 @@ class Subscribe(Base):
@classmethod @classmethod
@async_db_query @async_db_query
async def async_get_by_title(cls, db: AsyncSession, title: str, season: Optional[int] = None): async def async_get_by_title(cls, db: AsyncSession, title: str, season: Optional[int] = None):
if season: if season is not None:
result = await db.execute( result = await db.execute(
select(cls).filter(cls.name == title, cls.season == season) select(cls).filter(cls.name == title, cls.season == season)
) )
@@ -169,7 +169,7 @@ class Subscribe(Base):
@classmethod @classmethod
@db_query @db_query
def get_by_tmdbid(cls, db: Session, tmdbid: int, season: Optional[int] = None): def get_by_tmdbid(cls, db: Session, tmdbid: int, season: Optional[int] = None):
if season: if season is not None:
return db.query(cls).filter(cls.tmdbid == tmdbid, return db.query(cls).filter(cls.tmdbid == tmdbid,
cls.season == season).all() cls.season == season).all()
else: else:
@@ -178,7 +178,7 @@ class Subscribe(Base):
@classmethod @classmethod
@async_db_query @async_db_query
async def async_get_by_tmdbid(cls, db: AsyncSession, tmdbid: int, season: Optional[int] = None): async def async_get_by_tmdbid(cls, db: AsyncSession, tmdbid: int, season: Optional[int] = None):
if season: if season is not None:
result = await db.execute( result = await db.execute(
select(cls).filter(cls.tmdbid == tmdbid, cls.season == season) select(cls).filter(cls.tmdbid == tmdbid, cls.season == season)
) )
+2 -2
View File
@@ -99,7 +99,7 @@ class SubscribeHistory(Base):
def exists(cls, db: Session, tmdbid: Optional[int] = None, doubanid: Optional[str] = None, def exists(cls, db: Session, tmdbid: Optional[int] = None, doubanid: Optional[str] = None,
season: Optional[int] = None): season: Optional[int] = None):
if tmdbid: if tmdbid:
if season: if season is not None:
return db.query(cls).filter(cls.tmdbid == tmdbid, return db.query(cls).filter(cls.tmdbid == tmdbid,
cls.season == season).first() cls.season == season).first()
return db.query(cls).filter(cls.tmdbid == tmdbid).first() return db.query(cls).filter(cls.tmdbid == tmdbid).first()
@@ -112,7 +112,7 @@ class SubscribeHistory(Base):
async def async_exists(cls, db: AsyncSession, tmdbid: Optional[int] = None, doubanid: Optional[str] = None, async def async_exists(cls, db: AsyncSession, tmdbid: Optional[int] = None, doubanid: Optional[str] = None,
season: Optional[int] = None): season: Optional[int] = None):
if tmdbid: if tmdbid:
if season: if season is not None:
result = await db.execute( result = await db.execute(
select(cls).filter(cls.tmdbid == tmdbid, cls.season == season) select(cls).filter(cls.tmdbid == tmdbid, cls.season == season)
) )
+5 -5
View File
@@ -266,14 +266,14 @@ class TransferHistory(Base):
# TMDBID + 类型 # TMDBID + 类型
if tmdbid and mtype: if tmdbid and mtype:
# 电视剧某季某集 # 电视剧某季某集
if season and episode: if season is not None and episode:
return db.query(cls).filter(cls.tmdbid == tmdbid, return db.query(cls).filter(cls.tmdbid == tmdbid,
cls.type == mtype, cls.type == mtype,
cls.seasons == season, cls.seasons == season,
cls.episodes == episode, cls.episodes == episode,
cls.dest == dest).all() cls.dest == dest).all()
# 电视剧某季 # 电视剧某季
elif season: elif season is not None:
return db.query(cls).filter(cls.tmdbid == tmdbid, return db.query(cls).filter(cls.tmdbid == tmdbid,
cls.type == mtype, cls.type == mtype,
cls.seasons == season).all() cls.seasons == season).all()
@@ -290,14 +290,14 @@ class TransferHistory(Base):
# 标题 + 年份 # 标题 + 年份
elif title and year: elif title and year:
# 电视剧某季某集 # 电视剧某季某集
if season and episode: if season is not None and episode:
return db.query(cls).filter(cls.title == title, return db.query(cls).filter(cls.title == title,
cls.year == year, cls.year == year,
cls.seasons == season, cls.seasons == season,
cls.episodes == episode, cls.episodes == episode,
cls.dest == dest).all() cls.dest == dest).all()
# 电视剧某季 # 电视剧某季
elif season: elif season is not None:
return db.query(cls).filter(cls.title == title, return db.query(cls).filter(cls.title == title,
cls.year == year, cls.year == year,
cls.seasons == season).all() cls.seasons == season).all()
@@ -312,7 +312,7 @@ class TransferHistory(Base):
return db.query(cls).filter(cls.title == title, return db.query(cls).filter(cls.title == title,
cls.year == year).all() cls.year == year).all()
# 类型 + 转移路径(emby webhook season无tmdbid场景) # 类型 + 转移路径(emby webhook season无tmdbid场景)
elif mtype and season and dest: elif mtype and season is not None and dest:
# 电视剧某季 # 电视剧某季
return db.query(cls).filter(cls.type == mtype, return db.query(cls).filter(cls.type == mtype,
cls.seasons == season, cls.seasons == season,
+2 -2
View File
@@ -92,7 +92,7 @@ class SubscribeOper(DbOper):
判断是否存在 判断是否存在
""" """
if tmdbid: if tmdbid:
if season: if season is not None:
return True if Subscribe.exists(self._db, tmdbid=tmdbid, season=season) else False return True if Subscribe.exists(self._db, tmdbid=tmdbid, season=season) else False
else: else:
return True if Subscribe.exists(self._db, tmdbid=tmdbid) else False return True if Subscribe.exists(self._db, tmdbid=tmdbid) else False
@@ -195,7 +195,7 @@ class SubscribeOper(DbOper):
判断是否存在订阅历史 判断是否存在订阅历史
""" """
if tmdbid: if tmdbid:
if season: if season is not None:
return True if SubscribeHistory.exists(self._db, tmdbid=tmdbid, season=season) else False return True if SubscribeHistory.exists(self._db, tmdbid=tmdbid, season=season) else False
else: else:
return True if SubscribeHistory.exists(self._db, tmdbid=tmdbid) else False return True if SubscribeHistory.exists(self._db, tmdbid=tmdbid) else False