fix: process error from youtube-dl correctly. #80
This commit is contained in:
parent
f90482ab3c
commit
b640ff4721
@ -48,6 +48,9 @@ logfile =
|
|||||||
# in MB, 0 for no cache, -1 for unlimited size
|
# in MB, 0 for no cache, -1 for unlimited size
|
||||||
tmp_folder_max_size = 10
|
tmp_folder_max_size = 10
|
||||||
|
|
||||||
|
# how many times the bot will try to download an item
|
||||||
|
download_attempts = 2
|
||||||
|
|
||||||
ignored_folders = tmp
|
ignored_folders = tmp
|
||||||
ignored_files = Thumbs.db
|
ignored_files = Thumbs.db
|
||||||
|
|
||||||
|
@ -53,6 +53,9 @@ port = 64738
|
|||||||
#ignored_folders = tmp
|
#ignored_folders = tmp
|
||||||
#ignored_files = Thumbs.db
|
#ignored_files = Thumbs.db
|
||||||
|
|
||||||
|
# 'download_attempts': how many times the bot will try to download an item
|
||||||
|
#download_attempts = 2
|
||||||
|
|
||||||
# 'auto_check_update': check for updates every time the bot starts
|
# 'auto_check_update': check for updates every time the bot starts
|
||||||
#auto_check_update = True
|
#auto_check_update = True
|
||||||
#pip3_path = venv/bin/pip
|
#pip3_path = venv/bin/pip
|
||||||
|
@ -188,7 +188,8 @@ def get_playlist_info(url, start_index=0, user=""):
|
|||||||
'extract_flat': 'in_playlist'
|
'extract_flat': 'in_playlist'
|
||||||
}
|
}
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
for i in range(2):
|
attempts = var.config.getint('bot', 'download_attempts', fallback=2)
|
||||||
|
for i in range(attempts):
|
||||||
try:
|
try:
|
||||||
info = ydl.extract_info(url, download=False)
|
info = ydl.extract_info(url, download=False)
|
||||||
# # if url is not a playlist but a video
|
# # if url is not a playlist but a video
|
||||||
|
22
mumbleBot.py
22
mumbleBot.py
@ -292,7 +292,7 @@ class MumbleBot:
|
|||||||
except:
|
except:
|
||||||
error_traceback = traceback.format_exc()
|
error_traceback = traceback.format_exc()
|
||||||
error = error_traceback.rstrip().split("\n")[-1]
|
error = error_traceback.rstrip().split("\n")[-1]
|
||||||
logging.error("bot: command %s failed with error %s:\n" % (command_exc, error_traceback))
|
logging.error("bot: command %s failed with error: %s\n" % (command_exc, error_traceback))
|
||||||
self.send_msg(constants.strings('error_executing_command', command=command_exc, error=error), text)
|
self.send_msg(constants.strings('error_executing_command', command=command_exc, error=error), text)
|
||||||
|
|
||||||
def send_msg(self, msg, text=None):
|
def send_msg(self, msg, text=None):
|
||||||
@ -342,6 +342,7 @@ class MumbleBot:
|
|||||||
logging.info("bot: removing music from the playlist: %s" % util.format_debug_song_string(music))
|
logging.info("bot: removing music from the playlist: %s" % util.format_debug_song_string(music))
|
||||||
var.playlist.remove(index)
|
var.playlist.remove(index)
|
||||||
return
|
return
|
||||||
|
music = downloaded_music
|
||||||
uri = music['path']
|
uri = music['path']
|
||||||
|
|
||||||
elif music["type"] == "file":
|
elif music["type"] == "file":
|
||||||
@ -456,19 +457,26 @@ class MumbleBot:
|
|||||||
self.send_msg(constants.strings('download_in_progress', item=music['title']))
|
self.send_msg(constants.strings('download_in_progress', item=music['title']))
|
||||||
|
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
for i in range(2): # Always try 2 times
|
attempts = var.config.getint('bot', 'download_attempts', fallback=2)
|
||||||
|
download_succeed = False
|
||||||
|
for i in range(attempts):
|
||||||
|
logging.info("bot: download attempts %d / %d" % (i+1, attempts))
|
||||||
try:
|
try:
|
||||||
ydl.extract_info(url)
|
ydl.extract_info(url)
|
||||||
if 'ready' in music and music['ready'] == "downloading":
|
|
||||||
music['ready'] = "yes"
|
music['ready'] = "yes"
|
||||||
except youtube_dl.utils.DownloadError:
|
download_succeed = True
|
||||||
pass
|
except:
|
||||||
else:
|
error_traceback = traceback.format_exc()
|
||||||
break
|
logging.error("bot: download failed with error:\n %s" % error_traceback)
|
||||||
|
|
||||||
|
if not download_succeed:
|
||||||
|
self.send_msg(constants.strings('unable_download'))
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
logging.info("bot: music file existed, skip downloading " + mp3)
|
logging.info("bot: music file existed, skip downloading " + mp3)
|
||||||
music['ready'] = "yes"
|
music['ready'] = "yes"
|
||||||
|
|
||||||
|
logging.info("bot: finished downloading url (%s) %s, saved to %s." % (music['title'], url, music['path']))
|
||||||
music = util.get_music_tag_info(music)
|
music = util.get_music_tag_info(music)
|
||||||
|
|
||||||
var.playlist.update(music, index)
|
var.playlist.update(music, index)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user