mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-26 10:40:32 +08:00
feat:actions增加识别选项
This commit is contained in:
@@ -17,6 +17,7 @@ class AddDownloadParams(ActionParams):
|
|||||||
"""
|
"""
|
||||||
downloader: Optional[str] = Field(None, description="下载器")
|
downloader: Optional[str] = Field(None, description="下载器")
|
||||||
save_path: Optional[str] = Field(None, description="保存路径")
|
save_path: Optional[str] = Field(None, description="保存路径")
|
||||||
|
labels: Optional[str] = Field(None, description="标签(,分隔)")
|
||||||
only_lack: Optional[bool] = Field(False, description="仅下载缺失的资源")
|
only_lack: Optional[bool] = Field(False, description="仅下载缺失的资源")
|
||||||
|
|
||||||
|
|
||||||
@@ -92,7 +93,8 @@ class AddDownloadAction(BaseAction):
|
|||||||
|
|
||||||
did = self.downloadchain.download_single(context=t,
|
did = self.downloadchain.download_single(context=t,
|
||||||
downloader=params.downloader,
|
downloader=params.downloader,
|
||||||
save_path=params.save_path)
|
save_path=params.save_path,
|
||||||
|
label=params.labels)
|
||||||
if did:
|
if did:
|
||||||
self._added_downloads.append(did)
|
self._added_downloads.append(did)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class FetchRssParams(ActionParams):
|
|||||||
content_type: Optional[str] = Field(None, description="Content-Type")
|
content_type: Optional[str] = Field(None, description="Content-Type")
|
||||||
referer: Optional[str] = Field(None, description="Referer")
|
referer: Optional[str] = Field(None, description="Referer")
|
||||||
ua: Optional[str] = Field(None, description="User-Agent")
|
ua: Optional[str] = Field(None, description="User-Agent")
|
||||||
|
match_media: Optional[str] = Field(None, description="匹配媒体信息")
|
||||||
|
|
||||||
|
|
||||||
class FetchRssAction(BaseAction):
|
class FetchRssAction(BaseAction):
|
||||||
@@ -98,10 +99,12 @@ class FetchRssAction(BaseAction):
|
|||||||
pubdate=item["pubdate"].strftime("%Y-%m-%d %H:%M:%S") if item.get("pubdate") else None,
|
pubdate=item["pubdate"].strftime("%Y-%m-%d %H:%M:%S") if item.get("pubdate") else None,
|
||||||
)
|
)
|
||||||
meta = MetaInfo(title=torrentinfo.title, subtitle=torrentinfo.description)
|
meta = MetaInfo(title=torrentinfo.title, subtitle=torrentinfo.description)
|
||||||
mediainfo = self.chain.recognize_media(meta)
|
mediainfo = None
|
||||||
if not mediainfo:
|
if params.match_media:
|
||||||
logger.warning(f"{torrentinfo.title} 未识别到媒体信息")
|
mediainfo = self.chain.recognize_media(meta)
|
||||||
continue
|
if not mediainfo:
|
||||||
|
logger.warning(f"{torrentinfo.title} 未识别到媒体信息")
|
||||||
|
continue
|
||||||
self._rss_torrents.append(Context(meta_info=meta, media_info=mediainfo, torrent_info=torrentinfo))
|
self._rss_torrents.append(Context(meta_info=meta, media_info=mediainfo, torrent_info=torrentinfo))
|
||||||
|
|
||||||
if self._rss_torrents:
|
if self._rss_torrents:
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class FetchTorrentsParams(ActionParams):
|
|||||||
type: Optional[str] = Field(None, description="资源类型 (电影/电视剧)")
|
type: Optional[str] = Field(None, description="资源类型 (电影/电视剧)")
|
||||||
season: Optional[int] = Field(None, description="季度")
|
season: Optional[int] = Field(None, description="季度")
|
||||||
sites: Optional[List[int]] = Field([], description="站点列表")
|
sites: Optional[List[int]] = Field([], description="站点列表")
|
||||||
|
match_media: Optional[bool] = Field(False, description="匹配媒体信息")
|
||||||
|
|
||||||
|
|
||||||
class FetchTorrentsAction(BaseAction):
|
class FetchTorrentsAction(BaseAction):
|
||||||
@@ -71,10 +72,11 @@ class FetchTorrentsAction(BaseAction):
|
|||||||
if params.season and torrent.meta_info.begin_season != params.season:
|
if params.season and torrent.meta_info.begin_season != params.season:
|
||||||
continue
|
continue
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
torrent.media_info = self.searchchain.recognize_media(torrent.meta_info)
|
if params.match_media:
|
||||||
if not torrent.media_info:
|
torrent.media_info = self.searchchain.recognize_media(torrent.meta_info)
|
||||||
logger.warning(f"{torrent.torrent_info.title} 未识别到媒体信息")
|
if not torrent.media_info:
|
||||||
continue
|
logger.warning(f"{torrent.torrent_info.title} 未识别到媒体信息")
|
||||||
|
continue
|
||||||
self._torrents.append(torrent)
|
self._torrents.append(torrent)
|
||||||
else:
|
else:
|
||||||
# 搜索媒体列表
|
# 搜索媒体列表
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
torrent_list=torrent_list, mediainfo=mediainfo)
|
torrent_list=torrent_list, mediainfo=mediainfo)
|
||||||
|
|
||||||
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
||||||
episodes: Set[int] = None, category: str = None,
|
episodes: Set[int] = None, category: str = None, label: str = None,
|
||||||
downloader: str = None
|
downloader: str = None
|
||||||
) -> Optional[Tuple[Optional[str], Optional[str], Optional[str], str]]:
|
) -> Optional[Tuple[Optional[str], Optional[str], Optional[str], str]]:
|
||||||
"""
|
"""
|
||||||
@@ -357,11 +357,12 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
:param cookie: cookie
|
:param cookie: cookie
|
||||||
:param episodes: 需要下载的集数
|
:param episodes: 需要下载的集数
|
||||||
:param category: 种子分类
|
:param category: 种子分类
|
||||||
|
:param label: 标签
|
||||||
:param downloader: 下载器
|
:param downloader: 下载器
|
||||||
:return: 下载器名称、种子Hash、种子文件布局、错误原因
|
:return: 下载器名称、种子Hash、种子文件布局、错误原因
|
||||||
"""
|
"""
|
||||||
return self.run_module("download", content=content, download_dir=download_dir,
|
return self.run_module("download", content=content, download_dir=download_dir,
|
||||||
cookie=cookie, episodes=episodes, category=category,
|
cookie=cookie, episodes=episodes, category=category, label=label,
|
||||||
downloader=downloader)
|
downloader=downloader)
|
||||||
|
|
||||||
def download_added(self, context: Context, download_dir: Path, torrent_path: Path = None) -> None:
|
def download_added(self, context: Context, download_dir: Path, torrent_path: Path = None) -> None:
|
||||||
|
|||||||
@@ -209,7 +209,8 @@ class DownloadChain(ChainBase):
|
|||||||
save_path: str = None,
|
save_path: str = None,
|
||||||
userid: Union[str, int] = None,
|
userid: Union[str, int] = None,
|
||||||
username: str = None,
|
username: str = None,
|
||||||
media_category: str = None) -> Optional[str]:
|
media_category: str = None,
|
||||||
|
label: str = None) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
下载及发送通知
|
下载及发送通知
|
||||||
:param context: 资源上下文
|
:param context: 资源上下文
|
||||||
@@ -222,6 +223,7 @@ class DownloadChain(ChainBase):
|
|||||||
:param userid: 用户ID
|
:param userid: 用户ID
|
||||||
:param username: 调用下载的用户名/插件名
|
:param username: 调用下载的用户名/插件名
|
||||||
:param media_category: 自定义媒体类别
|
:param media_category: 自定义媒体类别
|
||||||
|
:param label: 自定义标签
|
||||||
"""
|
"""
|
||||||
# 发送资源下载事件,允许外部拦截下载
|
# 发送资源下载事件,允许外部拦截下载
|
||||||
event_data = ResourceDownloadEventData(
|
event_data = ResourceDownloadEventData(
|
||||||
@@ -310,6 +312,7 @@ class DownloadChain(ChainBase):
|
|||||||
episodes=episodes,
|
episodes=episodes,
|
||||||
download_dir=download_dir,
|
download_dir=download_dir,
|
||||||
category=_media.category,
|
category=_media.category,
|
||||||
|
label=label,
|
||||||
downloader=downloader or _site_downloader)
|
downloader=downloader or _site_downloader)
|
||||||
if result:
|
if result:
|
||||||
_downloader, _hash, _layout, error_msg = result
|
_downloader, _hash, _layout, error_msg = result
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import json
|
import json
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
from urllib.parse import urljoin
|
|
||||||
|
|
||||||
from app.modules.indexer.parser import SiteParserBase, SiteSchema
|
from app.modules.indexer.parser import SiteParserBase, SiteSchema
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
@@ -145,28 +144,7 @@ class HDDolbySiteUserInfo(SiteParserBase):
|
|||||||
"""
|
"""
|
||||||
解析未读消息链接,这里直接读出详情
|
解析未读消息链接,这里直接读出详情
|
||||||
"""
|
"""
|
||||||
if not html_text:
|
pass
|
||||||
return None
|
|
||||||
messages_info = json.loads(html_text)
|
|
||||||
if not messages_info or messages_info.get("code") != "0":
|
|
||||||
return None
|
|
||||||
# TODO
|
|
||||||
messages = messages_info.get("data", {}).get("data", [])
|
|
||||||
for message in messages:
|
|
||||||
if not message.get("unread"):
|
|
||||||
continue
|
|
||||||
head = message.get("title")
|
|
||||||
date = message.get("createdDate")
|
|
||||||
content = message.get("context")
|
|
||||||
if head and date and content:
|
|
||||||
self.message_unread_contents.append((head, date, content))
|
|
||||||
# 设置已读
|
|
||||||
self._get_page_content(
|
|
||||||
url=urljoin(self._base_url, f"api/msg/markRead"),
|
|
||||||
params={"msgId": message.get("id")}
|
|
||||||
)
|
|
||||||
# 是否存在下页数据
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _parse_message_content(self, html_text) -> Tuple[Optional[str], Optional[str], Optional[str]]:
|
def _parse_message_content(self, html_text) -> Tuple[Optional[str], Optional[str], Optional[str]]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
|
|||||||
server.reconnect()
|
server.reconnect()
|
||||||
|
|
||||||
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
||||||
episodes: Set[int] = None, category: str = None,
|
episodes: Set[int] = None, category: str = None, label: str = None,
|
||||||
downloader: str = None) -> Optional[Tuple[Optional[str], Optional[str], Optional[str], str]]:
|
downloader: str = None) -> Optional[Tuple[Optional[str], Optional[str], Optional[str], str]]:
|
||||||
"""
|
"""
|
||||||
根据种子文件,选择并添加下载任务
|
根据种子文件,选择并添加下载任务
|
||||||
@@ -87,6 +87,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
|
|||||||
:param cookie: cookie
|
:param cookie: cookie
|
||||||
:param episodes: 需要下载的集数
|
:param episodes: 需要下载的集数
|
||||||
:param category: 分类
|
:param category: 分类
|
||||||
|
:param label: 标签
|
||||||
:param downloader: 下载器
|
:param downloader: 下载器
|
||||||
:return: 下载器名称、种子Hash、种子文件布局、错误原因
|
:return: 下载器名称、种子Hash、种子文件布局、错误原因
|
||||||
"""
|
"""
|
||||||
@@ -118,7 +119,9 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
|
|||||||
|
|
||||||
# 生成随机Tag
|
# 生成随机Tag
|
||||||
tag = StringUtils.generate_random_str(10)
|
tag = StringUtils.generate_random_str(10)
|
||||||
if settings.TORRENT_TAG:
|
if label:
|
||||||
|
tags = label.split(',') + [tag]
|
||||||
|
elif settings.TORRENT_TAG:
|
||||||
tags = [tag, settings.TORRENT_TAG]
|
tags = [tag, settings.TORRENT_TAG]
|
||||||
else:
|
else:
|
||||||
tags = [tag]
|
tags = [tag]
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
|
|||||||
server.reconnect()
|
server.reconnect()
|
||||||
|
|
||||||
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
||||||
episodes: Set[int] = None, category: str = None,
|
episodes: Set[int] = None, category: str = None, label: str = None,
|
||||||
downloader: str = None) -> Optional[Tuple[Optional[str], Optional[str], Optional[str], str]]:
|
downloader: str = None) -> Optional[Tuple[Optional[str], Optional[str], Optional[str], str]]:
|
||||||
"""
|
"""
|
||||||
根据种子文件,选择并添加下载任务
|
根据种子文件,选择并添加下载任务
|
||||||
@@ -88,6 +88,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
|
|||||||
:param cookie: cookie
|
:param cookie: cookie
|
||||||
:param episodes: 需要下载的集数
|
:param episodes: 需要下载的集数
|
||||||
:param category: 分类,TR中未使用
|
:param category: 分类,TR中未使用
|
||||||
|
:param label: 标签
|
||||||
:param downloader: 下载器
|
:param downloader: 下载器
|
||||||
:return: 下载器名称、种子Hash、种子文件布局、错误原因
|
:return: 下载器名称、种子Hash、种子文件布局、错误原因
|
||||||
"""
|
"""
|
||||||
@@ -118,8 +119,11 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
|
|||||||
|
|
||||||
# 如果要选择文件则先暂停
|
# 如果要选择文件则先暂停
|
||||||
is_paused = True if episodes else False
|
is_paused = True if episodes else False
|
||||||
|
|
||||||
# 标签
|
# 标签
|
||||||
if settings.TORRENT_TAG:
|
if label:
|
||||||
|
labels = label.split(',')
|
||||||
|
elif settings.TORRENT_TAG:
|
||||||
labels = [settings.TORRENT_TAG]
|
labels = [settings.TORRENT_TAG]
|
||||||
else:
|
else:
|
||||||
labels = None
|
labels = None
|
||||||
|
|||||||
Reference in New Issue
Block a user