def youtube(self, ctx, *, ytsearch: str):
"""Does a little YouTube search."""
opener = request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
search = ytsearch.split()
search = "+".join(search)
errorthing = ytsearch
url = ('https://www.youtube.com/results?search_query={}'.format(search))
ourUrl = opener.open(url).read()
await self.bot.type()
soup = bs(ourUrl, "html.parser")
alexpls = re.findall('"(/watch\?v=.*?)"',
str(soup.find_all('a',
attrs={'href': re.compile('^/watch\?v=.*')})))
try:
await self.bot.say('{}: https://www.youtube.com{}'.format(ctx.message.author.mention, alexpls[0]))
except IndexError:
await self.bot.say('Sorry I could not find any results containing the name `{}`'.format(errorthing))
评论列表
文章目录