Discord Bot Audio Streaming Issues with yt-dlp: Need Help

Hey everyone! I’m stuck with a problem in my Discord music bot. I’m using C++ with DPP and yt-dlp to get audio URLs. It’s weird though. Short songs play fine but longer ones are super slow.

I tried this command: ytdl-helper -a --url-only "<LINK>"

Here’s what’s going on:

  • Short tracks (3 mins) work great
  • Long tracks (15 mins) are painfully slow
  • libav isn’t the problem, I checked
  • Network usage is tiny for yt-dlp URLs
  • Google Drive links stream way better
  • Sometimes yt-dlp downloads are fast, sometimes not

I think yt-dlp might be limiting longer tracks somehow.

Anyone know how to make YouTube streaming faster? Or is there a better tool than yt-dlp for getting audio for Discord bots? Thanks!

yo, ive run into this too. its a pain. have u tried using ffmpeg to convert the audio? sometimes that helps with longer tracks. also, maybe check ur server’s bandwidth. if its low, that could be why longer songs struggle. just a thought. good luck man!

I’ve dealt with similar issues in my Discord bot projects. From my experience, the problem might not be with yt-dlp itself, but rather with YouTube’s throttling for longer videos.

One workaround I found effective was to implement a chunking system. Instead of trying to stream the entire long video at once, you can split it into smaller segments and stream them sequentially. This approach often bypasses YouTube’s throttling and improves performance for longer tracks.

Another solution that worked for me was using a caching system. When a song is requested, download it to a temporary file first, then stream from that file. This adds a slight delay to the initial playback but significantly improves streaming quality for subsequent plays.

If these don’t work, you might want to explore alternative libraries like youtube-dl or even consider using a different API altogether, like Spotify’s API with YouTube fallback for unavailable tracks. Each approach has its pros and cons, so it’s worth experimenting to find what works best for your specific use case.

Having worked on music bots before, I can say this is a common issue. YouTube’s throttling on longer videos is likely the culprit here. One effective solution I’ve implemented is using a proxy rotation system. By cycling through different IP addresses, you can often bypass rate limits and improve streaming speeds for longer tracks.

Another approach worth considering is implementing a queue system that pre-fetches and caches upcoming songs in the background. This can significantly reduce lag between tracks and improve the overall user experience.

If you’re open to alternatives, you might want to look into using the Invidious API. It’s an open-source YouTube front-end that can provide better performance for audio extraction in some cases. Just be mindful of their terms of service and usage limits.

Ultimately, dealing with YouTube’s restrictions is an ongoing challenge for bot developers. Keep experimenting and don’t hesitate to combine multiple strategies for the best results.