Bonjour à tous !
J'ai réalisé un petit script en bash qui récupère une tablature pour guitare/basse à partir
du site
ultimate-guitar.com.
Télécharger
Code source :
#!/bin/bash
if [[ -z $1 || -z $2 ]]
then
echo "USAGE : ./tab.sh [\"band\"] [\"song\"] optional [int]"
exit 1
else
band=$1
song=$2
file="temp.html"
urlFile="url"
fi
url=$(echo "http://www.ultimate-guitar.com/search.php?view_state=advanced&band_name=${band}&song_name=${song}" | sed 's/ /+/g')
wget -q --user-agent="mozilla" -O $file $url
cat $file | awk -F"\"" '$3 == " class=" && $4 == "song" {print $2}' > $urlFile
if [ -z $3 ]
then
i=1
for url in $(cat $urlFile)
do
echo "${i} - ${url}"
(( i = i + 1 ))
done
echo -e "Enter url index to display : \c"
read int
if [[ $int -gt 0 && $int -le $i ]]
then
value=$int
else
echo "Index not found"
rm -f $file ; rm -f $urlFile
exit 1
fi
else
i=$(cat $urlFile | wc -l)
if [[ $3 -gt 0 && $3 -le $i ]]
then
value=$3
else
echo "Index not found"
rm -f $file ; rm -f $urlFile
exit 1
fi
fi
url=$(head -n $value $urlFile | tail -n 1)
rm -f $file ; rm -f $urlFile
wget -q --user-agent="mozilla" -O $file $url
topLine=$(cat $file | awk -F" " '$0 == "</pre>" {print NR}')
lastLine=$(cat $file | awk -F"\"" '$2 == "fb-meta" && $3 == ">" {print NR}')
((topLine = topLine + 1 ))
((lastLine = lastLine - 1 ))
sed -n "${topLine},${lastLine}p" $file > fichier
cat fichier | sed 's&<pre>&&g' | sed 's&</pre>&&g' | sed 's&<i>&&g' | sed 's&</i>&&g' | sed 's&<span>&&g' | sed 's&</span>&&g'
rm $file; rm fichier
exit 0
Bonne journée !