Handle errors
This commit is contained in:
parent
2f27c94be6
commit
11a639be5d
4
main.py
4
main.py
@ -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)
|
||||||
|
try:
|
||||||
for i in links:
|
for i in links:
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
info_dict = ydl.extract_info(i, download=False)
|
info_dict = ydl.extract_info(i, download=False)
|
||||||
fname = urllib.parse.quote(info_dict.get('title', None).replace('|', '_'))
|
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'
|
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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user