dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

tag-song.sh (976B)


      1 #!/usr/bin/env bash
      2 
      3 if [ "$1" = "-h" ]; then
      4 	echo "tag-song <genre> <amID/file.jpg> <files>*"
      5 	exit
      6 fi
      7 
      8 genre="$1"
      9 appleMusicID="$2"
     10 shift
     11 shift
     12 
     13 if [ "$appleMusicID" = "file.jpg" ]; then
     14 	cp file.jpg "$XDG_CACHE_HOME/art.jpg"
     15 	art="file.jpg"
     16 else
     17 	searchLink="https://itunes.apple.com/lookup?id=${appleMusicID}&entity=song"
     18 	json="$(curl "$searchLink")"
     19 	if [[ "$(echo "$json" | jq .results[0].collectionName)" == "null" ]]; then
     20 		echo null
     21 		searchLink="https://itunes.apple.com/lookup?id=${appleMusicID}&entity=album"
     22 		json="$(curl "$searchLink")"
     23 	fi
     24 
     25 	art="$(echo "$json" | jq -r .results[0].artworkUrl100 | sed 's/100x100bb/1500x1500/g')"
     26 	if [ "$art" = "null" ]; then
     27 		art="$(echo "$json" | jq -r .results[1].artworkUrl100 | sed 's/100x100bb/1500x1500/g')"
     28 	fi
     29 fi
     30 
     31 echo $art
     32 for arg; do
     33 	echo "$arg"
     34 	"$HOME/.local/share/regexghost/.venv/bin/python3" "${XDG_DATA_HOME}/regexghost/terminal/tag-music.py" "$arg" "$genre" "$art"
     35 done
     36 
     37 rm -f "$XDG_CACHE_HOME/art.jpg"