Use tempdir for downloading

This commit is contained in:
7x11x13
2024-06-20 14:43:56 -04:00
parent b9e2e6cc38
commit 832ac2188e

View File

@@ -711,15 +711,21 @@ def download_hls(client: SoundCloud, track: BasicTrack, title: str, playlist_inf
# Get the requests stream
url = get_transcoding_m3u8(client, transcoding, **kwargs)
filename_path = os.path.abspath(filename)
_, ext = os.path.splitext(filename)
with tempfile.TemporaryDirectory() as tmpdir:
temp_path = pathlib.Path(tmpdir).joinpath("scdl-download" + ext).absolute()
p = subprocess.Popen(
["ffmpeg", "-i", url, "-c", "copy", filename_path, "-loglevel", "error"],
["ffmpeg", "-i", url, "-c", "copy", str(temp_path), "-loglevel", "error"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate()
if stderr:
logger.error(stderr.decode("utf-8"))
else:
shutil.move(temp_path, filename_path)
return (filename, False)