A script to build playlists, Needs some work.

Hi, I am trying to write a script that will automatically create playlists in each one of my mp3 folders that I have on my debian box.

The box runs Sarge the filesystem in ext3 and the script will only be run once in a while so I really don't mind if it is a little slow.

The mp3's are located in /mnt/mp3/ each folder has the following naming convention Artist\ Album\ Name/. Each folder contains no sub folder.

This is done deliberately because I have an ipod and used to use iTunes on my mac. but now I am hoping to move away from the mac. I have started to use GTKpod and can add songs to my ipod via the add playlists option. The only problem is that the current playlist_generator script I have places each playlist in the same folder as the songs and references each song as ./Song_name.mp3

This means that my playlists are not portable.

I would ideally like to place my playlists in a playlist folder and have each song referred to by a complete path /mnt/mp3/Artist_album/Song_Name.mp3 in the playlist.

How can I accomplish this?

Here is what I have so far.

___________________________

#!/bin/bash
BASEDIR=/mnt/mp3/
if [ "$BASEDIR" == "" ]; then
echo You must specify a base directory
exit 1
fi
cd $BASEDIR
BASEDIR=`pwd`

# Remove existing playlists
find . -iname '*.m3u'|sed -e "s/^/\"/"|sed -e "s/$/\"/"|xargs rm -f

find . -type d |sort| while read -r DIR; do
cd "$BASEDIR/$DIR"

find . -type f -iname "*.mp3" | sed 's/^\.\///'|sort> "$DIR.m3u"

done
________________

I imagine I will need to save the pwd as a variable somehow whenever the script changes directories and add that to the beginning of the string read by sort, but I have no idea how.

Please help as this is my only obstacle remaining in ridding my life of iTunes completely and returning to my Open Source roots.

Thanks in Advance

Cy

0

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

find /home/myself/mp3topdir/

find /home/myself/mp3topdir/ -name *mp3

Something like that will always give you the fully qualified path. If you need each subdir to have its own playlist then you need to parse the output - not so hard since you know the minimum number of "/" characters and can count from there.

That was meant to be a

That was meant to be a reply, sorry

Cy

That worked too well, still bad

The problem with that is it puts every mp3 in all folders in to every playlist. Not very useful. No I really do need a way to read in the pwd as a variable so that I can somehow add it to the front for the songname string.

Please help

playlist script

You may have already figured something out, but if not, try this. It works by writing your songs to a temporary file, reading them back in using a while loop, and echoing the full path back out the the m3u file.


#!/bin/bash
BASEDIR=/mnt/mp3/
if [ "$BASEDIR" == "" ]; then
echo You must specify a base directory
exit 1
fi
cd $BASEDIR
BASEDIR=`pwd`

# Remove existing playlists
#find . -iname '*.m3u'|sed -e "s/^/\"/"|sed -e "s/$/\"/"
find . -iname '*.m3u'|sed -e "s/^/\"/"|sed -e "s/$/\"/"|xargs rm -f

find . -type d |sort| while read -r DIR; do

if [ "$DIR" != "." -a "$DIR" != ".." ]; then
DIRNAME=${DIR:2} # throw out 0th and 1st characters "./"
cd "$BASEDIR/$DIRNAME"
FINDMP3=`find . -type f -iname "*.mp3" | sed 's/^\.\///'|sort`
echo "$FINDMP3" >> "../$DIRNAME.m3u.tmp"
while read line
do
echo "$BASEDIR/${DIR:2}/$line" >> "../$DIRNAME.m3u"
done <"../$DIRNAME.m3u.tmp"
rm -f "../$DIRNAME.m3u.tmp"
fi

done

Syndicate content