A simple Python script that downloads audio from YouTube videos and converts them to MP3 format.
This tool uses the yt-dlp library to download audio from YouTube videos and automatically convert them to MP3 format with 256kbps quality. It's designed to be simple to use, requiring just a YouTube URL to function.
- Python 3
- yt-dlp library
- FFmpeg (located at
/opt/homebrew/binfor Mac M1/M2)
- Make sure you have Python 3 installed
- Install the required library:
pip install yt-dlp
- Install FFmpeg (if not already installed):
Run the script with a YouTube URL as an argument:
python main.py https://youtu.be/YOUR_VIDEO_ID
You can download a specific segment of the audio by providing start and end times in seconds using the --start and --end flags. Both flags must be used together.
Example: Download audio from 30 seconds to 120 seconds:
python main.py https://youtu.be/YOUR_VIDEO_ID --start 30 --end 120
You can convert any existing MP3 file to a low quality (64kbps) version using the --downgrade flag:
python main.py --downgrade your_audio.mp3
This will create a new file with _low added to the filename, e.g., your_audio_low.mp3.
If no URL is provided, the script will use a default YouTube video:
python main.py
This will download audio from the default video (ID: 882ba_OmWXE).
- The script takes a YouTube URL as input
- It configures yt-dlp to extract the best available audio
- FFmpeg processes the audio and converts it to MP3 format
- The resulting MP3 file is saved with the video's title as the filename
You can modify the script to change:
- Audio quality (currently set to 256kbps)
- Output filename format
- Audio format (currently MP3)