Skip to content

Instantly share code, notes, and snippets.

@D-32
Last active August 29, 2015 13:56
Show Gist options
  • Save D-32/9161544 to your computer and use it in GitHub Desktop.
Save D-32/9161544 to your computer and use it in GitHub Desktop.
Creates a m3u file for each album (a directory). Each mp3 is prefixed with it's position in the playlist: "1 - filename.mp3". The m3u is named like the directory of the album and contains the name of the .mp3 without prefix. The prefix is then removed from every mp3.
#!/bin/bash
# file name: "1 - songname.mp3"
delimiter="-"
delimiter_space=1 #characters after the delimiter until the songname starts
find * -type f -name '*.mp3' | while read path; do
dir=$(dirname "${path}")
filename=${path##*/}
cut=$(awk -v a="${filename}" -v b="${delimiter}" 'BEGIN{print index(a,b)}')
tmp="${filename%.*}"
songname=${tmp:cut+delimiter_space}
album=${dir##*/}
echo $songname.mp3 >> "$dir/$album.m3u"
mv "$dir/$filename" "$dir/$songname.mp3"
done
echo "finished :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment