Skip to content

Commit

Permalink
update(autofilm.py):优化下载文件逻辑结构
Browse files Browse the repository at this point in the history
  • Loading branch information
Akimio521 committed Jun 21, 2024
1 parent ac0229f commit f6cbfad
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions autofilm.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(self) -> None:
alist_server_password: str = alist_server.get("password")
alist_server_base_path: Optional[str] = alist_server.get("base_path")
alist_server_token: Optional[str] = alist_server.get("token")

alist_server_url = alist_server_url.rstrip("/")
if alist_server_base_path == None or alist_server_base_path == "":
alist_server_base_path = "/"
Expand Down Expand Up @@ -179,25 +179,18 @@ async def _file_process(
logging.debug(
f"{file_output_path.name}创建成功,文件本地目录:{file_output_path.parent}"
)
elif alist_path_cls.name.lower().endswith(self.img_ext) and self.img:
file_output_path.parent.mkdir(parents=True, exist_ok=True)
async with session.get(file_download_url) as resp:
if resp.status == 200:
with file_output_path.open(mode="wb") as f:
f.write(await resp.read())
logging.debug(
f"{file_output_path.name}下载成功,文件本地目录:{file_output_path.parent}"
)
elif alist_path_cls.name.lower().endswith(self.subtitle_ext) and self.subtitle:
file_output_path.parent.mkdir(parents=True, exist_ok=True)
async with session.get(file_download_url) as resp:
if resp.status == 200:
with file_output_path.open(mode="wb") as f:
f.write(await resp.read())
logging.debug(
f"{file_output_path.name}下载成功,文件本地目录:{file_output_path.parent}"
)
elif alist_path_cls.name.lower().endswith("nfo") and self.nfo:
return

if alist_path_cls.name.lower().endswith(self.img_ext) and not self.img:
return
elif (
alist_path_cls.name.lower().endswith(self.subtitle_ext)
and not self.subtitle
):
return
elif alist_path_cls.name.lower().endswith("nfo") and not self.nfo:
return
else:
file_output_path.parent.mkdir(parents=True, exist_ok=True)
async with session.get(file_download_url) as resp:
if resp.status == 200:
Expand Down

0 comments on commit f6cbfad

Please sign in to comment.