mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-13 11:39:50 +08:00
add:订阅分享与复用API
This commit is contained in:
@@ -54,7 +54,7 @@ def create_subscribe(
|
||||
*,
|
||||
subscribe_in: schemas.Subscribe,
|
||||
current_user: User = Depends(get_current_active_user),
|
||||
) -> Any:
|
||||
) -> schemas.Response:
|
||||
"""
|
||||
新增订阅
|
||||
"""
|
||||
@@ -84,6 +84,9 @@ def create_subscribe(
|
||||
best_version=subscribe_in.best_version,
|
||||
save_path=subscribe_in.save_path,
|
||||
search_imdbid=subscribe_in.search_imdbid,
|
||||
custom_words=subscribe_in.custom_words,
|
||||
media_category=subscribe_in.media_category,
|
||||
filter_groups=subscribe_in.filter_groups,
|
||||
exist_ok=True)
|
||||
return schemas.Response(
|
||||
success=bool(sid), message=message, data={"id": sid}
|
||||
@@ -412,6 +415,37 @@ def subscribe_files(
|
||||
return schemas.SubscrbieInfo()
|
||||
|
||||
|
||||
@router.post("/share", summary="分享订阅", response_model=schemas.Response)
|
||||
def subscribe_share(
|
||||
sub: schemas.SubscribeShare,
|
||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
分享订阅
|
||||
"""
|
||||
state, errmsg = SubscribeHelper().sub_share(subscribe_id=sub.subscribe_id,
|
||||
share_title=sub.share_title,
|
||||
share_comment=sub.share_comment,
|
||||
share_user=sub.share_user)
|
||||
return schemas.Response(success=state, message=errmsg)
|
||||
|
||||
|
||||
@router.post("/fork", summary="复用订阅", response_model=schemas.Response)
|
||||
def subscribe_fork(
|
||||
sub: schemas.SubscribeShare,
|
||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
复用订阅
|
||||
"""
|
||||
sub_dict = sub.dict()
|
||||
for key in sub_dict.keys():
|
||||
if not hasattr(schemas.Subscribe, key):
|
||||
sub_dict.pop(key)
|
||||
result = create_subscribe(subscribe_in=schemas.Subscribe(**sub_dict))
|
||||
if result.success:
|
||||
SubscribeHelper().sub_fork(share_id=sub.share_id)
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/{subscribe_id}", summary="订阅详情", response_model=schemas.Subscribe)
|
||||
def read_subscribe(
|
||||
subscribe_id: int,
|
||||
|
||||
@@ -117,4 +117,3 @@ class SubscribeOper(DbOper):
|
||||
kwargs.pop("id")
|
||||
subscribe = SubscribeHistory(**kwargs)
|
||||
subscribe.create(self._db)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from threading import Thread
|
||||
from typing import List
|
||||
from typing import List, Tuple
|
||||
|
||||
from cachetools import TTLCache, cached
|
||||
|
||||
@@ -13,7 +13,7 @@ from app.utils.singleton import Singleton
|
||||
|
||||
class SubscribeHelper(metaclass=Singleton):
|
||||
"""
|
||||
订阅数据统计
|
||||
订阅数据统计/订阅分享等
|
||||
"""
|
||||
|
||||
_sub_reg = f"{settings.MP_SERVER_HOST}/subscribe/add"
|
||||
@@ -24,6 +24,10 @@ class SubscribeHelper(metaclass=Singleton):
|
||||
|
||||
_sub_statistic = f"{settings.MP_SERVER_HOST}/subscribe/statistic"
|
||||
|
||||
_sub_share = f"{settings.MP_SERVER_HOST}/subscribe/share"
|
||||
|
||||
_sub_fork = f"{settings.MP_SERVER_HOST}/subscribe/fork/%s"
|
||||
|
||||
def __init__(self):
|
||||
self.systemconfig = SystemConfigOper()
|
||||
if settings.SUBSCRIBE_STATISTIC_SHARE:
|
||||
@@ -120,3 +124,64 @@ class SubscribeHelper(metaclass=Singleton):
|
||||
]
|
||||
})
|
||||
return True if res else False
|
||||
|
||||
def sub_share(self, subscribe_id: int,
|
||||
share_title: str, share_comment: str, share_user: str) -> Tuple[bool, str]:
|
||||
"""
|
||||
分享订阅
|
||||
"""
|
||||
if not settings.SUBSCRIBE_STATISTIC_SHARE:
|
||||
return False, "当前没有开启订阅数据共享功能"
|
||||
subscribe = SubscribeOper().get(subscribe_id)
|
||||
if not subscribe:
|
||||
return False, "订阅不存在"
|
||||
res = RequestUtils(content_type="application/json",
|
||||
timeout=10).post(self._sub_share,
|
||||
json={
|
||||
"share_title": share_title,
|
||||
"share_comment": share_comment,
|
||||
"share_user": share_user,
|
||||
"name": subscribe.name,
|
||||
"year": subscribe.year,
|
||||
"type": subscribe.type,
|
||||
"tmdbid": subscribe.tmdbid,
|
||||
"imdbid": subscribe.imdbid,
|
||||
"tvdbid": subscribe.tvdbid,
|
||||
"doubanid": subscribe.doubanid,
|
||||
"bangumiid": subscribe.bangumiid,
|
||||
"season": subscribe.season,
|
||||
"poster": subscribe.poster,
|
||||
"backdrop": subscribe.backdrop,
|
||||
"vote": subscribe.vote,
|
||||
"description": subscribe.description,
|
||||
"include": subscribe.include,
|
||||
"exclude": subscribe.include,
|
||||
"quality": subscribe.include,
|
||||
"resolution": subscribe.include,
|
||||
"effect": subscribe.include,
|
||||
"total_episode": subscribe.include,
|
||||
"custom_words": subscribe.include,
|
||||
"media_category": subscribe.include,
|
||||
})
|
||||
if res is None:
|
||||
return False, "连接MoviePilot服务器失败"
|
||||
if res.ok:
|
||||
return True, ""
|
||||
else:
|
||||
return False, res.json().get("message")
|
||||
|
||||
def sub_fork(self, share_id: int) -> Tuple[bool, str]:
|
||||
"""
|
||||
复用分享的订阅
|
||||
"""
|
||||
if not settings.SUBSCRIBE_STATISTIC_SHARE:
|
||||
return False, "当前没有开启订阅数据共享功能"
|
||||
res = RequestUtils(timeout=5, headers={
|
||||
"Content-Type": "application/json"
|
||||
}).get_res(self._sub_fork % share_id)
|
||||
if res is None:
|
||||
return False, "连接MoviePilot服务器失败"
|
||||
if res.ok:
|
||||
return True, ""
|
||||
else:
|
||||
return False, res.json().get("message")
|
||||
|
||||
@@ -75,6 +75,58 @@ class Subscribe(BaseModel):
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class SubscribeShare(BaseModel):
|
||||
# 分享ID
|
||||
share_id: Optional[int] = None
|
||||
# 订阅ID
|
||||
subscribe_id: Optional[int] = None
|
||||
# 分享标题
|
||||
share_title: Optional[str] = None
|
||||
# 分享说明
|
||||
share_comment: Optional[str] = None
|
||||
# 分享人
|
||||
share_user: Optional[str] = None
|
||||
# 订阅名称
|
||||
name: Optional[str] = None
|
||||
# 订阅年份
|
||||
year: Optional[str] = None
|
||||
# 订阅类型 电影/电视剧
|
||||
type: Optional[str] = None
|
||||
# 搜索关键字
|
||||
keyword: Optional[str] = None
|
||||
tmdbid: Optional[int] = None
|
||||
doubanid: Optional[str] = None
|
||||
bangumiid: Optional[int] = None
|
||||
# 季号
|
||||
season: Optional[int] = None
|
||||
# 海报
|
||||
poster: Optional[str] = None
|
||||
# 背景图
|
||||
backdrop: Optional[str] = None
|
||||
# 评分
|
||||
vote: Optional[int] = 0
|
||||
# 描述
|
||||
description: Optional[str] = None
|
||||
# 包含
|
||||
include: Optional[str] = None
|
||||
# 排除
|
||||
exclude: Optional[str] = None
|
||||
# 质量
|
||||
quality: Optional[str] = None
|
||||
# 分辨率
|
||||
resolution: Optional[str] = None
|
||||
# 特效
|
||||
effect: Optional[str] = None
|
||||
# 总集数
|
||||
total_episode: Optional[int] = 0
|
||||
# 时间
|
||||
date: Optional[str] = None
|
||||
# 自定义识别词
|
||||
custom_words: Optional[str] = None
|
||||
# 自定义媒体类别
|
||||
media_category: Optional[str] = None
|
||||
|
||||
|
||||
class SubscribeDownloadFileInfo(BaseModel):
|
||||
# 种子名称
|
||||
torrent_title: Optional[str] = None
|
||||
|
||||
Reference in New Issue
Block a user