| 1 |
#!/bin/sh |
| 2 |
set -e |
| 3 |
|
| 4 |
conf=/etc/mpd.conf |
| 5 |
if [ -e $HOME/.mpdconf ]; then |
| 6 |
conf=$HOME/.mpdconf |
| 7 |
fi |
| 8 |
if [ ! -e $conf ]; then |
| 9 |
echo "error: $conf does not exist" >&2 |
| 10 |
exit 1 |
| 11 |
fi |
| 12 |
|
| 13 |
music_directory=$(grep "^music_directory" $conf | cut -d '"' -f 2 | sed -e "s!^\~!$HOME!") |
| 14 |
playlist_directory=$(grep "^playlist_directory" $conf | cut -d '"' -f 2 | sed -e "s!^\~!$HOME!") |
| 15 |
|
| 16 |
if [ -z "$music_directory" ] || [ -z "$playlist_directory" ]; then |
| 17 |
echo "error: failed to parse $conf" >&2 |
| 18 |
exit 1 |
| 19 |
fi |
| 20 |
|
| 21 |
if [ ! -d "$music_directory" ] || [ ! -d "$playlist_directory" ]; then |
| 22 |
echo "error: both $music_directory and $playlist_directory need to exist" >&2 |
| 23 |
exit 1 |
| 24 |
fi |
| 25 |
|
| 26 |
rm $playlist_directory/\ *.m3u 2>/dev/null || true |
| 27 |
IFS=" |
| 28 |
" |
| 29 |
for dir in $(cd "$music_directory"; find -type d -follow | sed 's!^./!!'); do |
| 30 |
playlist="$(echo "$dir" | tr "_" " " | sed 's!/! - !g')" |
| 31 |
if [ "$playlist" = . ]; then |
| 32 |
playlist=all |
| 33 |
fi |
| 34 |
find "$music_directory/$dir" -type f -follow | sort \ |
| 35 |
> "$playlist_directory/ $playlist".m3u |
| 36 |
done |
| 37 |
|
| 38 |
exit |
| 39 |
|
| 40 |
<<POD |
| 41 |
|
| 42 |
=head1 NAME |
| 43 |
|
| 44 |
mpgenplaylists - generate mpd playlists for each subdirectory of music |
| 45 |
|
| 46 |
=head1 SYNOPSIS |
| 47 |
|
| 48 |
mpgenplaylists |
| 49 |
|
| 50 |
=head1 DESCRIPTION |
| 51 |
|
| 52 |
B<mpgenplaylists> generates mpd playlists. |
| 53 |
|
| 54 |
It reads your ~/.mpdconf or /etc/mpd.conf to figure out where mpd keeps its |
| 55 |
music directory and playlist directory. |
| 56 |
|
| 57 |
For each subdirectory of the music directory, a playlist is generated in the |
| 58 |
playlist directory. The playlists created by this tool always start with a |
| 59 |
space to avoid conflicts with your manually created playlists. |
| 60 |
|
| 61 |
So if you keep your sound in Artist/Album/ directories, you'll get playlists |
| 62 |
named like " Artist - Album", and also playlists named just " Artist" that |
| 63 |
contain all music by that artist. An " all" playlist is also created, that |
| 64 |
contains all your music. |
| 65 |
|
| 66 |
Each time it's run it updates the playlists, and removes any obsolete ones |
| 67 |
that it created before. |
| 68 |
|
| 69 |
=head1 LIMITATIONS |
| 70 |
|
| 71 |
It does not currently sort songs in an album by track number, but instead |
| 72 |
sorts by filename. |
| 73 |
|
| 74 |
=head1 AUTHOR |
| 75 |
|
| 76 |
Copyright 2007 Joey Hess <[email protected]> |
| 77 |
|
| 78 |
Licensed under the GNU GPL version 2 or higher. |
| 79 |
|
| 80 |
http://kitenet.net/~joey/code/mpdtoys |
| 81 |
|
| 82 |
=cut |
| 83 |
|
| 84 |
POD |