From e69fa979fb411dc0c55404238520748c81bdadd3 Mon Sep 17 00:00:00 2001 From: Lartza Date: Sun, 1 Mar 2020 20:40:57 +0200 Subject: [PATCH] Actually delete files when a download fails #80 --- mumbleBot.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/mumbleBot.py b/mumbleBot.py index dcc8c6e..e3eb9cd 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -464,20 +464,16 @@ class MumbleBot: self.log.info("bot: download attempts %d / %d" % (i+1, attempts)) try: ydl.extract_info(url) - if os.path.exists(mp3): - if os.stat(mp3).st_size > 0: - music['ready'] = "yes" - download_succeed = True - break - else: - os.remove(mp3) - else: - self.log.error("bot: download failed: file not existed or file size is 0.") + music['ready'] = "yes" + download_succeed = True except: error_traceback = traceback.format_exc() self.log.error("bot: download failed with error:\n %s" % error_traceback) 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')) return False else: