A simple Python script to download audio from YouTube videos using the yt-dlp
library. The script extracts audio in MP3 format with a preferred quality of 192kbps. It supports downloading both single songs and entire playlists.
- Downloads audio from YouTube URLs.
- Supports both single videos and playlists.
- Converts audio to MP3 format.
- Saves audio files with proper titles in a specified directory.
- Automatically creates a download directory if it doesn't exist.
Make sure you have Python 3.6 or higher installed. You can download Python from the official Python website.
Install the required Python libraries by running:
pip install -r requirements.txt
FFmpeg is required for audio extraction and conversion. Install it as follows:
- Linux (Ubuntu/Debian):
sudo apt install ffmpeg
- Fedora:
sudo dnf install ffmpeg
- macOS:
brew install ffmpeg
- Windows:
- Download FFmpeg from ffmpeg.org.
- Add FFmpeg to your system's PATH.
-
Clone or Download the Repository
git clone https://github.com/yourusername/yt-music-downloader.git cd yt-music-downloader
-
Set Up the Environment
- Ensure you have Python 3.6 or higher installed.
- Install dependencies:
pip install -r requirements.txt
-
Run the Script
python downloader.py
-
Provide the YouTube URL
- For a single song: Enter the YouTube video URL.
- For a playlist: Enter the YouTube playlist URL.
-
View Downloads
- MP3 files will be saved in the
downloads
directory by default.
- MP3 files will be saved in the
YouTube Music Downloader
------------------------
Enter YouTube URL (or 'q' to quit): https://www.youtube.com/watch?v=dQw4w9WgXcQ
INFO:root:Downloading from: https://www.youtube.com/watch?v=dQw4w9WgXcQ
INFO:root:Download completed successfully!
For a playlist:
Enter YouTube URL (or 'q' to quit): https://www.youtube.com/playlist?list=PLxyz123...
INFO:root:Downloading from: https://www.youtube.com/playlist?list=PLxyz123...
INFO:root:Download completed successfully!
-
download_audio(url, output_path="downloads")
: Downloads audio from the given YouTube URL and saves it as an MP3 file in the specified output path. -
main()
: Provides a simple user interface to enter URLs and download audio.
The script uses Python's built-in logging
module to provide informative output during execution.
Create a requirements.txt
file in the project directory with the following content:
yt-dlp
Install the dependencies by running:
pip install -r requirements.txt
Contributions are welcome! If you have ideas for improving the script or encounter issues, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
This script is for personal use only. Please ensure your usage complies with YouTube's Terms of Service.