summaryrefslogtreecommitdiff
path: root/mpgenplaylists
diff options
context:
space:
mode:
Diffstat (limited to 'mpgenplaylists')
-rwxr-xr-xmpgenplaylists84
1 files changed, 84 insertions, 0 deletions
diff --git a/mpgenplaylists b/mpgenplaylists
new file mode 100755
index 0000000..881bbec
--- /dev/null
+++ b/mpgenplaylists
@@ -0,0 +1,84 @@
+#!/bin/sh
+set -e
+
+conf=/etc/mpd.conf
+if [ -e $HOME/.mpdconf ]; then
+ conf=$HOME/.mpdconf
+fi
+if [ ! -e $conf ]; then
+ echo "error: $conf does not exist" >&2
+ exit 1
+fi
+
+music_directory=$(grep "^music_directory" $conf | cut -d '"' -f 2 | sed -e "s!^\~!$HOME!")
+playlist_directory=$(grep "^playlist_directory" $conf | cut -d '"' -f 2 | sed -e "s!^\~!$HOME!")
+
+if [ -z "$music_directory" ] || [ -z "$playlist_directory" ]; then
+ echo "error: failed to parse $conf" >&2
+ exit 1
+fi
+
+if [ ! -d "$music_directory" ] || [ ! -d "$playlist_directory" ]; then
+ echo "error: both $music_directory and $playlist_directory need to exist" >&2
+ exit 1
+fi
+
+rm $playlist_directory/\ *.m3u 2>/dev/null || true
+IFS="
+"
+for dir in $(cd "$music_directory"; find -type d -follow | sed 's!^./!!'); do
+ playlist="$(echo "$dir" | tr "_" " " | sed 's!/! - !g')"
+ if [ "$playlist" = . ]; then
+ playlist=all
+ fi
+ find "$music_directory/$dir" -type f -follow | sort \
+ > "$playlist_directory/ $playlist".m3u
+done
+
+exit
+
+<<POD
+
+=head1 NAME
+
+mpgenplaylists - generate mpd playlists for each subdirectory of music
+
+=head1 SYNOPSIS
+
+mpgenplaylists
+
+=head1 DESCRIPTION
+
+B<mpgenplaylists> generates mpd playlists.
+
+It reads your ~/.mpdconf or /etc/mpd.conf to figure out where mpd keeps its
+music directory and playlist directory.
+
+For each subdirectory of the music directory, a playlist is generated in the
+playlist directory. The playlists created by this tool always start with a
+space to avoid conflicts with your manually created playlists.
+
+So if you keep your sound in Artist/Album/ directories, you'll get playlists
+named like " Artist - Album", and also playlists named just " Artist" that
+contain all music by that artist. An " all" playlist is also created, that
+contains all your music.
+
+Each time it's run it updates the playlists, and removes any obsolete ones
+that it created before.
+
+=head1 LIMITATIONS
+
+It does not currently sort songs in an album by track number, but instead
+sorts by filename.
+
+=head1 AUTHOR
+
+Copyright 2007 Joey Hess <joey@kitenet.net>
+
+Licensed under the GNU GPL version 2 or higher.
+
+http://kitenet.net/~joey/code/mpdtoys
+
+=cut
+
+POD