#!/bin/sh ## Author: Parv, parv UNDERSCORE AT yahoo DOT com ## Version: 0.01 Apr 20 2003 ## ## License: Free to use as you please w/ proper credit given. ## use at your own risk. All responsibility for potential damage, ## loss, etc. is disclaimed. ## ## Name: mvmp3 ## ## Purpose: To move files w/ artist, song title, and 'mp3' separated by ## a dot in a directory named after the artist in the current directory. ## ## Example: Say, you have a file named ## 'ella-fitzgerald.mack-the-knife.mp3'. To move it to a directory ## 'ella-fitzgerald', just run mvmp3 in the directory that file resides. ## ## Don't forget to update $MP3 variable - root of all the ## subdirectories. ## # Peculiarities... # - This program uses Perl to get the string before first dot. Replace # w/ sed if so desire. # # - file & egrep commands are used to identify a mp3 file # home of subdirectories MP3="${HOME}/audio" case $1 in hind* ) MP3="$MP3/hindi" ;; eng* | * ) MP3="$MP3/english" ;; esac set -- # create home if doesn't exist mkdir -p "$MP3" || \ { echo "mkdir -p $MP3 failed" >&2; exit 1; } # get directory name from the file name get_dir() { dir=$( echo "$1" | perl -pe 's/^([^.]+).*/$1/;' ) } # move files to $MP3/ for m in *.*.mp3 do # make an attempt to find only the binary/mp3 files if { ! file "$m" | egrep -i ' (mp3|data)' >/dev/null 2>&1; } then echo "$m skipped..." continue fi if { get_dir "$m"; } then echo "$m --> ${MP3}/${dir}" # if artist directory doesn't exist, create it [ ! -d "${MP3}/${dir}" ] && mkdir "${MP3}/${dir}" mv "$m" "${MP3}/${dir}" fi done