Skip to content

Instantly share code, notes, and snippets.

@nonrice
Created February 7, 2022 03:49
Show Gist options
  • Save nonrice/9e7f5cb3615f922fd2e41d180a2a270b to your computer and use it in GitHub Desktop.
Save nonrice/9e7f5cb3615f922fd2e41d180a2a270b to your computer and use it in GitHub Desktop.
Downloads songs from Youtube into iTunes music library (MacOS)
#!/bin/zsh
# Downloads audio and cover art from youtube video and automatically adds to your iTunes music library.
#
# Required packages:
# youtube-dl
# eyeD3
# imageMagick
#
# To use, first make the script runnable:
# chmod +x yt-itunes.sh
#
# Run and specify proper args:
# ./yt-itunes.sh [video_url] [song_title] [song_artist]
vid_id=${1: -11}
vid_name="$2.mp3"
youtube-dl -x --audio-format mp3 $1 -o "$2.%(ext)s"
curl "https://img.youtube.com/vi/${vid_id}/maxresdefault.jpg" > cover.jpg
convert cover.jpg -resize "720^>" -gravity center -crop 720x720+0+0 -strip cover.jpg
eyeD3 --add-image "cover.jpg:FRONT_COVER" ${vid_name} --artist $3
mv ${vid_name} "$HOME/Music/Music/Media.localized/Automatically Add to Music.localized/"
rm cover.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment