Handle errors

This commit is contained in:
root 2021-06-15 14:28:05 +00:00
parent 2f27c94be6
commit 11a639be5d
1 changed files with 10 additions and 8 deletions

18
main.py
View File

@ -50,14 +50,16 @@ async def youtube(room, message):
match = botlib.MessageMatch(room, message, bot) match = botlib.MessageMatch(room, message, bot)
pieces = str(message).split() pieces = str(message).split()
links = filter(filterfunc, pieces) links = filter(filterfunc, pieces)
for i in links: try:
with youtube_dl.YoutubeDL(ydl_opts) as ydl: for i in links:
info_dict = ydl.extract_info(i, download=False) with youtube_dl.YoutubeDL(ydl_opts) as ydl:
fname = urllib.parse.quote(info_dict.get('title', None).replace('|', '_')) info_dict = ydl.extract_info(i, download=False)
#fname = fname.translate({ord(c): None for c in ',&!|'}) fname = urllib.parse.quote(info_dict.get('title', None).replace('|', '_'))
url = 'https://trygve.me/video_bot/' + fname + '.webm' url = 'https://trygve.me/video_bot/' + fname + '.webm'
ydl.download([i]) ydl.download([i])
await bot.api.send_text_message(room.room_id, url) 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) bot.add_message_listener(youtube)