fix download

This commit is contained in:
jxxghp 2023-07-08 16:30:45 +08:00
parent b6d957c7d9
commit 5ceaf94169
8 changed files with 34 additions and 7 deletions

View File

@ -6,9 +6,11 @@ from app import schemas
from app.chain.douban import DoubanChain
from app.chain.download import DownloadChain
from app.chain.media import MediaChain
from app.core.context import MediaInfo
from app.core.context import MediaInfo, Context, TorrentInfo
from app.core.metainfo import MetaInfo
from app.core.security import verify_token
from app.db.models.user import User
from app.db.userauth import get_current_active_superuser
from app.schemas import NotExistMediaInfo, MediaType
router = APIRouter()
@ -23,6 +25,25 @@ async def read_downloading(
return DownloadChain().downloading()
@router.post("/", summary="添加下载", response_model=schemas.Response)
async def add_downloading(
media_in: schemas.MediaInfo,
torrent_in: schemas.TorrentInfo,
current_user: User = Depends(get_current_active_superuser)) -> Any:
"""
添加下载任务
"""
context = Context(
meta_info=MetaInfo(title=torrent_in.title, subtitle=torrent_in.description),
media_info=MediaInfo().from_dict(media_in.dict()),
torrent_info=TorrentInfo(**torrent_in.dict())
)
did = DownloadChain().download_single(context=context, userid=current_user.name)
return schemas.Response(success=True if did else False, data={
"download_id": did
})
@router.post("/notexists", summary="查询缺失媒体信息", response_model=List[NotExistMediaInfo])
async def exists(media_in: schemas.MediaInfo,
_: schemas.TokenPayload = Depends(verify_token)) -> Any:

View File

@ -42,7 +42,7 @@ class DownloadChain(ChainBase):
msg_text = f"{msg_text}\n种子:{torrent.title}"
if torrent.seeders:
msg_text = f"{msg_text}\n做种数:{torrent.seeders}"
msg_text = f"{msg_text}\n促销:{torrent.get_volume_factor_string()}"
msg_text = f"{msg_text}\n促销:{torrent.volume_factor}"
if torrent.hit_and_run:
msg_text = f"{msg_text}\nHit&Run"
if torrent.description:

View File

@ -62,7 +62,7 @@ class TorrentInfo:
setattr(self, key, value)
@staticmethod
def get_free_string(upload_volume_factor, download_volume_factor):
def get_free_string(upload_volume_factor: float, download_volume_factor: float) -> str:
"""
计算促销类型
"""
@ -80,7 +80,8 @@ class TorrentInfo:
}
return free_strs.get('%.1f %.1f' % (upload_volume_factor, download_volume_factor), "未知")
def get_volume_factor_string(self):
@property
def volume_factor(self):
"""
返回促销信息
"""
@ -90,6 +91,8 @@ class TorrentInfo:
"""
返回字典
"""
dicts = asdict(self)
dicts["volume_factor"] = self.volume_factor
return asdict(self)

View File

@ -447,4 +447,5 @@ class MetaBase(object):
dicts = asdict(self)
dicts["type"] = self.type.value if self.type else None
dicts["season_episode"] = self.season_episode
dicts["edtion"] = self.edtion
return dicts

View File

@ -274,7 +274,7 @@ class Slack:
f"{meta.resource_term} " \
f"{meta.release_group}"
title = re.sub(r"\s+", " ", title).strip()
free = torrent.get_volume_factor_string()
free = torrent.volume_factor
seeder = f"{torrent.seeders}"
description = torrent.description
text = f"{index}. 【{site_name}】<{link}|{title}> " \

View File

@ -152,7 +152,7 @@ class Telegram(metaclass=Singleton):
f"{meta.resource_term} " \
f"{meta.release_group}"
title = re.sub(r"\s+", " ", title).strip()
free = torrent.get_volume_factor_string()
free = torrent.volume_factor
seeder = f"{torrent.seeders}"
description = torrent.description
caption = f"{caption}\n{index}.【{site_name}】[{title}]({link}) " \

View File

@ -218,7 +218,7 @@ class WeChat(metaclass=Singleton):
f"{meta.resource_term} " \
f"{meta.release_group} " \
f"{StringUtils.str_filesize(torrent.size)} " \
f"{torrent.get_volume_factor_string()} " \
f"{torrent.volume_factor} " \
f"{torrent.seeders}"
title = re.sub(r"\s+", " ", title).strip()
articles.append({

View File

@ -177,6 +177,8 @@ class TorrentInfo(BaseModel):
labels: Optional[list] = []
# 种子优先级
pri_order: Optional[int] = 0
# 促销
volume_factor: Optional[str] = None
class Context(BaseModel):