#! /bin/bash # $Id: mp3riplabel,v 1.13 2007/07/21 18:08:03 friedman Exp $ file-template () { tmpl_author=`filter "$author"` tmpl_album=`filter "$album"` for f in "$tmpl_author.$tmpl_album"?"$1."*".mp3" \ "$file_author.$file_album"?"$1."*".mp3" \ "$file_author.$tmpl_album"?"$1."*".mp3" \ "track$1.cdda.mp3" \ "track_$1.mp3" \ "$1-"*.mp3 \ "$1 -"*.mp3 \ *".$1."*.mp3 \ *"-$1-"*.mp3 \ *"_$1_"*.mp3 \ *" - $1 - "*.mp3 do if [ -f "$f" ]; then echo "$f" return fi done } acronymize () { case "$*" in *" "* | *-* ) echo "$*" \ | sed -e "s/^/ /" \ -e "s/ *\([^ ]\)[^ ]*/\1/g" \ -e "y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/" ;; * ) echo "$*" ;; esac } filter () { echo "$*" \ | sed -e "s/ / /g" \ -e "s/ $//" \ -e "s/^(//" \ -e "s/&/and/g" \ -e "y/[(_ /----/" \ -e "s/[]):.,'!?]//g" } label () { track="$1" file=`file-template "$1"` title="$2" comment="${3-$defcomment}" touch -r "$file" .stamp #mp3info -W "$file" #mp3info -t "$title" \ # -l "$album" \ # -a "$author" \ # -c "$comment" \ # -y "$year" \ # -g "$genre" \ # "$file" id3v2 -D "$file" # --comment "$comment" \ id3tag --artist "$author" \ --album "$album" \ --track "$track" \ --total "$total_tracks" \ --song "$title" \ --year "$year" \ --genre "$genre" \ "$file" touch -r .stamp "$file" rm -f .stamp } rename () { old=`file-template "$1"` title="$2" comment="${3-$defcomment}" #new=`filter "$title" "$comment"` #new="$file_author.$file_album.$1.$new.mp3" new=`echo $title $comment` new="$author - $album - $1 - $new.mp3" case "$new" in "$old" ) : ;; * ) mv -v "$old" "$new" ;; esac } init () { ############################## author='' album='' defcomment=' ' year= genre= total_tracks= # Alternatively, use `acronymize' file_author=`filter "$author"` file_album=`filter "$album"` } doit () { ############################## ############################## $1 01 "Example Title" "Example Comment" $1 02 "Example Title" "Example Comment" $1 03 "Example Title" "Example Comment" $1 04 "Example Title" "Example Comment" $1 05 "Example Title" "Example Comment" $1 06 "Example Title" "Example Comment" $1 07 "Example Title" "Example Comment" $1 08 "Example Title" "Example Comment" $1 09 "Example Title" "Example Comment" $1 10 "Example Title" "Example Comment" $1 11 "Example Title" "Example Comment" $1 12 "Example Title" "Example Comment" $1 13 "Example Title" "Example Comment" $1 14 "Example Title" "Example Comment" $1 15 "Example Title" "Example Comment" $1 16 "Example Title" "Example Comment" $1 17 "Example Title" "Example Comment" $1 18 "Example Title" "Example Comment" $1 19 "Example Title" "Example Comment" $1 20 "Example Title" "Example Comment" } init doit label doit rename # eof