This Python script is designed to download videos and audio (music) directly from YouTube links.
The project is still under development, which may cause some bugs. Please see the Troubleshooting section for common issues and the Contributing section to report new ones.
- Download single YouTube videos.
- Download entire YouTube playlists.
- Convert downloaded videos to audio (e.g., MP3).
- Cross-platform compatibility (Windows, macOS, Linux - requires Python and FFmpeg).
- Ease of use (interactive command-line interface).
git clone https://github.com/william-ks/python-youtube-downloader.gitcd python-youtube-downloaderClick the green Code button and then click Download ZIP.
After the download is complete, unzip the ZIP file and open the terminal inside the folder.
First, you need Python 3.7+, which can be downloaded from python.org.
After installing Python, install the necessary libraries from the requirements.txt file using the command:
pip install -r requirements.txtWhen you run the script using python main.py, it will guide you through the download process interactively.
- Start the program:
python main.py
- The script will display a welcome message and ensure
ffmpeg(for audio conversion) is available, downloading it if necessary. - Paste the YouTube URL for the video or song when prompted and press Enter.
(Note: The image above shows the initial URL prompt. The script will subsequently ask you to choose the download format (Audio/Video) and handle playlist options as described below.) - You will then be asked to choose the download format:
- Audio (MP3): Select this to download and convert the content to an MP3 audio file.
- Video (MP4): Select this to download the content as an MP4 video file.
- The download will begin, and the file will be saved in the
downloadsfolder.
- Start the program as described above.
- Paste the YouTube playlist URL when prompted. The playlist must be public for the script to access its contents.
- The script will detect that the URL is a playlist and ask for your preference:
- Download ENTIRE playlist: Choose this to download all videos/songs in the playlist.
- Download ONLY the current video: If the playlist URL also points to a specific video within the playlist, choose this to download only that single video.
- Cancel: Stop the download process.
- If you choose to download (either the entire playlist or a single video from it), you will then be prompted to select the format (Audio MP3 or Video MP4), similar to a single item download.
- The files will be downloaded to the
downloadsfolder.
Here are solutions to common issues you might encounter:
- Context: The script attempts to download
ffmpegautomatically on its first run, which is necessary for audio conversion. The script looks forffmpeg.exe(on Windows) orffmpeg(on macOS/Linux) within a./tools/ffmpeg/bindirectory relative to the script. - Solution:
- Ensure you have a stable internet connection when running the script for the first time.
- Try running the script again; the download might have failed due to a temporary glitch.
- If the automatic download continues to fail, you can download
ffmpegmanually from https://ffmpeg.org/download.html. After downloading, you can either:- Place the
ffmpeg.exe(orffmpegbinary) directly into a folder structure like./tools/ffmpeg/bin/relative to the script. - Or, add the
bindirectory of your manualffmpeginstallation to your system's PATH environment variable.
- Place the
- Privacy: Playlists must be public. Private or unlisted playlists cannot be accessed by the script.
- Individual Video Failures: Sometimes, a playlist download might fail or hang due to issues with a specific video within that playlist (e.g., it's deleted, private, or region-restricted). Try downloading other videos from the playlist or a single video from the playlist to see if the issue is isolated.
- Internet Connection: A stable internet connection is crucial. Check your connection if downloads fail repeatedly.
- Restricted Content: Some YouTube videos are region-restricted, private, or have other settings that prevent downloading through third-party scripts. These may not be downloadable.
- Try Again: Sometimes, download issues are temporary. It's often worth trying the download again after a few moments.
- Problem: Old versions of downloaded libraries (especially
yt-dlp) can cause unexpected errors as YouTube frequently updates its platform. - Solution: Keep your libraries updated by running the following command in your terminal, in the script's directory:
pip install --upgrade -r requirements.txt
- If you encounter a persistent issue that isn't covered here, please consider opening an issue on the project's GitHub issues page: https://github.com/william-ks/python-youtube-downloader/issues.
- When reporting, please provide as much detail as possible, including:
- The exact YouTube link (URL) you were trying to download.
- The error message(s) you received.
- The steps you took before the error occurred.
- Your operating system.
We welcome contributions to improve this project! Here's how you can help:
- Check Existing Issues: Before submitting a new bug report, please check the GitHub Issues to see if someone has already reported it.
- Provide Details: If the bug hasn't_been reported, open a new issue. Please include:
- Clear steps to reproduce the bug.
- Any error messages you received.
- Your operating system (e.g., Windows 10, Ubuntu 20.04).
- Your Python version (e.g., Python 3.9.5).
- The YouTube link(s) that caused the problem.
- Clear Description: If you have an idea for a new feature or an improvement to an existing one, please open an issue on GitHub Issues.
- Provide a clear and detailed explanation of the enhancement, why it would be beneficial, and if possible, suggest how it might be implemented.
We are happy to review pull requests (PRs) for bug fixes and features. Please follow this basic workflow:
- Fork the Repository: Create your own copy of the project at https://github.com/william-ks/python-youtube-downloader.
- Create a Branch: Make a new branch in your fork for your changes. Use a descriptive name:
git checkout -b feature/YourAmazingFeatureName # or for bug fixes: git checkout -b fix/IssueDescriptionOrNumber - Make Your Changes: Implement your feature or bug fix.
- Commit Your Changes: Write clear and concise commit messages:
git commit -m "Add: Implement YourAmazingFeatureName" # or for fixes: git commit -m "Fix: Resolve bug #123 by doing X"
- Push to Your Branch:
git push origin feature/YourAmazingFeatureName
- Open a Pull Request: Go to the original repository on GitHub and open a new Pull Request from your forked branch.
- Reference any relevant issues in your PR description (e.g., "Closes #123").
- PEP 8: Please try to follow PEP 8 guidelines for Python code.
- Commit Messages: Write meaningful commit messages that explain the "what" and "why" of your changes.
- Keep it Simple: Aim for clear and readable code.
This project is licensed under the MIT License. See the LICENSE.md file for details.
