Skip to content

Instantly share code, notes, and snippets.

@n1chre
Last active July 13, 2018 05:23
Show Gist options
  • Save n1chre/ad37738f3a0ad58ea7833da159e1f0b4 to your computer and use it in GitHub Desktop.
Save n1chre/ad37738f3a0ad58ea7833da159e1f0b4 to your computer and use it in GitHub Desktop.
Add artwork to songs by using the thumbnail from the first video on youtube
#!/usr/bin/env bash
ROOT_DIR='/directory/with/artist/album/song' # root directory which will be traversed
ALBUM='Unknown Album' # only set artwork for songs in given album (for each artist)
pushd "$(pwd)"
cd "$ROOT_DIR"
for artist in *; do
cd "$artist"
if [ -d "$ALBUM" ]; then
echo "$artist"
cd "$ALBUM"
for song in *; do
echo -ne "\t${song%.*}... "
url=$(youtube-dl --get-thumbnail "ytsearch1: $artist - ${song%.*}")
curl "$url" 2>/dev/null | ffmpeg -y -i "$song" -i - -map 0:0 -map 1:0 -c copy tmp_song.mp3 &>/dev/null && mv tmp_song.mp3 "$song"
echo "Done!"
done
cd ..
fi
cd ..
done
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment