1159b3361Sopenharmony_ci#!/bin/sh 2159b3361Sopenharmony_ci 3159b3361Sopenharmony_ci############################################################################ 4159b3361Sopenharmony_ci# 5159b3361Sopenharmony_ci# Run the LAME encoder on multiple files, with option to delete .wav files 6159b3361Sopenharmony_ci# after encoding. "mlame -?" will give instructions. 7159b3361Sopenharmony_ci# 8159b3361Sopenharmony_ci# Robert Hegemann 9159b3361Sopenharmony_ci# modified on request: Frank Klemm <pfk@uni-jena.de> 10159b3361Sopenharmony_ci# 11159b3361Sopenharmony_ci############################################################################ 12159b3361Sopenharmony_ci 13159b3361Sopenharmony_ci# encoder path to use 14159b3361Sopenharmony_cimp3coder="lame" 15159b3361Sopenharmony_cimp3analyzer="mlame_corr" 16159b3361Sopenharmony_ci 17159b3361Sopenharmony_ci# default options to use 18159b3361Sopenharmony_cioptions_low="-h -d -mj -b 128" 19159b3361Sopenharmony_cioptions_high="-h -d -mj -V 1 -b 112 -B 320" 20159b3361Sopenharmony_cioptions=$options_high 21159b3361Sopenharmony_ci 22159b3361Sopenharmony_ci# remove source? 23159b3361Sopenharmony_ciremovesource=false 24159b3361Sopenharmony_ci 25159b3361Sopenharmony_ci# force overwrite of destination 26159b3361Sopenharmony_citestoverwrite=true 27159b3361Sopenharmony_ci 28159b3361Sopenharmony_ci# waiting after error report n seconds 29159b3361Sopenharmony_cierrordelay=1 30159b3361Sopenharmony_ci 31159b3361Sopenharmony_cihelptext="\n\ 32159b3361Sopenharmony_ciThis script runs the LAME mp3 encoder on multiple files: \n\n\ 33159b3361Sopenharmony_ci $0 [options] <file 1> ... <file n>\n\ 34159b3361Sopenharmony_ci\n\ 35159b3361Sopenharmony_ci options:\n\ 36159b3361Sopenharmony_ci -? this help text\n\ 37159b3361Sopenharmony_ci -r remove files after encoding\n\ 38159b3361Sopenharmony_ci -f force overwrite of destination if exists\n\ 39159b3361Sopenharmony_ci -l low quality settings\n\ 40159b3361Sopenharmony_ci -h high quality settings\n\ 41159b3361Sopenharmony_ci -o \"<lame options>\" overrides script default options 42159b3361Sopenharmony_ci\n\ 43159b3361Sopenharmony_ci example:\n\ 44159b3361Sopenharmony_ci $0 -r -f -o \"-v -V 0 -b 112\" a*.wav z*.aif g*.mp?\n\ 45159b3361Sopenharmony_ci\n\ 46159b3361Sopenharmony_ci" 47159b3361Sopenharmony_ci 48159b3361Sopenharmony_ci# process command-line options 49159b3361Sopenharmony_ci# this could be extended to fake the 50159b3361Sopenharmony_ci# commandline interface of the mp3encoder 51159b3361Sopenharmony_ci 52159b3361Sopenharmony_ciwhile getopts ":o:r:h:l:f" optn; do 53159b3361Sopenharmony_ci case $optn in 54159b3361Sopenharmony_ci o ) options=$OPTARG # replace default options 55159b3361Sopenharmony_ci echo New lame options are \'$options\' 56159b3361Sopenharmony_ci ;; 57159b3361Sopenharmony_ci r ) removesource=true 58159b3361Sopenharmony_ci echo Removing source files after successfully converting 59159b3361Sopenharmony_ci ;; 60159b3361Sopenharmony_ci f ) testoverwrite=false 61159b3361Sopenharmony_ci echo Force overwriting existing destination files 62159b3361Sopenharmony_ci ;; 63159b3361Sopenharmony_ci h ) options=$options_high 64159b3361Sopenharmony_ci ;; 65159b3361Sopenharmony_ci l ) options=$options_low 66159b3361Sopenharmony_ci ;; 67159b3361Sopenharmony_ci \? ) printf "$helptext" 68159b3361Sopenharmony_ci sleep $errordelay 69159b3361Sopenharmony_ci exit 1 70159b3361Sopenharmony_ci ;; 71159b3361Sopenharmony_ci esac 72159b3361Sopenharmony_cidone 73159b3361Sopenharmony_cishift $(($OPTIND - 1)) 74159b3361Sopenharmony_ci 75159b3361Sopenharmony_ci# no files remaining? 76159b3361Sopenharmony_ci 77159b3361Sopenharmony_ciif [ "$1" = "" ]; then 78159b3361Sopenharmony_ci printf "$helptext" 79159b3361Sopenharmony_ci sleep $errordelay 80159b3361Sopenharmony_ci exit 1 81159b3361Sopenharmony_cifi 82159b3361Sopenharmony_ci 83159b3361Sopenharmony_ci# process input-files 84159b3361Sopenharmony_ci 85159b3361Sopenharmony_cifor src in "$@"; do 86159b3361Sopenharmony_ci 87159b3361Sopenharmony_ci case $src in 88159b3361Sopenharmony_ci *[.][wW][aA][vV] ) 89159b3361Sopenharmony_ci dst=${src%[.][wW][aA][vV]}.mp3 90159b3361Sopenharmony_ci if [ -f "$src" ]; then 91159b3361Sopenharmony_ci if [ $testoverwrite = true -a -f "$dst" ]; then 92159b3361Sopenharmony_ci echo \'$dst\' already exists, skipping 93159b3361Sopenharmony_ci sleep $errordelay 94159b3361Sopenharmony_ci elif $mp3coder $options `$mp3analyzer "$src"` "$src" "$dst"; then 95159b3361Sopenharmony_ci if [ $removesource = true ]; then 96159b3361Sopenharmony_ci rm -f "$src" 97159b3361Sopenharmony_ci fi 98159b3361Sopenharmony_ci else 99159b3361Sopenharmony_ci echo converting of \'$src\' to \'$dst\' failed 100159b3361Sopenharmony_ci sleep $errordelay 101159b3361Sopenharmony_ci fi 102159b3361Sopenharmony_ci else 103159b3361Sopenharmony_ci echo No source file \'$src\' found. 104159b3361Sopenharmony_ci sleep $errordelay 105159b3361Sopenharmony_ci fi 106159b3361Sopenharmony_ci ;; 107159b3361Sopenharmony_ci 108159b3361Sopenharmony_ci *[.][aA][iI][fF] ) 109159b3361Sopenharmony_ci dst=${src%[.][aA][iI][fF]}.mp3 110159b3361Sopenharmony_ci if [ -f "$src" ]; then 111159b3361Sopenharmony_ci if [ $testoverwrite = true -a -f "$dst" ]; then 112159b3361Sopenharmony_ci echo \'$dst\' already exists, skipping 113159b3361Sopenharmony_ci sleep $errordelay 114159b3361Sopenharmony_ci elif $mp3coder $options "$src" "$dst"; then 115159b3361Sopenharmony_ci if [ $removesource = true ]; then 116159b3361Sopenharmony_ci rm -f "$src" 117159b3361Sopenharmony_ci fi 118159b3361Sopenharmony_ci else 119159b3361Sopenharmony_ci echo converting of \'$src\' to \'$dst\' failed 120159b3361Sopenharmony_ci sleep $errordelay 121159b3361Sopenharmony_ci fi 122159b3361Sopenharmony_ci else 123159b3361Sopenharmony_ci echo No source file \'$src\' found. 124159b3361Sopenharmony_ci sleep $errordelay 125159b3361Sopenharmony_ci fi 126159b3361Sopenharmony_ci ;; 127159b3361Sopenharmony_ci 128159b3361Sopenharmony_ci *[.][aA][iI][fF][fF] ) 129159b3361Sopenharmony_ci dst=${src%[.][aA][iI][fF][fF]}.mp3 130159b3361Sopenharmony_ci if [ -f "$src" ]; then 131159b3361Sopenharmony_ci if [ $testoverwrite = true -a -f "$dst" ]; then 132159b3361Sopenharmony_ci echo \'$dst\' already exists, skipping 133159b3361Sopenharmony_ci sleep $errordelay 134159b3361Sopenharmony_ci elif $mp3coder $options "$src" "$dst"; then 135159b3361Sopenharmony_ci if [ $removesource = true ]; then 136159b3361Sopenharmony_ci rm -f "$src" 137159b3361Sopenharmony_ci fi 138159b3361Sopenharmony_ci else 139159b3361Sopenharmony_ci echo converting of \'$src\' to \'$dst\' failed 140159b3361Sopenharmony_ci sleep $errordelay 141159b3361Sopenharmony_ci fi 142159b3361Sopenharmony_ci else 143159b3361Sopenharmony_ci echo No source file \'$src\' found. 144159b3361Sopenharmony_ci sleep $errordelay 145159b3361Sopenharmony_ci fi 146159b3361Sopenharmony_ci ;; 147159b3361Sopenharmony_ci 148159b3361Sopenharmony_ci *[.][mM][pP][gG12] ) 149159b3361Sopenharmony_ci dst=${src%[.][mM][pP][gG12]}.mp3 150159b3361Sopenharmony_ci if [ -f "$src" ]; then 151159b3361Sopenharmony_ci if [ $testoverwrite = true -a -f "$dst" ]; then 152159b3361Sopenharmony_ci echo \'$dst\' already exists, skipping 153159b3361Sopenharmony_ci sleep $errordelay 154159b3361Sopenharmony_ci elif $mp3coder $options "$src" "$dst"; then 155159b3361Sopenharmony_ci if [ $removesource = true ]; then 156159b3361Sopenharmony_ci rm -f "$src" 157159b3361Sopenharmony_ci fi 158159b3361Sopenharmony_ci else 159159b3361Sopenharmony_ci echo converting of \'$src\' to \'$dst\' failed 160159b3361Sopenharmony_ci sleep $errordelay 161159b3361Sopenharmony_ci fi 162159b3361Sopenharmony_ci else 163159b3361Sopenharmony_ci echo No source file \'$src\' found. 164159b3361Sopenharmony_ci sleep $errordelay 165159b3361Sopenharmony_ci fi 166159b3361Sopenharmony_ci ;; 167159b3361Sopenharmony_ci 168159b3361Sopenharmony_ci *[.][mM][pP]3 ) 169159b3361Sopenharmony_ci dst=${src%[.][mM][pP]3}-new-converted-file.${src##*.} 170159b3361Sopenharmony_ci if [ -f "$src" ]; then 171159b3361Sopenharmony_ci if [ $testoverwrite = true -a -f "$dst" ]; then 172159b3361Sopenharmony_ci echo \'$dst\' already exists, skipping 173159b3361Sopenharmony_ci sleep $errordelay 174159b3361Sopenharmony_ci elif $mp3coder $options "$src" "$dst"; then 175159b3361Sopenharmony_ci if [ $removesource = true ]; then 176159b3361Sopenharmony_ci mv -f "$dst" "$src" 177159b3361Sopenharmony_ci fi 178159b3361Sopenharmony_ci else 179159b3361Sopenharmony_ci echo converting of \'$src\' to \'$dst\' failed 180159b3361Sopenharmony_ci sleep $errordelay 181159b3361Sopenharmony_ci fi 182159b3361Sopenharmony_ci else 183159b3361Sopenharmony_ci echo No source file \'$src\' found. 184159b3361Sopenharmony_ci sleep $errordelay 185159b3361Sopenharmony_ci fi 186159b3361Sopenharmony_ci ;; 187159b3361Sopenharmony_ci 188159b3361Sopenharmony_ci * ) # the rest 189159b3361Sopenharmony_ci echo warning: File extention \'.${src##*.}\' not supported 190159b3361Sopenharmony_ci sleep $errordelay 191159b3361Sopenharmony_ci ;; 192159b3361Sopenharmony_ci 193159b3361Sopenharmony_ci esac 194159b3361Sopenharmony_ci 195159b3361Sopenharmony_cidone 196