From f20c133c813ffea3f7ddaba41d27cb82b22bf873 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 9 Jul 2023 00:04:04 +0800 Subject: [PATCH] fix download --- app/api/endpoints/download.py | 15 ++++++++++++--- app/core/context.py | 19 +++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/api/endpoints/download.py b/app/api/endpoints/download.py index b3393993..9602addf 100644 --- a/app/api/endpoints/download.py +++ b/app/api/endpoints/download.py @@ -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( - 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()) + meta_info=metainfo, + media_info=mediainfo, + torrent_info=torrentinfo ) did = DownloadChain().download_single(context=context, userid=current_user.name) return schemas.Response(success=True if did else False, data={ diff --git a/app/core/context.py b/app/core/context.py index 513ffdd1..cea1e682 100644 --- a/app/core/context.py +++ b/app/core/context.py @@ -55,11 +55,14 @@ class TorrentInfo: # 种子优先级 pri_order: int = 0 - def __init__(self, **kwargs): - self.labels = [] - for key, value in kwargs.items(): - if hasattr(self, key) and value is not None: - setattr(self, key, value) + def from_dict(self, data: dict): + """ + 从字典中初始化 + """ + for key, value in data.items(): + if key in ['volume_factor']: + continue + setattr(self, key, value) @staticmethod 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(): - attr = getattr(self, key, None) - if attr and not isinstance(attr, property): - setattr(self, key, value) + if key in ["title_year", "detail_link", "stars", "vote_star"]: + continue + setattr(self, key, value) if isinstance(self.type, str): self.type = MediaType(self.type)