mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-10 06:09:09 +08:00
fix actions
This commit is contained in:
@@ -23,6 +23,7 @@ class AddDownloadAction(BaseAction):
|
||||
|
||||
# 已添加的下载
|
||||
_added_downloads = []
|
||||
_has_error = False
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -46,7 +47,7 @@ class AddDownloadAction(BaseAction):
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self._added_downloads else False
|
||||
return not self._has_error
|
||||
|
||||
def execute(self, params: dict, context: ActionContext) -> ActionContext:
|
||||
"""
|
||||
@@ -59,6 +60,7 @@ class AddDownloadAction(BaseAction):
|
||||
if not t.media_info:
|
||||
t.media_info = self.mediachain.recognize_media(meta=t.meta_info)
|
||||
if not t.media_info:
|
||||
self._has_error = True
|
||||
logger.warning(f"{t.title} 未识别到媒体信息,无法下载")
|
||||
continue
|
||||
did = self.downloadchain.download_single(context=t,
|
||||
@@ -66,6 +68,8 @@ class AddDownloadAction(BaseAction):
|
||||
save_path=params.save_path)
|
||||
if did:
|
||||
self._added_downloads.append(did)
|
||||
else:
|
||||
self._has_error = True
|
||||
|
||||
if self._added_downloads:
|
||||
logger.info(f"已添加 {len(self._added_downloads)} 个下载任务")
|
||||
|
||||
@@ -20,6 +20,7 @@ class AddSubscribeAction(BaseAction):
|
||||
"""
|
||||
|
||||
_added_subscribes = []
|
||||
_has_error = False
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -43,7 +44,7 @@ class AddSubscribeAction(BaseAction):
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self._added_subscribes else False
|
||||
return not self._has_error
|
||||
|
||||
def execute(self, params: dict, context: ActionContext) -> ActionContext:
|
||||
"""
|
||||
@@ -66,6 +67,8 @@ class AddSubscribeAction(BaseAction):
|
||||
username=settings.SUPERUSER)
|
||||
if sid:
|
||||
self._added_subscribes.append(sid)
|
||||
else:
|
||||
self._has_error = True
|
||||
|
||||
if self._added_subscribes:
|
||||
logger.info(f"已添加 {len(self._added_subscribes)} 个订阅")
|
||||
|
||||
@@ -25,9 +25,9 @@ class FetchMediasAction(BaseAction):
|
||||
获取媒体数据
|
||||
"""
|
||||
|
||||
__inner_sources = []
|
||||
_inner_sources = []
|
||||
|
||||
__medias = []
|
||||
_medias = []
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -113,7 +113,7 @@ class FetchMediasAction(BaseAction):
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self.__medias else False
|
||||
return True if self._medias else False
|
||||
|
||||
def __get_source(self, source: str):
|
||||
"""
|
||||
@@ -145,12 +145,12 @@ class FetchMediasAction(BaseAction):
|
||||
results = res.json()
|
||||
if results:
|
||||
logger.info(f"{name} 获取到 {len(results)} 条数据")
|
||||
self.__medias.extend([MediaInfo(**r) for r in results])
|
||||
self._medias.extend([MediaInfo(**r) for r in results])
|
||||
else:
|
||||
logger.error(f"{name} 获取数据失败")
|
||||
|
||||
if self.__medias:
|
||||
context.medias.extend(self.__medias)
|
||||
if self._medias:
|
||||
context.medias.extend(self._medias)
|
||||
|
||||
self.job_done()
|
||||
return context
|
||||
|
||||
@@ -29,6 +29,7 @@ class FetchRssAction(BaseAction):
|
||||
"""
|
||||
|
||||
_rss_torrents = []
|
||||
_has_error = False
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -52,7 +53,7 @@ class FetchRssAction(BaseAction):
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self._rss_torrents else False
|
||||
return not self._has_error
|
||||
|
||||
def execute(self, params: dict, context: ActionContext) -> ActionContext:
|
||||
"""
|
||||
@@ -74,6 +75,11 @@ class FetchRssAction(BaseAction):
|
||||
proxy=settings.PROXY if params.proxy else None,
|
||||
timeout=params.timeout,
|
||||
headers=headers)
|
||||
if rss_items is None or rss_items is False:
|
||||
logger.error(f'RSS地址 {params.url} 请求失败!')
|
||||
self._has_error = True
|
||||
return context
|
||||
|
||||
if not rss_items:
|
||||
logger.error(f'RSS地址 {params.url} 未获取到RSS数据!')
|
||||
return context
|
||||
|
||||
@@ -47,14 +47,14 @@ class FetchTorrentsAction(BaseAction):
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self._torrents else False
|
||||
return self.done
|
||||
|
||||
def execute(self, params: dict, context: ActionContext) -> ActionContext:
|
||||
"""
|
||||
搜索站点,获取资源列表
|
||||
"""
|
||||
params = FetchTorrentsParams(**params)
|
||||
torrents = self.searchchain.search_by_title(title=params.name, sites=params.sites)
|
||||
torrents = self.searchchain.search_by_title(title=params.name, sites=params.sites, cache_local=False)
|
||||
for torrent in torrents:
|
||||
if params.year and torrent.meta_info.year != params.year:
|
||||
continue
|
||||
|
||||
@@ -4,7 +4,6 @@ from pydantic import Field
|
||||
|
||||
from app.actions import BaseAction
|
||||
from app.schemas import ActionParams, ActionContext
|
||||
from app.schemas.types import MediaType
|
||||
|
||||
|
||||
class FilterMediasParams(ActionParams):
|
||||
@@ -22,7 +21,7 @@ class FilterMediasAction(BaseAction):
|
||||
过滤媒体数据
|
||||
"""
|
||||
|
||||
__medias = []
|
||||
_medias = []
|
||||
|
||||
@classmethod
|
||||
@property
|
||||
@@ -41,7 +40,7 @@ class FilterMediasAction(BaseAction):
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self.__medias else False
|
||||
return self.done
|
||||
|
||||
def execute(self, params: dict, context: ActionContext) -> ActionContext:
|
||||
"""
|
||||
@@ -49,7 +48,7 @@ class FilterMediasAction(BaseAction):
|
||||
"""
|
||||
params = FilterMediasParams(**params)
|
||||
for media in context.medias:
|
||||
if params.type and media.type != MediaType(params.type):
|
||||
if params.type and media.type != params.type:
|
||||
continue
|
||||
if params.category and media.category != params.category:
|
||||
continue
|
||||
@@ -57,10 +56,10 @@ class FilterMediasAction(BaseAction):
|
||||
continue
|
||||
if params.year and media.year != params.year:
|
||||
continue
|
||||
self.__medias.append(media)
|
||||
self._medias.append(media)
|
||||
|
||||
if self.__medias:
|
||||
context.medias = self.__medias
|
||||
if self._medias:
|
||||
context.medias = self._medias
|
||||
|
||||
self.job_done()
|
||||
return context
|
||||
|
||||
@@ -20,7 +20,8 @@ class ScrapeFileAction(BaseAction):
|
||||
刮削文件
|
||||
"""
|
||||
|
||||
__scraped_files = []
|
||||
_scraped_files = []
|
||||
_has_error = False
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -44,24 +45,25 @@ class ScrapeFileAction(BaseAction):
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self.__scraped_files else False
|
||||
return not self._has_error
|
||||
|
||||
def execute(self, params: dict, context: ActionContext) -> ActionContext:
|
||||
"""
|
||||
刮削fileitems中的所有文件
|
||||
"""
|
||||
for fileitem in context.fileitems:
|
||||
if fileitem in self.__scraped_files:
|
||||
if fileitem in self._scraped_files:
|
||||
continue
|
||||
if not self.storagechain.exists(fileitem):
|
||||
continue
|
||||
meta = MetaInfoPath(Path(fileitem.path))
|
||||
mediainfo = self.mediachain.recognize_media(meta)
|
||||
if not mediainfo:
|
||||
self._has_error = True
|
||||
logger.info(f"{fileitem.path} 未识别到媒体信息,无法刮削")
|
||||
continue
|
||||
self.mediachain.scrape_metadata(fileitem=fileitem, meta=meta, mediainfo=mediainfo)
|
||||
self.__scraped_files.append(fileitem)
|
||||
self._scraped_files.append(fileitem)
|
||||
|
||||
self.job_done()
|
||||
return context
|
||||
|
||||
@@ -19,7 +19,8 @@ class TransferFileAction(BaseAction):
|
||||
整理文件
|
||||
"""
|
||||
|
||||
__fileitems = []
|
||||
_fileitems = []
|
||||
_has_error = False
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -43,7 +44,7 @@ class TransferFileAction(BaseAction):
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self.__fileitems else False
|
||||
return not self._has_error
|
||||
|
||||
def execute(self, params: dict, context: ActionContext) -> ActionContext:
|
||||
"""
|
||||
@@ -60,13 +61,14 @@ class TransferFileAction(BaseAction):
|
||||
logger.info(f"开始整理文件 {download.path} ...")
|
||||
state, errmsg = self.transferchain.do_transfer(fileitem, background=False)
|
||||
if not state:
|
||||
self._has_error = True
|
||||
logger.error(f"整理文件 {download.path} 失败: {errmsg}")
|
||||
continue
|
||||
logger.info(f"整理文件 {download.path} 完成")
|
||||
self.__fileitems.append(fileitem)
|
||||
self._fileitems.append(fileitem)
|
||||
|
||||
if self.__fileitems:
|
||||
context.fileitems.extend(self.__fileitems)
|
||||
if self._fileitems:
|
||||
context.fileitems.extend(self._fileitems)
|
||||
|
||||
self.job_done()
|
||||
return context
|
||||
|
||||
@@ -217,7 +217,7 @@ class WorkflowChain(ChainBase):
|
||||
executor.execute()
|
||||
|
||||
if not executor.success:
|
||||
logger.info(f"工作流 {workflow.name} 执行失败:{executor.errmsg}!")
|
||||
logger.info(f"工作流 {workflow.name} 执行失败:{executor.errmsg}")
|
||||
self.workflowoper.fail(workflow_id, result=executor.errmsg)
|
||||
return False, executor.errmsg
|
||||
else:
|
||||
|
||||
@@ -225,27 +225,27 @@ class RssHelper:
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def parse(url, proxy: bool = False, timeout: int = 15, headers: dict = None) -> Union[List[dict], None]:
|
||||
def parse(url, proxy: bool = False, timeout: int = 15, headers: dict = None) -> Union[List[dict], None, bool]:
|
||||
"""
|
||||
解析RSS订阅URL,获取RSS中的种子信息
|
||||
:param url: RSS地址
|
||||
:param proxy: 是否使用代理
|
||||
:param timeout: 请求超时
|
||||
:param headers: 自定义请求头
|
||||
:return: 种子信息列表,如为None代表Rss过期
|
||||
:return: 种子信息列表,如为None代表Rss过期,如果为False则为错误
|
||||
"""
|
||||
# 开始处理
|
||||
ret_array: list = []
|
||||
if not url:
|
||||
return []
|
||||
return False
|
||||
try:
|
||||
ret = RequestUtils(proxies=settings.PROXY if proxy else None,
|
||||
timeout=timeout, headers=headers).get_res(url)
|
||||
if not ret:
|
||||
return []
|
||||
return False
|
||||
except Exception as err:
|
||||
logger.error(f"获取RSS失败:{str(err)} - {traceback.format_exc()}")
|
||||
return []
|
||||
return False
|
||||
if ret:
|
||||
ret_xml = ""
|
||||
try:
|
||||
@@ -322,6 +322,7 @@ class RssHelper:
|
||||
]
|
||||
if ret_xml in _rss_expired_msg:
|
||||
return None
|
||||
return False
|
||||
return ret_array
|
||||
|
||||
def get_rss_link(self, url: str, cookie: str, ua: str, proxy: bool = False) -> Tuple[str, str]:
|
||||
|
||||
Reference in New Issue
Block a user