#!/bin/bash # WAV to MP3 converter script. # # Original idea and design: Remco van Rijn # Additional tuning: Maarten de Boer # Thanks to: Pieter Suurmond # Last edited on march 13, 2009. # Put this bash script in the rootdir of a WAV-tree before running it. # It will produce an MP3-tree next to the WAV-tree. # It assumes all directory-names at the root of the WAV-tree are # composer-names, so this name can be used as an MP3-tag. # Name of the MP3-tree: DST=../MP3_from_WAV # First collect all WAV-filenames in a temporary textfile # (note that we can only run one script at a time!): find . -iname "*.wav" > /tmp/wav_files.txt # Then iterate over all names: cat /tmp/wav_files.txt | while read NAAM; do # Trim the first 2 characters (which are "./") from the name: NAAM="${NAAM:2}" # Construct new filename for the MP3 (substituting the .wav-suffix # by an .mp3-suffix): MP3_FILE="$DST"/`echo "$NAAM" | sed 's/.\{3\}$/mp3/'` # The first part of the path (up to first slash) is the composers name: # (${string%%substring} = Strip longest match of $substring from back of $string) COMPOSER="${NAAM%%/*}" # The last part of the path is the title (without the trailing ".wav"): # (${string##substring} = Strip longest match of $substring from front of $string) TITLE="${NAAM##*/}" # (${string%substring} = Strip shortest match of $substring from back of $string) TITLE="${TITLE%.wav}" # Name of the parent directory is the album name (could be same as composer). ALBUM="${NAAM%/*}" ALBUM="${ALBUM##*/}" # Create new subdirs in the MP3-tree, if necessary: DIR=`dirname "$MP3_FILE"` mkdir -p "$DIR" # Create MP3-file with variable bitrate. Quality/filesize is determined # by "V n", with n=9 for lowest quality, and n=0 for highest quality. lame --nohist --ta "$COMPOSER" --tl "$ALBUM" --tt "$TITLE" -h -V 1 "$NAAM" "$MP3_FILE" done