def _youtube(self, context, *, query: str):
"""Search on Youtube"""
try:
url = 'https://www.youtube.com/results?'
payload = {'search_query': ''.join(query)}
headers = {'user-agent': 'Red-cog/1.0'}
conn = aiohttp.TCPConnector()
session = aiohttp.ClientSession(connector=conn)
async with session.get(url, params=payload, headers=headers) as r:
result = await r.text()
session.close()
yt_find = re.findall(r'href=\"\/watch\?v=(.{11})', result)
url = 'https://www.youtube.com/watch?v={}'.format(yt_find[0])
await self.bot.say(url)
except Exception as e:
message = 'Something went terribly wrong! [{}]'.format(e)
await self.bot.say(message)
评论列表
文章目录