From af3a50f7ea6e11d06c4426b9cbb386d6694122c1 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 16 Nov 2024 09:00:18 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=AE=A2=E9=98=85=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=BB=91=E5=AE=9A=E4=B8=8B=E8=BD=BD=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/download.py | 26 +++++++++++++++---------- app/chain/subscribe.py | 8 ++++++-- app/db/models/subscribe.py | 2 ++ app/schemas/subscribe.py | 2 ++ database/versions/eaf9cbc49027_2_0_7.py | 9 ++++++--- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/chain/download.py b/app/chain/download.py index b09a4f38..96775b5c 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -204,10 +204,10 @@ class DownloadChain(ChainBase): def download_single(self, context: Context, torrent_file: Path = None, episodes: Set[int] = None, channel: MessageChannel = None, source: str = None, + downloader: str = None, save_path: str = None, userid: Union[str, int] = None, username: str = None, - downloader: str = None, media_category: str = None) -> Optional[str]: """ 下载及发送通知 @@ -216,16 +216,16 @@ class DownloadChain(ChainBase): :param episodes: 需要下载的集数 :param channel: 通知渠道 :param source: 通知来源 + :param downloader: 下载器 :param save_path: 保存路径 :param userid: 用户ID :param username: 调用下载的用户名/插件名 - :param downloader: 下载器 :param media_category: 自定义媒体类别 """ _torrent = context.torrent_info _media = context.media_info _meta = context.meta_info - _downloader = _torrent.site_downloader + _site_downloader = _torrent.site_downloader # 补充完整的media数据 if not _media.genre_ids: @@ -288,7 +288,7 @@ class DownloadChain(ChainBase): episodes=episodes, download_dir=download_dir, category=_media.category, - downloader=downloader or _downloader) + downloader=downloader or _site_downloader) if result: _downloader, _hash, error_msg = result else: @@ -387,7 +387,8 @@ class DownloadChain(ChainBase): source: str = None, userid: str = None, username: str = None, - media_category: str = None + media_category: str = None, + downloader: str = None ) -> Tuple[List[Context], Dict[Union[int, str], Dict[int, NotExistMediaInfo]]]: """ 根据缺失数据,自动种子列表中组合择优下载 @@ -399,6 +400,7 @@ class DownloadChain(ChainBase): :param userid: 用户ID :param username: 调用下载的用户名/插件名 :param media_category: 自定义媒体类别 + :param downloader: 下载器 :return: 已经下载的资源列表、剩余未下载到的剧集 no_exists[tmdb_id/douban_id] = {season: NotExistMediaInfo} """ # 已下载的项目 @@ -470,7 +472,7 @@ class DownloadChain(ChainBase): logger.info(f"开始下载电影 {context.torrent_info.title} ...") if self.download_single(context, save_path=save_path, channel=channel, source=source, userid=userid, username=username, - media_category=media_category): + media_category=media_category, downloader=downloader): # 下载成功 logger.info(f"{context.torrent_info.title} 添加下载成功") downloaded_list.append(context) @@ -555,7 +557,8 @@ class DownloadChain(ChainBase): source=source, userid=userid, username=username, - media_category=media_category + media_category=media_category, + downloader=downloader, ) else: # 下载 @@ -563,7 +566,8 @@ class DownloadChain(ChainBase): download_id = self.download_single(context, save_path=save_path, channel=channel, source=source, userid=userid, username=username, - media_category=media_category) + media_category=media_category, + downloader=downloader) if download_id: # 下载成功 @@ -634,7 +638,8 @@ class DownloadChain(ChainBase): download_id = self.download_single(context, save_path=save_path, channel=channel, source=source, userid=userid, username=username, - media_category=media_category) + media_category=media_category, + downloader=downloader) if download_id: # 下载成功 logger.info(f"{meta.title} 添加下载成功") @@ -723,7 +728,8 @@ class DownloadChain(ChainBase): source=source, userid=userid, username=username, - media_category=media_category + media_category=media_category, + downloader=downloader ) if not download_id: continue diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 8f4c1a0c..108c5e2d 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -159,6 +159,8 @@ class SubscribeChain(ChainBase): "search_imdbid") else kwargs.get("search_imdbid"), 'sites': self.__get_default_subscribe_config(mediainfo.type, "sites") or None if not kwargs.get( "sites") else kwargs.get("sites"), + 'downloader': self.__get_default_subscribe_config(mediainfo.type, "downloader") if not kwargs.get( + "downloader") else kwargs.get("downloader"), 'save_path': self.__get_default_subscribe_config(mediainfo.type, "save_path") if not kwargs.get( "save_path") else kwargs.get("save_path") }) @@ -394,7 +396,8 @@ class SubscribeChain(ChainBase): userid=subscribe.username, username=subscribe.username, save_path=subscribe.save_path, - media_category=subscribe.media_category + media_category=subscribe.media_category, + downloader=subscribe.downloader, ) # 判断是否应完成订阅 @@ -773,7 +776,8 @@ class SubscribeChain(ChainBase): userid=subscribe.username, username=subscribe.username, save_path=subscribe.save_path, - media_category=subscribe.media_category) + media_category=subscribe.media_category, + downloader=subscribe.downloader) # 判断是否要完成订阅 self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, downloads=downloads, lefts=lefts) diff --git a/app/db/models/subscribe.py b/app/db/models/subscribe.py index 114e2c89..47d23cfc 100644 --- a/app/db/models/subscribe.py +++ b/app/db/models/subscribe.py @@ -64,6 +64,8 @@ class Subscribe(Base): username = Column(String) # 订阅站点 sites = Column(JSON, default=list) + # 下载器 + downloader = Column(String) # 是否洗版 best_version = Column(Integer, default=0) # 当前优先级 diff --git a/app/schemas/subscribe.py b/app/schemas/subscribe.py index 3f9dfa27..f69ffd8d 100644 --- a/app/schemas/subscribe.py +++ b/app/schemas/subscribe.py @@ -54,6 +54,8 @@ class Subscribe(BaseModel): username: Optional[str] = None # 订阅站点 sites: Optional[List[int]] = [] + # 下载器 + downloader: Optional[str] = None # 是否洗版 best_version: Optional[int] = 0 # 当前优先级 diff --git a/database/versions/eaf9cbc49027_2_0_7.py b/database/versions/eaf9cbc49027_2_0_7.py index d3156434..0ced5b34 100644 --- a/database/versions/eaf9cbc49027_2_0_7.py +++ b/database/versions/eaf9cbc49027_2_0_7.py @@ -19,10 +19,13 @@ depends_on = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - # 站点管理增加下载器选项 - with contextlib.suppress(Exception): + # 站点管理、订阅增加下载器选项 + with contextlib.suppress(Exception): op.add_column('site', sa.Column('downloader', sa.String(), nullable=True)) - # ### end Alembic commands ### + op.add_column('subscribe', sa.Column('downloader', sa.String(), nullable=True)) + + +# ### end Alembic commands ### def downgrade() -> None: pass