From 11a639be5d6b3260aee80da5a8ecd44da29f397e Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Jun 2021 14:28:05 +0000 Subject: [PATCH] Handle errors --- main.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 5b635bb..e10ca3e 100644 --- a/main.py +++ b/main.py @@ -50,14 +50,16 @@ async def youtube(room, message): match = botlib.MessageMatch(room, message, bot) pieces = str(message).split() links = filter(filterfunc, pieces) - for i in links: - with youtube_dl.YoutubeDL(ydl_opts) as ydl: - info_dict = ydl.extract_info(i, download=False) - fname = urllib.parse.quote(info_dict.get('title', None).replace('|', '_')) - #fname = fname.translate({ord(c): None for c in ',&!|'}) - url = 'https://trygve.me/video_bot/' + fname + '.webm' - ydl.download([i]) - await bot.api.send_text_message(room.room_id, url) + try: + for i in links: + with youtube_dl.YoutubeDL(ydl_opts) as ydl: + info_dict = ydl.extract_info(i, download=False) + fname = urllib.parse.quote(info_dict.get('title', None).replace('|', '_')) + url = 'https://trygve.me/video_bot/' + fname + '.webm' + ydl.download([i]) + await bot.api.send_text_message(room.room_id, url) + except Exception as e: + await bot.api.send_text_message(room.room_id, str(e)) bot.add_message_listener(youtube)