Wiedergabelisten aus Clementine-Datenbank erstellen

Dieses Bash-Script erlaubt das automatische Erzeugen von Wiedergabelisten (Playlists) aus der Clementine-Datenbank.

#!/bin/bash
# config variables
GENRES="Abstract,Acoustic,Acoustic Rock,Alternative Metal,Alternative Rock,Ambient,Billy,Black Metal,Break Beat,Country,Crossover,Dark Metal,Death Metal,Disco,Doom Metal,Downtempo,Drum Bass,Dub,EBM,Electro,Emo,Europop,Experimental,Folk,Folk Rock,Fun Metal,Goa,Goth,Goth Metal,Goth Rock,Grunge,Hardcore,Hard Rock,Heavy Metal,Hip Hop,Indie Rock,Industrial,Industrial Metal,Industrial Rock,Industrial Pop,iris,Jazz,Latin,Leftfield,Lo-Fi,Melodic Death Metal,Metal,Minimal,NDH,NDW,Noise,Noise Rock,Nu Metal,Party,Pop Rock,Post Rock,Power Metal,Oldie,Psychedelic Rock,Punk,Punk Rock,Rap,Reggae,RnB,Rock,Rock Roll,Romanesca,Soft Rock,Soundtrack,Speed Metal,Symphonic Metal,Salsa,Synth Pop,Trance,Trip Hop,Viking Metal"
DB=~/.config/Clementine/clementine.db
BASE=$HOME/Musik

# switch of line breaks as separator, enable colon as separator
OLDIFS=$IFS
IFS=','

function urldecode(){
  echo -e "$(sed 's/+/ /g; s/%/\\x/g')"
}

function createPlaylistFor(){

# create filename
FILENAME="$BASE/Playlists/$@.m3u"

# create search string
GENRE=$(echo "$@" | sed "s/ /%\" and genre like \"%/g")

# create queue
QUEUE="select filename from songs where genre like \"%"$GENRE"%\""

# write m3u header
echo "#EXTM3U" > $FILENAME

# read database and write playlist
  sqlite3 $DB "$QUEUE" | sed "s|file://$BASE|..|g" | urldecode | shuf >> $FILENAME
}

# create playlist directory
mkdir -p $BASE/Playlists
cd $BASE/Playlists

# create one playlist per genre
for GENRE in $GENRES; do
  createPlaylistFor "$GENRE"
done

# some cleanup
chmod -x *.m3u
mv Rock\ Roll.m3u Rock\'n\'Roll.m3u
mv iris.m3u Irish.m3u
mv Synth\ Pop.m3u Synthie\ Pop.m3u
ln -s NDW.m3u Neue\ Deutsche\ Welle.m3u
ln -s NDH.m3u Neue\ Deutsche\ Härte.m3u

IFS=$OLDIFS

Hierzu müssen lediglich die Variablen am Anfang des Scripts verändert werden.