Skip to content

Commit

Permalink
fix absolute output path problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu1845 committed Nov 17, 2021
1 parent b51b247 commit 63a6d41
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions twspace_dl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def metadata(self) -> dict:
return metadata

@cached_property
def filename(self):
def filename(self) -> str:
format_info = FormatInfo()
format_info.set_info(self.metadata)
filename = format_info.format(self.format_str)
Expand Down Expand Up @@ -267,10 +267,11 @@ def playlist_text(self) -> str:

def write_playlist(self, save_dir: str = "./") -> None:
"""Write the modified playlist for external use"""
filename = os.path.join(save_dir, shlex.quote(self.filename) + ".m3u8")
with open(filename, "w", encoding="utf-8") as stream_io:
filename = shlex.quote(os.path.basename(self.filename)) + ".m3u8"
path = os.path.join(save_dir, filename)
with open(path, "w", encoding="utf-8") as stream_io:
stream_io.write(self.playlist_text)
logging.info(f"{filename} written to disk")
logging.info(f"{path} written to disk")

def download(self) -> None:
"""Download a twitter space"""
Expand Down Expand Up @@ -301,16 +302,17 @@ def download(self) -> None:
]
cmd_base = [shlex.quote(element) for element in cmd_base]

filename_m3u8 = os.path.join("tmp", shlex.quote(self.filename) + ".m3u8")
filename_old = os.path.join("tmp", (self.filename) + ".m4a")
filename = shlex.quote(os.path.basename(self.filename))
filename_m3u8 = os.path.join("tmp", filename + ".m3u8")
filename_old = os.path.join("tmp", filename + ".m4a")
cmd_old = cmd_base.copy()
cmd_old.insert(1, "-protocol_whitelist")
cmd_old.insert(2, "file,https,tls,tcp")
cmd_old.insert(8, filename_m3u8)
cmd_old.append(filename_old)

if state == "Running":
filename_new = os.path.join("tmp", (self.filename) + "_new.m4a")
filename_new = os.path.join("tmp", filename + "_new.m4a")
cmd_new = cmd_base.copy()
cmd_new.insert(6, (self.dyn_url))
cmd_new.append(filename_new)
Expand Down Expand Up @@ -340,9 +342,7 @@ def download(self) -> None:
subprocess.run(cmd_final, check=True)
else:
subprocess.run(cmd_old, check=True)
shutil.move(
os.path.join("tmp", self.filename + ".m4a"), self.filename + ".m4a"
)
shutil.move(filename_old, self.filename + ".m4a")

logging.info("Finished downloading")

Expand Down

0 comments on commit 63a6d41

Please sign in to comment.