CUBISTCODE

CUBISTCODE

Shell script to copy m3u playlist on Linux

#!/bin/bash
# copyplaylist.sh

# accept a playlist and a destination directory
# copy the playlist files to the destination

copycmd="rsync -avR"

#grep -v "^#" playlist.m3u > clean.m3u 
#rsync -v --files-from=clean.m3u / /path/to/music/player/ 

if [ -z "$1" ] || [ -z "$2" ] # if we don't have two args...
then
    #echo "usage: $0 playlist.m3u destination_dir"
    destination_dir="/media/Sansa m240"
else
    if [ -f "$1" ] # valid file specified?
    then
        if [ -d "$2" ] # valid destination directory?
        then
        	destination_dir=$2
            # read each line in the file
            while read line
            do
                if echo "$line" | grep -q "^#"
                then
                    # skip lines beginning with '#'
                    # they're m3u comments
                    continue
                else
                    echo "$line"
                    $copycmd $line $destination_dir #$2
                fi
            done < $1
        else
            echo "$2 isn't a valid destination directory."
        fi
    else
        echo "$1 isn't a playlist file."
    fi
fi

# notes: this script copies the complete path and filename to the destination
# e.g. /home/audio/music/artist/album/song.ogg
# I would rather that it only copy the path starting at /artist/album/song.ogg
# but I was unable to get rsync to do this for me.
# If anyone has any ideas, let me know!
# until then, it works, so I'm happy. 


Tags: file, mp3, scripts, xmms2

Rate This Article:



Privacy Policy | Copyright/Trademark Notification