User Tools

Site Tools


inglese:wordit-download-en

indice

Wordit-downloaden

Per il download della pronuncia (audio) di una parola in lingua inglese da wiktionary.

wordit-downloaden.sh
#!/bin/bash
 
# dipendenze curl wget sox sed
# utilizzo 
# bash wordit-downloaden.sh <word>
 
if [ -z "$1" ]
    then
        echo -e "How to use it: \n bash wordit-downloaden.sh <word>"
        exit 0;
fi
 
set -u
if [ -n "$1" ] 
then
  #echo "1 $1"
  curl -s https://en.wiktionary.org/wiki/File:en-uk-"$1".ogg -o "${HOME}/wiktionary-uk.htm"
  parole=$(grep -Eo -m 1 --color -i 'source src=".*ogg"' "${HOME}/wiktionary-uk.htm")
  url="${parole:14:-1}"
  #echo "l1 ${#url}"
  if [ -z "$url" ]
  then
    #echo "2 $1"
    curl -s https://en.wiktionary.org/wiki/File:en-us-"$1".ogg -o "${HOME}/wiktionary-us.htm"
    parole=$(grep -Eo -m 1 --color -i 'source src=".*ogg"' "${HOME}/wiktionary-us.htm")
    url="${parole:14:-1}"
    #echo "l2 ${#url}"
    if [ -z "$url" ]
    then
      #echo "3 $1"
      curl -s https://en.wiktionary.org/wiki/File:en-au-"$1".ogg -o "${HOME}/wiktionary-au.htm"
      parole=$(grep -Eo -m 1 --color -i 'source src=".*ogg"' "${HOME}/wiktionary-au.htm")
      url="${parole:14:-1}"
      #echo "l3 ${#url}"
      if [ -z "$url" ]
      then
		  #echo "4 $1"
		  curl -s https://en.wiktionary.org/wiki/File:en-ca-"$1".ogg -o "${HOME}/wiktionary-ca.htm"
		  parole=$(grep -Eo -m 1 --color -i 'source src=".*ogg"' "${HOME}/wiktionary-ca.htm")
		  url="${parole:14:-1}"
		  #echo "l3 ${#url}"
		  if [ -z "$url" ]
		  then
			#echo "4 $1"
			  curl -s https://en.wiktionary.org/wiki/File:LL-Q1860_%28eng%29-Vealhurl-"$1".wav -o "${HOME}/wiktionary-eng-vealhurl.htm"
			  parole=$(grep -Eo -m 1 --color -i 'source src=".*\.ogg"' "${HOME}/wiktionary-eng-vealhurl.htm")
			  url="${parole:14:-1}"
			  #echo "l3 ${#url}"
				if [ -z "$url" ]
				then
					echo -e " !!!!!!!!! warning !!!!!!!!! \n audio file not found on wiktionary :( ... "
				else
					echo "South England English"
					#parole=`grep -Eo -m 1 --color -i 'source src=".*ogg"' "${HOME}/wiktionary-au.htm"`
				fi
			else
			echo "Canadian English"
			#parole=`grep -Eo -m 1 --color -i 'source src=".*ogg"' "${HOME}/wiktionary-au.htm"`
		  fi
      else
      echo "American English"
      #parole=`grep -Eo -m 1 --color -i 'source src=".*ogg"' "${HOME}/wiktionary-us.htm"`
      #exit 0;
      fi
    fi
  else
    echo "British English"
    #parole=`grep -Eo -m 1 --color -i 'source src=".*ogg"' "${HOME}/wiktionary-uk.htm"`
    #exit 0
  fi
 
fi
 
#url="https://${parole:14:-1}"
echo "${url}"
wget --quiet "https://${url}"
 
ls ./*"$1"*
 
if [ -n "$1" ] 
then
  echo "1 $1"
  curl -s https://en.wiktionary.org/wiki/"$1" -o "${HOME}/wiktionary-pron.htm"
  parole=$(grep -Eo -m 1 --color -i '<span class="IPA">.*</span>' "${HOME}/wiktionary-pron.htm")
  #url="${parole:14:-1}"
  echo "${parole}"
fi
 
if [ -n "$1" ] 
then
  echo "1 $1"
  curl -s https://en.wiktionary.org/wiki/"$1" -o "${HOME}/wiktionary-pron.htm"
  parole=$(grep -Eo --color -i '<span class="Latn" lang="it">.*</span>' "${HOME}/wiktionary-pron.htm")
  parola=$(echo "$parole" | sed -e 's/.*\(title="\)\(it\:\)\(.*\)\(">\).*/\3/')
  #url="${parole:14:-1}"
  echo "${parola}"
fi
 
if [ -a *$1.ogg ] 
then 
    play ./*"$1".ogg
else
    if [ -a *$1.wav.ogg ]
    then
        play ./*"$1".wav.ogg
    fi
fi
inglese/wordit-download-en.txt · Last modified: 2024/02/25 22:29 by profpro