Hey everyone, I’m working on a Discord bot that plays music from a local folder. I’m trying to add a feature where it can download songs from YouTube and save them locally. But I’m running into a problem.
When I use the download command, it starts the process and creates a file in the directory. However, the file always ends up empty (0 bytes) and the download never completes. Here is a simplified version of my code:
I encountered a similar issue when developing a YouTube downloader. One thing that often gets overlooked is the content disposition of the stream. YouTube sometimes sends audio in a fragmented format, which can cause issues with direct piping.
Try using the ‘audioFormat’ option to specify a desired format:
If these modifications don’t resolve the issue, you might want to explore alternative libraries like fluent-ffmpeg in combination with ytdl-core for more reliable audio extraction.
I’ve faced a similar issue when working with ytdl-core. The problem might be that the download is terminating prematurely. Here’s what worked for me:
Add error handling to catch any issues during the download process, use the ‘end’ event on the stream instead of relying solely on the ‘finish’ event of the file, and ensure you have the latest version of ytdl-core installed.
This approach helped me resolve the empty file issue. Also, make sure you have sufficient disk space and proper write permissions for the output directory. If the problem persists, you might want to consider using a different library like youtube-dl-exec for more robust downloading capabilities.