One of my favourite TV shows is Parks and Recreation. If you don’t know it watch it. One of the main characters portrayed by Chris Pratt is a wannabe rock star. His band, Mouse Rat, created few quite good rock songs. Recently I re-watched this TV show and I tried to buy the soundtrack containing mentioned rock hits. Unfortunately I wasn’t able to find it on Amazon, Apple Store and NBC store so I looked for it on Youtube and did what every developer would do, created a simple python script that converts Youtube video into mp3. Why homemade script and not one of bazillion websites that convert Youtube videos? Because first few sites I tested were filled with crap (ads, malware, redirects, etc.). Ok, let’s start.
First of all you will need ffmpeg. I’m using MacOS and the easiest way of installing it is running those two commands
brew tap homebrew-ffmpeg/ffmpeg brew install homebrew-ffmpeg/ffmpeg/ffmpeg
Once you have ffmpeg installed you can pull code and install dependencies.
git https://github.com/wilgucki/get-the-music.git cd get-the-music # now you need to do the virtual environment magic followed by pip install -r requirements.txt
Using script is easy. Just run
python -m get_mp3 --url "<youtube url>"
It will download mp4 file and convert it to mp3. File will be saved under the Youtube video title in current directory.