Discord.py / youtube_dlp Audio streaming bot

37 Views Asked by At

I was wondering how I could speed up my discord bot that takes a youtube link as input (Or just the title and artist etc. -> see code) Right now it takes quite a while to search for the video and play it.

This is what I am using right now with yt_dlp. And this function takes the most time. After this there is just a function that makes the bot join the channel. Thanks in advance.

def search(query):
        with YoutubeDL({'format': 'bestaudio', 'noplaylist':'True'}) as ydl:
            if 'spotify.com' in query:
                query = ExtractSpotifyInfo.get_song_info(query)
                info = ydl.extract_info(f"ytsearch:{query}", download=False)['entries'][0]
            if 'youtube.com' in query or 'youtu.be' in query: info = ydl.extract_info(query, download=False)
            else: info = ydl.extract_info(f"ytsearch:{query}", download=False)['entries'][0]
        return info
0

There are 0 best solutions below