Merge pull request #86 from Lartza/clean-download-fail
Actually delete files when a download fails to fix #80
This commit is contained in:
commit
9c62abfeb2
10
mumbleBot.py
10
mumbleBot.py
@ -464,20 +464,16 @@ class MumbleBot:
|
|||||||
self.log.info("bot: download attempts %d / %d" % (i+1, attempts))
|
self.log.info("bot: download attempts %d / %d" % (i+1, attempts))
|
||||||
try:
|
try:
|
||||||
ydl.extract_info(url)
|
ydl.extract_info(url)
|
||||||
if os.path.exists(mp3):
|
|
||||||
if os.stat(mp3).st_size > 0:
|
|
||||||
music['ready'] = "yes"
|
music['ready'] = "yes"
|
||||||
download_succeed = True
|
download_succeed = True
|
||||||
break
|
|
||||||
else:
|
|
||||||
os.remove(mp3)
|
|
||||||
else:
|
|
||||||
self.log.error("bot: download failed: file not existed or file size is 0.")
|
|
||||||
except:
|
except:
|
||||||
error_traceback = traceback.format_exc()
|
error_traceback = traceback.format_exc()
|
||||||
self.log.error("bot: download failed with error:\n %s" % error_traceback)
|
self.log.error("bot: download failed with error:\n %s" % error_traceback)
|
||||||
|
|
||||||
if not download_succeed:
|
if not download_succeed:
|
||||||
|
for f in [mp3, path.replace(".%(ext)s", ".jpg"), path.replace(".%(ext)s", ".m4a")]:
|
||||||
|
if os.path.exists(f):
|
||||||
|
os.remove(f)
|
||||||
self.send_msg(constants.strings('unable_download'))
|
self.send_msg(constants.strings('unable_download'))
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user