HOWTO create a simple music playlist

From LinuxReviews
Jump to navigationJump to search

Here are two simple and somewhat feature-limited scripts for making a playlist file that's compatible with most music player software.

genplaylists.sh[edit | edit source]

Warning: This script does delete your old playlist files.

#!/bin/bash

BASEDIR=$1
if [ "$BASEDIR" == "" ]; then
        echo You must specify a base directory
        exit 1
fi

cd $BASEDIR
BASEDIR=`pwd`

# Remove existing playlists
find . -name '*.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 |grep -v m3u|sort> '00-Playlist.m3u'
done

make-ogg-playlist[edit | edit source]

!/bin/bash
#
# make-ogg-playlist v0.1 (By Sam Storie)
#
# Changelog:
#	v0.1 Initial Creation
#
#
# This creates a series of XMMS playlist files 
# from an ogg library that is organized like:
#
#	/home/sam/music
#		+- Radiohead
#			+- Paranoid_Android
#			|	+- Track1.ogg
#			|	+- Track2.ogg
#			+- Hail_to_the_Theif
#				+- Track1.ogg
#				+- Track2.ogg
#
# and creates these files:
# .../music/all.pls			    (all oggs)
# .../music/Radiohead.pls		    (from Radiohead)
# ../music/Radiohead/Paranoid_Android.pls   (that album only)
# .../music/Radiohead/Hail_to_the_Theif.pls (that album only)
#

# Needs to be full path (ie, ~/music won't work)
ROOT=/home/sam/music
cd $ROOT

BuildPlaylist() {
 ct=1
 NUM=$(find $1 -type f -name *.ogg | wc -l | awk '{print $1}')
 echo "[playlist]" > $2.pls
 echo "NumberOfEntries=$NUM" >> $2.pls
 for i in `find $1* -type f -name *.ogg`; do
	echo "File${ct}=${ROOT}/${i}" >> $2.pls
	ct=`expr $ct + 1`
 done
}

# Do all the subdirectories
for j in `find * -type d -maxdepth 1`; do
	BuildPlaylist $j $j
done

# Make a list for all of them
BuildPlaylist "" "all"
/pre>