YouTube to Apple Music Download Script
I've long had some bookmarked DJ sets or live performances on YouTube that I would love to have available as I run or work. Viewing them on YouTube is usually not a great option because you have to keep the web page open, it inserts ads into the video and audio, etc. It's not optimized for listening, not like my Apple Music apps.
I've long been a fan and user of
youtube-dl - the best program to download videos from YouTube and a few other sites. I've written many scripts against it for Narro and other services.
I've long uploaded my own MP3 files into my Apple Music library - my own recordings or audiobooks I've generated with Narro, etc.
What I didn't know was how to programmatically get a nicely formatted and tagged MP3 into my Apple Music library. Luckily, some web-excavating lead me to this forum post from ten years ago about how to move files into (then) iTunes. With that hint I was able to determine the current folder structure and wrote up this script:
#!/usr/bin/env bash name=$(echo $1 | sed 's|^.*?v=||g') youtube-dl -o "$name.%(ext)s" --embed-thumbnail --add-metadata -x --audio-format=mp3 --buffer-size=16k $1 && \ mv $name.mp3 ~/Music/Music/Media.localized/Automatically\ Add\ to\ Music.localized
All you need to do is save that into an executable file and then you can run:
And the audio will download, get tagged with the appropriate metadata for music libraries, and be sucked up into your Apple Music library. Simple and sweet.