Skip to content

Commit

Permalink
fix #4609
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed May 8, 2023
1 parent 01b322d commit b65e808
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions app/media/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,23 @@ def __gen_tv_episode_nfo_file(self,
# 保存文件
self.__save_nfo(doc, os.path.join(out_path, os.path.join(out_path, "%s.nfo" % file_name)))

def __save_remove_file(self, out_file, content):
"""
保存文件到远端
"""
temp_file = os.path.join(self._temp_path, out_file[1:])
temp_file_dir = os.path.dirname(temp_file)
if not os.path.exists(temp_file_dir):
os.makedirs(temp_file_dir)
with open(temp_file, "wb") as f:
f.write(content)
if self._rmt_mode in [RmtMode.RCLONE, RmtMode.RCLONECOPY]:
SystemUtils.rclone_move(temp_file, out_file)
elif self._rmt_mode in [RmtMode.MINIO, RmtMode.MINIOCOPY]:
SystemUtils.minio_move(temp_file, out_file)
else:
SystemUtils.move(temp_file, out_file)

@retry(RequestException, logger=log)
def __save_image(self, url, out_path, itype='', force=False):
"""
Expand All @@ -395,18 +412,7 @@ def __save_image(self, url, out_path, itype='', force=False):
if r:
# 下载到temp目录,远程则先存到temp再远程移动,本地则直接保存
if self._rmt_mode in ModuleConf.REMOTE_RMT_MODES:
temp_img = os.path.join(self._temp_path, image_path)
temp_img_dir = os.path.dirname(temp_img)
if not os.path.exists(temp_img_dir):
os.makedirs(temp_img_dir)
with open(file=temp_img, mode="wb") as img:
img.write(r.content)
if self._rmt_mode in [RmtMode.RCLONE, RmtMode.RCLONECOPY]:
SystemUtils.rclone_move(temp_img, image_path)
elif self._rmt_mode in [RmtMode.MINIO, RmtMode.MINIOCOPY]:
SystemUtils.minio_move(temp_img, image_path)
else:
SystemUtils.move(temp_img, image_path)
self.__save_remove_file(image_path, r.content)
else:
with open(file=image_path, mode="wb") as img:
img.write(r.content)
Expand All @@ -423,18 +429,7 @@ def __save_nfo(self, doc, out_file):
xml_str = doc.toprettyxml(indent=" ", encoding="utf-8")
# 下载到temp目录,远程则先存到temp再远程移动,本地则直接保存
if self._rmt_mode in ModuleConf.REMOTE_RMT_MODES:
temp_file = os.path.join(self._temp_path, out_file)
temp_file_dir = os.path.dirname(temp_file)
if not os.path.exists(temp_file_dir):
os.makedirs(temp_file_dir)
with open(temp_file, "wb") as xml_file:
xml_file.write(xml_str)
if self._rmt_mode in [RmtMode.RCLONE, RmtMode.RCLONECOPY]:
SystemUtils.rclone_move(temp_file, out_file)
elif self._rmt_mode in [RmtMode.MINIO, RmtMode.MINIOCOPY]:
SystemUtils.minio_move(temp_file, out_file)
else:
SystemUtils.move(temp_file, out_file)
self.__save_remove_file(out_file, xml_str)
else:
with open(out_file, "wb") as xml_file:
xml_file.write(xml_str)
Expand Down

0 comments on commit b65e808

Please sign in to comment.