Skip to content

Instantly share code, notes, and snippets.

@rshipp
Last active March 23, 2023 12:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rshipp/95ee7c36f6cdc57b988d to your computer and use it in GitHub Desktop.
Save rshipp/95ee7c36f6cdc57b988d to your computer and use it in GitHub Desktop.
Scrape the highest rated MP3 from Forvo.com for a given word
#!/bin/bash
# Forvo scraper
language=${FORVO_LANG:-fr}
BASEURL="http://forvo.com/search/"
AUDIOURL="http://audio.forvo.com/mp3/"
word=$1
if [[ -z $word ]]; then
echo "usage: "
echo "FORVO_LANG=languagecode ./forvo_scraper.sh myword"
echo "for example: "
echo "FORVO_LANG=fr ./forvo_scraper.sh chien"
echo "will save a single file named 'chien.mp3' in the current folder"
exit
fi
url="${BASEURL}${word}/${language}"
playurl="${BASEURL}${word}/#${language}"
file="$(wget -qO- "${url}" | grep 'onclick="Play(' | head -1 | sed "s/^.*Play(.*,'\([^']*\)','.*$/\1/g" | base64 -d)"
wget -qO"${word}.mp3" "${AUDIOURL}${file}"
@jiru
Copy link

jiru commented Jul 28, 2016

Thanks! I updated your script to make it work again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment