pronunciask (938B)
1 #!/bin/bash 2 # Get pronunciations from forvo.com. Written for fun. 3 4 LANG=en 5 PLAYER="mplayer -quiet" 6 MP3BASE="http://it.forvo.com/player-mp3Handler.php?path=" 7 GETTER="wget -t1 --timeout=5 -q" 8 TMP="/tmp/$(basename $0)" 9 10 usage() { 11 echo -n "Usage: $0 [-h] [-l <lang>] <word> ... 12 -l <lang> Set the language (default: $LANG) 13 -h Show this help 14 " 15 16 exit 1 17 } 18 19 run() { 20 [ ! -d "$TMP" ] && mkdir "$TMP" 21 rm -f "${TMP}/*" 22 23 n=0 24 for word in $@ 25 do 26 n=$(echo $n+1|bc) 27 mp3=$($GETTER -O - "http://it.forvo.com/word/$word" |sed -n "/<abbr title=\"[^\"]*\">${LANG}<\/abbr>/,/<\/ul>/ p" |grep 'Play(' |head -1 |sed "s/.*Play([0-9]*,'\([^,]*\)','.*/\1/") 28 $GETTER -O "${TMP}/${n}" "${MP3BASE}${mp3}" 29 done 30 31 files='' 32 for i in $(seq 1 $n) 33 do 34 files="${files} ${TMP}/${i}" 35 done 36 $PLAYER $files 37 } 38 39 main() { 40 while getopts "hl:" opt; do 41 case $opt in 42 h) usage;; 43 l) LANG=$OPTARG; 44 esac 45 done 46 47 shift "$(echo $OPTIND-1|bc)" 48 49 run "$@" 50 } 51 52 main "$@"