source code available on github
YouTube to MP3 Downloader
This project provides a script to download YouTube videos and convert them to MP3 format using multiple CPU cores for better performance. It also monitors CPU and memory usage during the download process.
Features
- Download audio from YouTube videos and convert them to MP3.
- Process multiple URLs concurrently using multiple CPU cores.
- Monitor CPU and memory usage during the process.
Requirements
- Python 3.6+
pytube
for downloading YouTube videos.pydub
for audio conversion.psutil
for monitoring system usage.ffmpeg
orlibav
for audio processing (required bypydub
).
Installation
-
Install Python packages:
pip install pytube pydub psutil
-
Install ffmpeg:
On macOS using Homebrew:
brew install ffmpeg
On Ubuntu:
sudo apt update sudo apt install ffmpeg
On Windows, download the binaries from ffmpeg.org and add them to your PATH.
-
Clone my github repository:
git clone https://github.com/MetythornPenn/youtube2mp3.git
-
Install dependency:
# go to dir cd youtube2mp3 # create python env with conda conda create -n env python=3.12 -y # can be any python3 verson # activate env conda activate env # install dependency pip install -r requirements.txt
Usage
-
Prepare a text file with YouTube URLs:
Create a text file (
urls.txt
) with each line containing a YouTube video URL you want to download.# example urls.txt file https://www.youtube.com/watch?v=MFtfIpt7DfY&list=PLCl5gq1pTcnXSGkvV1-QemxiEPYDz6GnT&index=2 https://www.youtube.com/watch?v=aNk0DIWFw8w https://www.youtube.com/watch?v=ZLiGQsPm1gg https://www.youtube.com/watch?v=D7F_rGhB7hE
-
Run the script:
python main.py