Kapisi/roles/Yggdrasil/package/yggdrasil-set-music-data

49 lines
1.6 KiB
Plaintext
Raw Permalink Normal View History

2024-09-02 23:54:57 -05:00
#!/bin/bash
parser="$(echo $PWD | rev)"
IFS="
"
partist="$(echo $parser | cut -f 2 -d '/' | rev)"
palbum="$(echo $parser | cut -f 1 -d '/' | rev)"
pgenre="$(echo $parser | cut -f 3 -d '/' | rev)"
if [ "$partist" == "" ] || [ "$palbum" == "" ] || [ "$pgenre" == "" ]; then
echo "This script expects a format of "'$MUSICBASEPATH'"/Genre/Artist/Album/Song.ext"
exit;
fi
echo Expected metadata:
echo Artist: $partist
echo Album: $palbum
echo Genre: $pgenre
echo
for i in $@; do
if [ ! -f "$i" ]; then
echo File doesn\'t exist. $i
continue;
fi
ffartist="$(ffprobe -hide_banner -i $i 2>&1 | grep artist | grep -v 'album_artist' | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' | sed -e 's/*[[:space:]]$//')"
ffalbum="$(ffprobe -hide_banner -i $i 2>&1 | grep album | grep -v 'album_artist' | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' | sed -e 's/*[[:space:]]$//')"
ffgenre="$(ffprobe -hide_banner -i $i 2>&1 | grep genre | head -n 1 | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' | sed -e 's/*[[:space:]]$//')"
echo For \[$i\]...
unset tags
echo Found artist \[$ffartist\]
if [ "$partist" != "$ffartist" ]; then
export tags=$tags" -metadata artist=\"$partist\""
fi
echo Found album \[$ffalbum\]
if [ "$ffalbum" != "$palbum" ]; then
export tags=$tags" -metadata album=\"$palbum\""
fi
echo Found genre \[$ffgenre\]
if [ "$ffgenre" != "$pgenre" ]; then
export tags=$tags" -metadata genre=\"$pgenre\""
fi
if [ "$tags" != "" ]; then
bash -c "ffmpeg -hide_banner -i \"$i\"$tags \"$i.ffmpeg.mp3\""
mv "$i.ffmpeg.mp3" "$i"
fi
echo
done