23 lines
740 B
Python
23 lines
740 B
Python
from collections import namedtuple
|
|
|
|
import discord.utils
|
|
import youtube_dl
|
|
|
|
eerror = namedtuple('eerror', ['content'])
|
|
|
|
|
|
def extract(params: dict, url: str, kwargs: dict):
|
|
try:
|
|
extracted = youtube_dl.YoutubeDL(params=params).extract_info(url, **kwargs)
|
|
if 'entries' in extracted:
|
|
extracted['entries'] = list(extracted['entries'])
|
|
return extracted
|
|
except (youtube_dl.utils.ExtractorError, youtube_dl.utils.DownloadError) as e:
|
|
msg = str(e)
|
|
msg = discord.utils.escape_markdown(msg)
|
|
msg = msg.replace('\x1b[0;31m', '__')
|
|
msg = msg.replace('\x1b[0m', '__')
|
|
print(msg)
|
|
msg = 'unknown ytdl error'
|
|
return {'__error__': True, '__error_str__': msg}
|