feat:订阅历史以及API
This commit is contained in:
parent
b04bc74550
commit
3a18267ec0
@ -11,6 +11,7 @@ from app.core.metainfo import MetaInfo
|
|||||||
from app.core.security import verify_token, verify_uri_token
|
from app.core.security import verify_token, verify_uri_token
|
||||||
from app.db import get_db
|
from app.db import get_db
|
||||||
from app.db.models.subscribe import Subscribe
|
from app.db.models.subscribe import Subscribe
|
||||||
|
from app.db.models.subscribehistory import SubscribeHistory
|
||||||
from app.db.models.user import User
|
from app.db.models.user import User
|
||||||
from app.db.userauth import get_current_active_user
|
from app.db.userauth import get_current_active_user
|
||||||
from app.scheduler import Scheduler
|
from app.scheduler import Scheduler
|
||||||
@ -197,9 +198,11 @@ def search_subscribes(
|
|||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
Scheduler().start,
|
Scheduler().start,
|
||||||
job_id="subscribe_search",
|
job_id="subscribe_search",
|
||||||
sid=None,
|
**{
|
||||||
state='R',
|
"sid": None,
|
||||||
manual=True
|
"state": 'R',
|
||||||
|
"manual": True
|
||||||
|
}
|
||||||
)
|
)
|
||||||
return schemas.Response(success=True)
|
return schemas.Response(success=True)
|
||||||
|
|
||||||
@ -215,29 +218,15 @@ def search_subscribe(
|
|||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
Scheduler().start,
|
Scheduler().start,
|
||||||
job_id="subscribe_search",
|
job_id="subscribe_search",
|
||||||
sid=subscribe_id,
|
**{
|
||||||
state=None,
|
"sid": subscribe_id,
|
||||||
manual=True
|
"state": None,
|
||||||
|
"manual": True
|
||||||
|
}
|
||||||
)
|
)
|
||||||
return schemas.Response(success=True)
|
return schemas.Response(success=True)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{subscribe_id}", summary="订阅详情", response_model=schemas.Subscribe)
|
|
||||||
def read_subscribe(
|
|
||||||
subscribe_id: int,
|
|
||||||
db: Session = Depends(get_db),
|
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|
||||||
"""
|
|
||||||
根据订阅编号查询订阅信息
|
|
||||||
"""
|
|
||||||
if not subscribe_id:
|
|
||||||
return Subscribe()
|
|
||||||
subscribe = Subscribe.get(db, subscribe_id)
|
|
||||||
if subscribe and subscribe.sites:
|
|
||||||
subscribe.sites = json.loads(subscribe.sites)
|
|
||||||
return subscribe
|
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/media/{mediaid}", summary="删除订阅", response_model=schemas.Response)
|
@router.delete("/media/{mediaid}", summary="删除订阅", response_model=schemas.Response)
|
||||||
def delete_subscribe_by_mediaid(
|
def delete_subscribe_by_mediaid(
|
||||||
mediaid: str,
|
mediaid: str,
|
||||||
@ -262,19 +251,6 @@ def delete_subscribe_by_mediaid(
|
|||||||
return schemas.Response(success=True)
|
return schemas.Response(success=True)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{subscribe_id}", summary="删除订阅", response_model=schemas.Response)
|
|
||||||
def delete_subscribe(
|
|
||||||
subscribe_id: int,
|
|
||||||
db: Session = Depends(get_db),
|
|
||||||
_: schemas.TokenPayload = Depends(verify_token)
|
|
||||||
) -> Any:
|
|
||||||
"""
|
|
||||||
删除订阅信息
|
|
||||||
"""
|
|
||||||
Subscribe.delete(db, subscribe_id)
|
|
||||||
return schemas.Response(success=True)
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/seerr", summary="OverSeerr/JellySeerr通知订阅", response_model=schemas.Response)
|
@router.post("/seerr", summary="OverSeerr/JellySeerr通知订阅", response_model=schemas.Response)
|
||||||
async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
|
async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
|
||||||
authorization: str = Header(None)) -> Any:
|
authorization: str = Header(None)) -> Any:
|
||||||
@ -326,3 +302,58 @@ async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
|
|||||||
username=user_name)
|
username=user_name)
|
||||||
|
|
||||||
return schemas.Response(success=True)
|
return schemas.Response(success=True)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/history/{mtype}", summary="查询订阅历史", response_model=List[schemas.Subscribe])
|
||||||
|
def read_subscribe(
|
||||||
|
mtype: str,
|
||||||
|
page: int = 1,
|
||||||
|
count: int = 30,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
查询电影/电视剧订阅历史
|
||||||
|
"""
|
||||||
|
return SubscribeHistory.list_by_type(db, mtype=mtype, page=page, count=count)
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/history/{history_id}", summary="删除订阅历史", response_model=schemas.Response)
|
||||||
|
def delete_subscribe(
|
||||||
|
history_id: int,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)
|
||||||
|
) -> Any:
|
||||||
|
"""
|
||||||
|
删除订阅历史
|
||||||
|
"""
|
||||||
|
SubscribeHistory.delete(db, history_id)
|
||||||
|
return schemas.Response(success=True)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/{subscribe_id}", summary="订阅详情", response_model=schemas.Subscribe)
|
||||||
|
def read_subscribe(
|
||||||
|
subscribe_id: int,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
根据订阅编号查询订阅信息
|
||||||
|
"""
|
||||||
|
if not subscribe_id:
|
||||||
|
return Subscribe()
|
||||||
|
subscribe = Subscribe.get(db, subscribe_id)
|
||||||
|
if subscribe and subscribe.sites:
|
||||||
|
subscribe.sites = json.loads(subscribe.sites)
|
||||||
|
return subscribe
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/{subscribe_id}", summary="删除订阅", response_model=schemas.Response)
|
||||||
|
def delete_subscribe(
|
||||||
|
subscribe_id: int,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)
|
||||||
|
) -> Any:
|
||||||
|
"""
|
||||||
|
删除订阅信息
|
||||||
|
"""
|
||||||
|
Subscribe.delete(db, subscribe_id)
|
||||||
|
return schemas.Response(success=True)
|
||||||
|
@ -16,6 +16,7 @@ from app.core.meta import MetaBase
|
|||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.db.models.subscribe import Subscribe
|
from app.db.models.subscribe import Subscribe
|
||||||
from app.db.subscribe_oper import SubscribeOper
|
from app.db.subscribe_oper import SubscribeOper
|
||||||
|
from app.db.subscribehistory_oper import SubscribeHistoryOper
|
||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
from app.helper.message import MessageHelper
|
from app.helper.message import MessageHelper
|
||||||
from app.helper.torrent import TorrentHelper
|
from app.helper.torrent import TorrentHelper
|
||||||
@ -34,6 +35,7 @@ class SubscribeChain(ChainBase):
|
|||||||
self.downloadchain = DownloadChain()
|
self.downloadchain = DownloadChain()
|
||||||
self.searchchain = SearchChain()
|
self.searchchain = SearchChain()
|
||||||
self.subscribeoper = SubscribeOper()
|
self.subscribeoper = SubscribeOper()
|
||||||
|
self.subscribehistoryoper = SubscribeHistoryOper()
|
||||||
self.torrentschain = TorrentsChain()
|
self.torrentschain = TorrentsChain()
|
||||||
self.mediachain = MediaChain()
|
self.mediachain = MediaChain()
|
||||||
self.message = MessageHelper()
|
self.message = MessageHelper()
|
||||||
@ -371,6 +373,9 @@ class SubscribeChain(ChainBase):
|
|||||||
priority = max([item.torrent_info.pri_order for item in downloads])
|
priority = max([item.torrent_info.pri_order for item in downloads])
|
||||||
if priority == 100:
|
if priority == 100:
|
||||||
logger.info(f'{mediainfo.title_year} 洗版完成,删除订阅')
|
logger.info(f'{mediainfo.title_year} 洗版完成,删除订阅')
|
||||||
|
# 新增订阅历史
|
||||||
|
self.subscribehistoryoper.add(**subscribe.to_dict())
|
||||||
|
# 删除订阅
|
||||||
self.subscribeoper.delete(subscribe.id)
|
self.subscribeoper.delete(subscribe.id)
|
||||||
# 发送通知
|
# 发送通知
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
||||||
@ -406,6 +411,9 @@ class SubscribeChain(ChainBase):
|
|||||||
or force):
|
or force):
|
||||||
# 全部下载完成
|
# 全部下载完成
|
||||||
logger.info(f'{mediainfo.title_year} 完成订阅')
|
logger.info(f'{mediainfo.title_year} 完成订阅')
|
||||||
|
# 新增订阅历史
|
||||||
|
self.subscribehistoryoper.add(**subscribe.to_dict())
|
||||||
|
# 删除订阅
|
||||||
self.subscribeoper.delete(subscribe.id)
|
self.subscribeoper.delete(subscribe.id)
|
||||||
# 发送通知
|
# 发送通知
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
||||||
|
72
app/db/models/subscribehistory.py
Normal file
72
app/db/models/subscribehistory.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
from sqlalchemy import Column, Integer, String, Sequence, Float
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from app.db import db_query, Base
|
||||||
|
|
||||||
|
|
||||||
|
class SubscribeHistory(Base):
|
||||||
|
"""
|
||||||
|
订阅历史表
|
||||||
|
"""
|
||||||
|
id = Column(Integer, Sequence('id'), primary_key=True, index=True)
|
||||||
|
# 标题
|
||||||
|
name = Column(String, nullable=False, index=True)
|
||||||
|
# 年份
|
||||||
|
year = Column(String)
|
||||||
|
# 类型
|
||||||
|
type = Column(String)
|
||||||
|
# 搜索关键字
|
||||||
|
keyword = Column(String)
|
||||||
|
tmdbid = Column(Integer, index=True)
|
||||||
|
imdbid = Column(String)
|
||||||
|
tvdbid = Column(Integer)
|
||||||
|
doubanid = Column(String, index=True)
|
||||||
|
bangumiid = Column(Integer, index=True)
|
||||||
|
# 季号
|
||||||
|
season = Column(Integer)
|
||||||
|
# 海报
|
||||||
|
poster = Column(String)
|
||||||
|
# 背景图
|
||||||
|
backdrop = Column(String)
|
||||||
|
# 评分,float
|
||||||
|
vote = Column(Float)
|
||||||
|
# 简介
|
||||||
|
description = Column(String)
|
||||||
|
# 过滤规则
|
||||||
|
filter = Column(String)
|
||||||
|
# 包含
|
||||||
|
include = Column(String)
|
||||||
|
# 排除
|
||||||
|
exclude = Column(String)
|
||||||
|
# 质量
|
||||||
|
quality = Column(String)
|
||||||
|
# 分辨率
|
||||||
|
resolution = Column(String)
|
||||||
|
# 特效
|
||||||
|
effect = Column(String)
|
||||||
|
# 总集数
|
||||||
|
total_episode = Column(Integer)
|
||||||
|
# 开始集数
|
||||||
|
start_episode = Column(Integer)
|
||||||
|
# 订阅完成时间
|
||||||
|
date = Column(String)
|
||||||
|
# 订阅用户
|
||||||
|
username = Column(String)
|
||||||
|
# 订阅站点
|
||||||
|
sites = Column(String)
|
||||||
|
# 是否洗版
|
||||||
|
best_version = Column(Integer, default=0)
|
||||||
|
# 保存路径
|
||||||
|
save_path = Column(String)
|
||||||
|
# 是否使用 imdbid 搜索
|
||||||
|
search_imdbid = Column(Integer, default=0)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@db_query
|
||||||
|
def list_by_type(db: Session, mtype: str, page: int = 1, count: int = 30):
|
||||||
|
result = db.query(SubscribeHistory).filter(
|
||||||
|
SubscribeHistory.type == mtype
|
||||||
|
).order_by(
|
||||||
|
SubscribeHistory.date.desc()
|
||||||
|
).offset((page - 1) * count).limit(count).all()
|
||||||
|
return list(result)
|
27
app/db/subscribehistory_oper.py
Normal file
27
app/db/subscribehistory_oper.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
from app.db import DbOper
|
||||||
|
from app.db.models.subscribehistory import SubscribeHistory
|
||||||
|
|
||||||
|
|
||||||
|
class SubscribeHistoryOper(DbOper):
|
||||||
|
"""
|
||||||
|
订阅历史管理
|
||||||
|
"""
|
||||||
|
|
||||||
|
def add(self, **kwargs):
|
||||||
|
"""
|
||||||
|
新增订阅
|
||||||
|
"""
|
||||||
|
# 去除kwargs中 SubscribeHistory 没有的字段
|
||||||
|
kwargs = {k: v for k, v in kwargs.items() if hasattr(SubscribeHistory, k)}
|
||||||
|
# 更新完成订阅时间
|
||||||
|
kwargs.update({"date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())})
|
||||||
|
subscribe = SubscribeHistory(**kwargs)
|
||||||
|
subscribe.create(self._db)
|
||||||
|
|
||||||
|
def list_by_type(self, mtype: str, page: int = 1, count: int = 30) -> SubscribeHistory:
|
||||||
|
"""
|
||||||
|
获取指定类型的订阅
|
||||||
|
"""
|
||||||
|
return SubscribeHistory.list_by_type(self._db, mtype=mtype, page=page, count=count)
|
Loading…
x
Reference in New Issue
Block a user