Create directory only after download is ready
Avoid creating junky empty dirs on failed downloads
This commit is contained in:
parent
a9f54b8f42
commit
2d82329e4f
7
c3dbdl
7
c3dbdl
|
@ -109,9 +109,6 @@ def downloadSong(destination, filename, entry):
|
|||
download_filename = f"{destination}/{download_filename}"
|
||||
download_path = '/'.join(f"{download_filename}".split('/')[0:-1])
|
||||
|
||||
if not os.path.exists(download_path):
|
||||
os.makedirs(download_path)
|
||||
|
||||
if os.path.exists(download_filename):
|
||||
click.echo(f"File exists at {download_filename}")
|
||||
return None
|
||||
|
@ -135,6 +132,10 @@ def downloadSong(destination, filename, entry):
|
|||
else:
|
||||
code = "-1"
|
||||
raise HTTPError(download_url, code, "", None, None)
|
||||
|
||||
if not os.path.exists(download_path):
|
||||
os.makedirs(download_path)
|
||||
|
||||
with open(download_filename, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
|
|
Loading…
Reference in New Issue