verify downloaded size matches content-length (#249)
parent
40dec6ea02
commit
da72588ff6
|
@ -507,6 +507,7 @@ def download_track(track, playlist_name=None, playlist_file=None):
|
||||||
logging.info('{0} too large, skipping'.format(title))
|
logging.info('{0} too large, skipping'.format(title))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
received=0
|
||||||
with temp as f:
|
with temp as f:
|
||||||
for chunk in progress.bar(
|
for chunk in progress.bar(
|
||||||
r.iter_content(chunk_size=1024),
|
r.iter_content(chunk_size=1024),
|
||||||
|
@ -514,9 +515,14 @@ def download_track(track, playlist_name=None, playlist_file=None):
|
||||||
hide=True if arguments["--hide-progress"] else False
|
hide=True if arguments["--hide-progress"] else False
|
||||||
):
|
):
|
||||||
if chunk:
|
if chunk:
|
||||||
|
received+=len(chunk)
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
|
if received != total_length:
|
||||||
|
logger.error('connection closed prematurely, download incomplete')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
shutil.move(temp.name, os.path.join(os.getcwd(), filename))
|
shutil.move(temp.name, os.path.join(os.getcwd(), filename))
|
||||||
if filename.endswith('.mp3') or filename.endswith('.m4a'):
|
if filename.endswith('.mp3') or filename.endswith('.m4a'):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue