mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
fix
This commit is contained in:
@@ -59,6 +59,7 @@ class AddDownloadAction(BaseAction):
|
|||||||
将上下文中的torrents添加到下载任务中
|
将上下文中的torrents添加到下载任务中
|
||||||
"""
|
"""
|
||||||
params = AddDownloadParams(**params)
|
params = AddDownloadParams(**params)
|
||||||
|
_started = False
|
||||||
for t in context.torrents:
|
for t in context.torrents:
|
||||||
if global_vars.is_workflow_stopped(workflow_id):
|
if global_vars.is_workflow_stopped(workflow_id):
|
||||||
break
|
break
|
||||||
@@ -96,6 +97,7 @@ class AddDownloadAction(BaseAction):
|
|||||||
logger.warning(f"{t.meta_info.title} 第 {t.meta_info.begin_season} 季第 {t.meta_info.episode_list} 集已存在,跳过")
|
logger.warning(f"{t.meta_info.title} 第 {t.meta_info.begin_season} 季第 {t.meta_info.episode_list} 集已存在,跳过")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
_started = True
|
||||||
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,
|
||||||
@@ -104,14 +106,14 @@ class AddDownloadAction(BaseAction):
|
|||||||
self._added_downloads.append(did)
|
self._added_downloads.append(did)
|
||||||
# 保存缓存
|
# 保存缓存
|
||||||
self.save_cache(workflow_id, cache_key)
|
self.save_cache(workflow_id, cache_key)
|
||||||
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)} 个下载任务")
|
||||||
context.downloads.extend(
|
context.downloads.extend(
|
||||||
[DownloadTask(download_id=did, downloader=params.downloader) for did in self._added_downloads]
|
[DownloadTask(download_id=did, downloader=params.downloader) for did in self._added_downloads]
|
||||||
)
|
)
|
||||||
|
elif _started:
|
||||||
|
self._has_error = True
|
||||||
|
|
||||||
self.job_done(f"已添加 {len(self._added_downloads)} 个下载任务")
|
self.job_done(f"已添加 {len(self._added_downloads)} 个下载任务")
|
||||||
return context
|
return context
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class AddSubscribeAction(BaseAction):
|
|||||||
"""
|
"""
|
||||||
将medias中的信息添加订阅,如果订阅不存在的话
|
将medias中的信息添加订阅,如果订阅不存在的话
|
||||||
"""
|
"""
|
||||||
|
_started = False
|
||||||
for media in context.medias:
|
for media in context.medias:
|
||||||
if global_vars.is_workflow_stopped(workflow_id):
|
if global_vars.is_workflow_stopped(workflow_id):
|
||||||
break
|
break
|
||||||
@@ -64,6 +65,7 @@ class AddSubscribeAction(BaseAction):
|
|||||||
logger.info(f"{media.title} 已存在订阅")
|
logger.info(f"{media.title} 已存在订阅")
|
||||||
continue
|
continue
|
||||||
# 添加订阅
|
# 添加订阅
|
||||||
|
_started = True
|
||||||
sid, message = self.subscribechain.add(mtype=mediainfo.type,
|
sid, message = self.subscribechain.add(mtype=mediainfo.type,
|
||||||
title=mediainfo.title,
|
title=mediainfo.title,
|
||||||
year=mediainfo.year,
|
year=mediainfo.year,
|
||||||
@@ -76,13 +78,13 @@ class AddSubscribeAction(BaseAction):
|
|||||||
self._added_subscribes.append(sid)
|
self._added_subscribes.append(sid)
|
||||||
# 保存缓存
|
# 保存缓存
|
||||||
self.save_cache(workflow_id, cache_key)
|
self.save_cache(workflow_id, cache_key)
|
||||||
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)} 个订阅")
|
||||||
for sid in self._added_subscribes:
|
for sid in self._added_subscribes:
|
||||||
context.subscribes.append(self.subscribeoper.get(sid))
|
context.subscribes.append(self.subscribeoper.get(sid))
|
||||||
|
elif _started:
|
||||||
|
self._has_error = True
|
||||||
|
|
||||||
self.job_done(f"已添加 {len(self._added_subscribes)} 个订阅")
|
self.job_done(f"已添加 {len(self._added_subscribes)} 个订阅")
|
||||||
return context
|
return context
|
||||||
|
|||||||
+37
-33
@@ -28,8 +28,8 @@ class FetchMediasAction(BaseAction):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_inner_sources = []
|
_inner_sources = []
|
||||||
|
|
||||||
_medias = []
|
_medias = []
|
||||||
|
_has_error = False
|
||||||
|
|
||||||
def __init__(self, action_id: str):
|
def __init__(self, action_id: str):
|
||||||
super().__init__(action_id)
|
super().__init__(action_id)
|
||||||
@@ -115,7 +115,7 @@ class FetchMediasAction(BaseAction):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True if self._medias else False
|
return self._has_error
|
||||||
|
|
||||||
def __get_source(self, source: str):
|
def __get_source(self, source: str):
|
||||||
"""
|
"""
|
||||||
@@ -131,37 +131,41 @@ class FetchMediasAction(BaseAction):
|
|||||||
获取媒体数据,填充到medias
|
获取媒体数据,填充到medias
|
||||||
"""
|
"""
|
||||||
params = FetchMediasParams(**params)
|
params = FetchMediasParams(**params)
|
||||||
if params.source_type == "ranking":
|
try:
|
||||||
for name in params.sources:
|
if params.source_type == "ranking":
|
||||||
if global_vars.is_workflow_stopped(workflow_id):
|
for name in params.sources:
|
||||||
break
|
if global_vars.is_workflow_stopped(workflow_id):
|
||||||
source = self.__get_source(name)
|
break
|
||||||
if not source:
|
source = self.__get_source(name)
|
||||||
continue
|
if not source:
|
||||||
logger.info(f"获取媒体数据 {source} ...")
|
continue
|
||||||
results = []
|
logger.info(f"获取媒体数据 {source} ...")
|
||||||
if source.get("func"):
|
results = []
|
||||||
results = source['func']()
|
if source.get("func"):
|
||||||
else:
|
results = source['func']()
|
||||||
# 调用内部API获取数据
|
else:
|
||||||
api_url = f"http://127.0.0.1:{settings.PORT}/api/v1/{source['api_path']}?token={settings.API_TOKEN}"
|
# 调用内部API获取数据
|
||||||
res = RequestUtils(timeout=15).post_res(api_url)
|
api_url = f"http://127.0.0.1:{settings.PORT}/api/v1/{source['api_path']}?token={settings.API_TOKEN}"
|
||||||
if res:
|
res = RequestUtils(timeout=15).post_res(api_url)
|
||||||
results = res.json()
|
if res:
|
||||||
if results:
|
results = res.json()
|
||||||
logger.info(f"{name} 获取到 {len(results)} 条数据")
|
if results:
|
||||||
self._medias.extend([MediaInfo(**r) for r in results])
|
logger.info(f"{name} 获取到 {len(results)} 条数据")
|
||||||
else:
|
self._medias.extend([MediaInfo(**r) for r in results])
|
||||||
logger.error(f"{name} 获取数据失败")
|
else:
|
||||||
else:
|
logger.error(f"{name} 获取数据失败")
|
||||||
# 调用内部API获取数据
|
else:
|
||||||
api_url = f"http://127.0.0.1:{settings.PORT}{params.api_path}?token={settings.API_TOKEN}"
|
# 调用内部API获取数据
|
||||||
res = RequestUtils(timeout=15).post_res(api_url)
|
api_url = f"http://127.0.0.1:{settings.PORT}{params.api_path}?token={settings.API_TOKEN}"
|
||||||
if res:
|
res = RequestUtils(timeout=15).post_res(api_url)
|
||||||
results = res.json()
|
if res:
|
||||||
if results:
|
results = res.json()
|
||||||
logger.info(f"{params.api_path} 获取到 {len(results)} 条数据")
|
if results:
|
||||||
self._medias.extend([MediaInfo(**r) for r in results])
|
logger.info(f"{params.api_path} 获取到 {len(results)} 条数据")
|
||||||
|
self._medias.extend([MediaInfo(**r) for r in results])
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取媒体数据失败: {e}")
|
||||||
|
self._has_error = True
|
||||||
|
|
||||||
if self._medias:
|
if self._medias:
|
||||||
context.medias.extend(self._medias)
|
context.medias.extend(self._medias)
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ class ScrapeFileAction(BaseAction):
|
|||||||
"""
|
"""
|
||||||
刮削fileitems中的所有文件
|
刮削fileitems中的所有文件
|
||||||
"""
|
"""
|
||||||
|
# 失败次数
|
||||||
|
_failed_count = 0
|
||||||
for fileitem in context.fileitems:
|
for fileitem in context.fileitems:
|
||||||
if global_vars.is_workflow_stopped(workflow_id):
|
if global_vars.is_workflow_stopped(workflow_id):
|
||||||
break
|
break
|
||||||
@@ -62,12 +64,12 @@ class ScrapeFileAction(BaseAction):
|
|||||||
# 检查缓存
|
# 检查缓存
|
||||||
cache_key = f"{fileitem.path}"
|
cache_key = f"{fileitem.path}"
|
||||||
if self.check_cache(workflow_id, cache_key):
|
if self.check_cache(workflow_id, cache_key):
|
||||||
logger.info(f"{fileitem.path} 已刮削,跳过")
|
logger.info(f"{fileitem.path} 已刮削过,跳过")
|
||||||
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
|
_failed_count += 1
|
||||||
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)
|
||||||
@@ -75,5 +77,8 @@ class ScrapeFileAction(BaseAction):
|
|||||||
# 保存缓存
|
# 保存缓存
|
||||||
self.save_cache(workflow_id, cache_key)
|
self.save_cache(workflow_id, cache_key)
|
||||||
|
|
||||||
self.job_done(f"成功刮削了 {len(self._scraped_files)} 个文件")
|
if not self._scraped_files and _failed_count:
|
||||||
|
self._has_error = True
|
||||||
|
|
||||||
|
self.job_done(f"成功刮削 {len(self._scraped_files)} 个文件,失败 {_failed_count} 个")
|
||||||
return context
|
return context
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ class TransferFileAction(BaseAction):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
params = TransferFileParams(**params)
|
params = TransferFileParams(**params)
|
||||||
|
# 失败次数
|
||||||
|
_failed_count = 0
|
||||||
if params.source == "downloads":
|
if params.source == "downloads":
|
||||||
# 从下载任务中整理文件
|
# 从下载任务中整理文件
|
||||||
for download in context.downloads:
|
for download in context.downloads:
|
||||||
@@ -92,7 +94,7 @@ 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
|
_failed_count += 1
|
||||||
logger.error(f"整理文件 {download.path} 失败: {errmsg}")
|
logger.error(f"整理文件 {download.path} 失败: {errmsg}")
|
||||||
continue
|
continue
|
||||||
logger.info(f"整理文件 {download.path} 完成")
|
logger.info(f"整理文件 {download.path} 完成")
|
||||||
@@ -116,7 +118,7 @@ class TransferFileAction(BaseAction):
|
|||||||
state, errmsg = self.transferchain.do_transfer(fileitem, background=False,
|
state, errmsg = self.transferchain.do_transfer(fileitem, background=False,
|
||||||
continue_callback=check_continue)
|
continue_callback=check_continue)
|
||||||
if not state:
|
if not state:
|
||||||
self._has_error = True
|
_failed_count += 1
|
||||||
logger.error(f"整理文件 {fileitem.path} 失败: {errmsg}")
|
logger.error(f"整理文件 {fileitem.path} 失败: {errmsg}")
|
||||||
continue
|
continue
|
||||||
logger.info(f"整理文件 {fileitem.path} 完成")
|
logger.info(f"整理文件 {fileitem.path} 完成")
|
||||||
@@ -128,6 +130,8 @@ class TransferFileAction(BaseAction):
|
|||||||
|
|
||||||
if self._fileitems:
|
if self._fileitems:
|
||||||
context.fileitems.extend(self._fileitems)
|
context.fileitems.extend(self._fileitems)
|
||||||
|
elif _failed_count:
|
||||||
|
self._has_error = True
|
||||||
|
|
||||||
self.job_done()
|
self.job_done(f"整理成功 {len(self._fileitems)} 个文件,失败 {_failed_count} 个")
|
||||||
return context
|
return context
|
||||||
|
|||||||
Reference in New Issue
Block a user