Use tempdir for downloading
This commit is contained in:
22
scdl/scdl.py
22
scdl/scdl.py
@@ -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", str(temp_path), "-loglevel", "error"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = p.communicate()
|
||||
if stderr:
|
||||
logger.error(stderr.decode("utf-8"))
|
||||
else:
|
||||
shutil.move(temp_path, filename_path)
|
||||
|
||||
p = subprocess.Popen(
|
||||
["ffmpeg", "-i", url, "-c", "copy", filename_path, "-loglevel", "error"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = p.communicate()
|
||||
if stderr:
|
||||
logger.error(stderr.decode("utf-8"))
|
||||
return (filename, False)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user