fix actions

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