feat:订阅支持绑定下载器

This commit is contained in:
jxxghp
2024-11-16 09:00:18 +08:00
parent 44a0e5b4a7
commit af3a50f7ea
5 changed files with 32 additions and 15 deletions
+16 -10
View File
@@ -204,10 +204,10 @@ class DownloadChain(ChainBase):
def download_single(self, context: Context, torrent_file: Path = None, def download_single(self, context: Context, torrent_file: Path = None,
episodes: Set[int] = None, episodes: Set[int] = None,
channel: MessageChannel = None, source: str = None, channel: MessageChannel = None, source: str = None,
downloader: str = None,
save_path: str = None, save_path: str = None,
userid: Union[str, int] = None, userid: Union[str, int] = None,
username: str = None, username: str = None,
downloader: str = None,
media_category: str = None) -> Optional[str]: media_category: str = None) -> Optional[str]:
""" """
下载及发送通知 下载及发送通知
@@ -216,16 +216,16 @@ class DownloadChain(ChainBase):
:param episodes: 需要下载的集数 :param episodes: 需要下载的集数
:param channel: 通知渠道 :param channel: 通知渠道
:param source: 通知来源 :param source: 通知来源
:param downloader: 下载器
:param save_path: 保存路径 :param save_path: 保存路径
:param userid: 用户ID :param userid: 用户ID
:param username: 调用下载的用户名/插件名 :param username: 调用下载的用户名/插件名
:param downloader: 下载器
:param media_category: 自定义媒体类别 :param media_category: 自定义媒体类别
""" """
_torrent = context.torrent_info _torrent = context.torrent_info
_media = context.media_info _media = context.media_info
_meta = context.meta_info _meta = context.meta_info
_downloader = _torrent.site_downloader _site_downloader = _torrent.site_downloader
# 补充完整的media数据 # 补充完整的media数据
if not _media.genre_ids: if not _media.genre_ids:
@@ -288,7 +288,7 @@ class DownloadChain(ChainBase):
episodes=episodes, episodes=episodes,
download_dir=download_dir, download_dir=download_dir,
category=_media.category, category=_media.category,
downloader=downloader or _downloader) downloader=downloader or _site_downloader)
if result: if result:
_downloader, _hash, error_msg = result _downloader, _hash, error_msg = result
else: else:
@@ -387,7 +387,8 @@ class DownloadChain(ChainBase):
source: str = None, source: str = None,
userid: str = None, userid: str = None,
username: 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]]]: ) -> Tuple[List[Context], Dict[Union[int, str], Dict[int, NotExistMediaInfo]]]:
""" """
根据缺失数据,自动种子列表中组合择优下载 根据缺失数据,自动种子列表中组合择优下载
@@ -399,6 +400,7 @@ class DownloadChain(ChainBase):
:param userid: 用户ID :param userid: 用户ID
:param username: 调用下载的用户名/插件名 :param username: 调用下载的用户名/插件名
:param media_category: 自定义媒体类别 :param media_category: 自定义媒体类别
:param downloader: 下载器
:return: 已经下载的资源列表、剩余未下载到的剧集 no_exists[tmdb_id/douban_id] = {season: NotExistMediaInfo} :return: 已经下载的资源列表、剩余未下载到的剧集 no_exists[tmdb_id/douban_id] = {season: NotExistMediaInfo}
""" """
# 已下载的项目 # 已下载的项目
@@ -470,7 +472,7 @@ class DownloadChain(ChainBase):
logger.info(f"开始下载电影 {context.torrent_info.title} ...") logger.info(f"开始下载电影 {context.torrent_info.title} ...")
if self.download_single(context, save_path=save_path, channel=channel, if self.download_single(context, save_path=save_path, channel=channel,
source=source, userid=userid, username=username, source=source, userid=userid, username=username,
media_category=media_category): media_category=media_category, downloader=downloader):
# 下载成功 # 下载成功
logger.info(f"{context.torrent_info.title} 添加下载成功") logger.info(f"{context.torrent_info.title} 添加下载成功")
downloaded_list.append(context) downloaded_list.append(context)
@@ -555,7 +557,8 @@ class DownloadChain(ChainBase):
source=source, source=source,
userid=userid, userid=userid,
username=username, username=username,
media_category=media_category media_category=media_category,
downloader=downloader,
) )
else: else:
# 下载 # 下载
@@ -563,7 +566,8 @@ class DownloadChain(ChainBase):
download_id = self.download_single(context, save_path=save_path, download_id = self.download_single(context, save_path=save_path,
channel=channel, source=source, channel=channel, source=source,
userid=userid, username=username, userid=userid, username=username,
media_category=media_category) media_category=media_category,
downloader=downloader)
if download_id: if download_id:
# 下载成功 # 下载成功
@@ -634,7 +638,8 @@ class DownloadChain(ChainBase):
download_id = self.download_single(context, save_path=save_path, download_id = self.download_single(context, save_path=save_path,
channel=channel, source=source, channel=channel, source=source,
userid=userid, username=username, userid=userid, username=username,
media_category=media_category) media_category=media_category,
downloader=downloader)
if download_id: if download_id:
# 下载成功 # 下载成功
logger.info(f"{meta.title} 添加下载成功") logger.info(f"{meta.title} 添加下载成功")
@@ -723,7 +728,8 @@ class DownloadChain(ChainBase):
source=source, source=source,
userid=userid, userid=userid,
username=username, username=username,
media_category=media_category media_category=media_category,
downloader=downloader
) )
if not download_id: if not download_id:
continue continue
+6 -2
View File
@@ -159,6 +159,8 @@ class SubscribeChain(ChainBase):
"search_imdbid") else kwargs.get("search_imdbid"), "search_imdbid") else kwargs.get("search_imdbid"),
'sites': self.__get_default_subscribe_config(mediainfo.type, "sites") or None if not kwargs.get( 'sites': self.__get_default_subscribe_config(mediainfo.type, "sites") or None if not kwargs.get(
"sites") else kwargs.get("sites"), "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': self.__get_default_subscribe_config(mediainfo.type, "save_path") if not kwargs.get(
"save_path") else kwargs.get("save_path") "save_path") else kwargs.get("save_path")
}) })
@@ -394,7 +396,8 @@ class SubscribeChain(ChainBase):
userid=subscribe.username, userid=subscribe.username,
username=subscribe.username, username=subscribe.username,
save_path=subscribe.save_path, 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, userid=subscribe.username,
username=subscribe.username, username=subscribe.username,
save_path=subscribe.save_path, 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, self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo,
downloads=downloads, lefts=lefts) downloads=downloads, lefts=lefts)
+2
View File
@@ -64,6 +64,8 @@ class Subscribe(Base):
username = Column(String) username = Column(String)
# 订阅站点 # 订阅站点
sites = Column(JSON, default=list) sites = Column(JSON, default=list)
# 下载器
downloader = Column(String)
# 是否洗版 # 是否洗版
best_version = Column(Integer, default=0) best_version = Column(Integer, default=0)
# 当前优先级 # 当前优先级
+2
View File
@@ -54,6 +54,8 @@ class Subscribe(BaseModel):
username: Optional[str] = None username: Optional[str] = None
# 订阅站点 # 订阅站点
sites: Optional[List[int]] = [] sites: Optional[List[int]] = []
# 下载器
downloader: Optional[str] = None
# 是否洗版 # 是否洗版
best_version: Optional[int] = 0 best_version: Optional[int] = 0
# 当前优先级 # 当前优先级
+6 -3
View File
@@ -19,10 +19,13 @@ depends_on = None
def upgrade() -> None: def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ### # ### 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)) 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: def downgrade() -> None:
pass pass