Revert "fix #907"
This reverts commit 4dcefb141a6d1958e36156155d0b1f8a89aafcc5.
This commit is contained in:
parent
7587946d51
commit
c1ecdfc61d
@ -20,7 +20,18 @@ def statistic(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|||||||
"""
|
"""
|
||||||
查询媒体数量统计信息
|
查询媒体数量统计信息
|
||||||
"""
|
"""
|
||||||
return DashboardChain().media_statistic()
|
media_statistics: Optional[List[schemas.Statistic]] = DashboardChain().media_statistic()
|
||||||
|
if media_statistics:
|
||||||
|
# 汇总各媒体库统计信息
|
||||||
|
ret_statistic = schemas.Statistic()
|
||||||
|
for media_statistic in media_statistics:
|
||||||
|
ret_statistic.movie_count += media_statistic.movie_count
|
||||||
|
ret_statistic.tv_count += media_statistic.tv_count
|
||||||
|
ret_statistic.episode_count += media_statistic.episode_count
|
||||||
|
ret_statistic.user_count += media_statistic.user_count
|
||||||
|
return ret_statistic
|
||||||
|
else:
|
||||||
|
return schemas.Statistic()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/statistic2", summary="媒体数量统计(API_TOKEN)", response_model=schemas.Statistic)
|
@router.get("/statistic2", summary="媒体数量统计(API_TOKEN)", response_model=schemas.Statistic)
|
||||||
|
@ -1,50 +1,19 @@
|
|||||||
import json
|
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.db.mediaserver_oper import MediaServerOper
|
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
|
|
||||||
|
|
||||||
class DashboardChain(ChainBase, metaclass=Singleton):
|
class DashboardChain(ChainBase, metaclass=Singleton):
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.dboper = MediaServerOper()
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
各类仪表板统计处理链
|
各类仪表板统计处理链
|
||||||
"""
|
"""
|
||||||
|
def media_statistic(self) -> Optional[List[schemas.Statistic]]:
|
||||||
def media_statistic(self) -> Optional[schemas.Statistic]:
|
|
||||||
"""
|
"""
|
||||||
媒体数量统计
|
媒体数量统计
|
||||||
"""
|
"""
|
||||||
ret_statistic = schemas.Statistic()
|
return self.run_module("media_statistic")
|
||||||
media_statistics = self.run_module("media_statistic")
|
|
||||||
if media_statistics:
|
|
||||||
# 汇总各媒体库统计信息
|
|
||||||
for media_statistic in media_statistics:
|
|
||||||
ret_statistic.user_count += media_statistic.user_count
|
|
||||||
# 电影数量
|
|
||||||
movies = self.dboper.list_by_type(mtype="电影") or []
|
|
||||||
ret_statistic.movie_count = len(movies)
|
|
||||||
# 电视剧数量
|
|
||||||
series = self.dboper.list_by_type(mtype="电视剧") or []
|
|
||||||
if series:
|
|
||||||
ret_statistic.tv_count = len(series)
|
|
||||||
# 剧集数量
|
|
||||||
for tv in series:
|
|
||||||
seasoninfo = tv.seasoninfo
|
|
||||||
if seasoninfo:
|
|
||||||
if not isinstance(seasoninfo, dict):
|
|
||||||
seasoninfo = json.loads(seasoninfo)
|
|
||||||
if seasoninfo.keys():
|
|
||||||
for season in seasoninfo.keys():
|
|
||||||
episodes = seasoninfo.get(season) or []
|
|
||||||
ret_statistic.episode_count += len(episodes)
|
|
||||||
return ret_statistic
|
|
||||||
|
|
||||||
def downloader_info(self) -> schemas.DownloaderInfo:
|
def downloader_info(self) -> schemas.DownloaderInfo:
|
||||||
"""
|
"""
|
||||||
|
@ -65,9 +65,3 @@ class MediaServerOper(DbOper):
|
|||||||
if not item:
|
if not item:
|
||||||
return None
|
return None
|
||||||
return str(item.item_id)
|
return str(item.item_id)
|
||||||
|
|
||||||
def list_by_type(self, mtype: str = None):
|
|
||||||
"""
|
|
||||||
获取指定类型的媒体服务器数据
|
|
||||||
"""
|
|
||||||
return MediaServerItem.list_by_type(self._db, mtype=mtype)
|
|
||||||
|
@ -66,11 +66,3 @@ class MediaServerItem(Base):
|
|||||||
return db.query(MediaServerItem).filter(MediaServerItem.title == title,
|
return db.query(MediaServerItem).filter(MediaServerItem.title == title,
|
||||||
MediaServerItem.item_type == mtype,
|
MediaServerItem.item_type == mtype,
|
||||||
MediaServerItem.year == str(year)).first()
|
MediaServerItem.year == str(year)).first()
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
@db_query
|
|
||||||
def list_by_type(db: Session, mtype: str = None):
|
|
||||||
if mtype:
|
|
||||||
return db.query(MediaServerItem).filter(MediaServerItem.item_type == mtype).all()
|
|
||||||
else:
|
|
||||||
return db.query(MediaServerItem).all()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user