Dan A
Dan A

Reputation: 414

Discor.py Bot YouTube Search

Hello I wrote this code so that I can search up videos from Youtube, but recently it stopped working

The bot is supposed to search up a video and pull the top result and paste the link in the channel

Example: !yt Never Gonna Give You Up Bot: posts the video link

from discord.ext import commands
from discord.utils import get
import urllib.parse, urllib.request, re
import discord


@commands.command()
    async def yt(self, ctx, *, search):

        query_string = urllib.parse.urlencode({'search_query': search})
        htm_content = urllib.request.urlopen(
            'http://www.youtube.com/results?' + query_string)
        search_results = re.findall('href=\"\\/watch\\?v=(.{11})',
                                    htm_content.read().decode())
        await ctx.send('http://www.youtube.com/watch?v=' + search_results[0])

Upvotes: 1

Views: 2451

Answers (1)

Dan A
Dan A

Reputation: 414

I found a solution

change: 'href=\"\\/watch\\?v+(.{11})' to r'/watch\?v=(.{11})'

Upvotes: 1

Related Questions