fix download

This commit is contained in:
jxxghp 2023-07-09 00:04:04 +08:00
parent 5690ee9bd6
commit f20c133c81
2 changed files with 23 additions and 11 deletions

View File

@ -33,10 +33,19 @@ async def add_downloading(
""" """
添加下载任务 添加下载任务
""" """
# 元数据
metainfo = MetaInfo(title=torrent_in.title, subtitle=torrent_in.description)
# 媒体信息
mediainfo = MediaInfo()
mediainfo.from_dict(media_in.dict())
# 种子信息
torrentinfo = TorrentInfo()
torrentinfo.from_dict(torrent_in.dict())
# 上下文
context = Context( context = Context(
meta_info=MetaInfo(title=torrent_in.title, subtitle=torrent_in.description), meta_info=metainfo,
media_info=MediaInfo().from_dict(media_in.dict()), media_info=mediainfo,
torrent_info=TorrentInfo(**torrent_in.dict()) torrent_info=torrentinfo
) )
did = DownloadChain().download_single(context=context, userid=current_user.name) did = DownloadChain().download_single(context=context, userid=current_user.name)
return schemas.Response(success=True if did else False, data={ return schemas.Response(success=True if did else False, data={

View File

@ -55,11 +55,14 @@ class TorrentInfo:
# 种子优先级 # 种子优先级
pri_order: int = 0 pri_order: int = 0
def __init__(self, **kwargs): def from_dict(self, data: dict):
self.labels = [] """
for key, value in kwargs.items(): 从字典中初始化
if hasattr(self, key) and value is not None: """
setattr(self, key, value) for key, value in data.items():
if key in ['volume_factor']:
continue
setattr(self, key, value)
@staticmethod @staticmethod
def get_free_string(upload_volume_factor: float, download_volume_factor: float) -> str: def get_free_string(upload_volume_factor: float, download_volume_factor: float) -> str:
@ -159,9 +162,9 @@ class MediaInfo:
从字典中初始化 从字典中初始化
""" """
for key, value in data.items(): for key, value in data.items():
attr = getattr(self, key, None) if key in ["title_year", "detail_link", "stars", "vote_star"]:
if attr and not isinstance(attr, property): continue
setattr(self, key, value) setattr(self, key, value)
if isinstance(self.type, str): if isinstance(self.type, str):
self.type = MediaType(self.type) self.type = MediaType(self.type)