Salut à tous,
J'ai fait un petit script pour récupérer les info venant de
IMDb (et Wikipédia) de mes films, ce script a été fait pour s'utiliser en temps que "script click droit" dans nautilus et autre thunar, spacefm...
En le lançant il va afficher une fenêtre zenity avec le titre, le réalisateur, le synopsis, la durée, l'affiche du film...
Pour Nautilus il suffit de mettre le fichier dans ~/.local/share/nautilus/scripts (ou dans ~/.gnome2/nautilus-scripts pour les anciennes versions...) et de le rendre executable.
Pour thunar c'est dans éditer-> configurer les actions personnalisée qu'il faut aller chercher.
#!/bin/bash
# dépendances : libxml2-utils (pour xmllint), zenity, links et imagemagik (pour display)
# man :
# -i : affiche les info en gtk (besion de zenity)
# -v : affiche la bande annonce
# -c : affiche les info en console
browser="x-www-browser"
# fichiers temporaires supprimé en fin d'exécution :
imdbpage="$HOME/.imdbpage"
imdbimage="$HOME/.imdbimage"
# ordre de priorités :
premier=omdbapi
deuxieme=imdbapi
troisieme=wikipedia
#man :
if [ -z "$1" ]
then
echo "Utilisation :
-i [fichier|nom de film] : affiche les info en gtk (besion de zenity)
-c [fichier|nom de film] : affiche les info en console
-v [fichier|nom de film] : affiche la bande annonce dans $browser"
exit 1
fi
function Totxt ()
{
sed 's/\â/â/g
s/\à/à/g
s/\ç/ç/g
s/\é/é/g
s/\ê/ê/g
s/\è/è/g
s/\ï/œ/g
s/\\x{c3}\\x{a9}/é/g
s/\\x{c3}\\x{a8}/è/g
s/\\x{c3}\\x{a0}/à/g
s/\\x{c3}\\x{ae}/î/g
s/\\x{c3}\\x{a7}/ç/g
s/\\x{c3}\\x{aa}/ê/g
s/\\x{e2}\\x{80}\\x{99}/\`/g
s/\\x{c3}\\x{af}/ï/g'
}
function ToHtml ()
{
sed 's/à/a/g
s/â/a/g
s/ä/a/g
s/ç/c/g
s/è/e/g
s/é/e/g
s/ê/e/g
s/ë/e/g
s/î/i/g
s/ï/i/g
s/ù/u/g
s/ü/u/g
s/û/u/g
s/" "/"%20"/g'
}
imagedl () {
wget -qO- -O $imdbimage $1
if [ -e $imdbimage ]
then
display $imdbimage
rm "$imdbimage"
fi
}
imdbapi () {
wget -qO- -O $imdbpage "http://imdbapi.org/?title=$titre&type=xml&plot=full&episode=1&limit=1&yg=0&mt=none&lang=fr-FR&offset=&aka=simple&release=simple&business=0&tech=0"
image=$(xmllint --xpath "//IMDBDocumentList/item/poster/text()" "$imdbpage")
rating=$(xmllint --xpath "//IMDBDocumentList/item/rating/text()" "$imdbpage")
plot=$(xmllint --xpath "//IMDBDocumentList/item/plot/text()" "$imdbpage" | Totxt)
title=$(xmllint --xpath "//IMDBDocumentList/item/title/text()" "$imdbpage" | Totxt)
year=$(xmllint --xpath "//IMDBDocumentList/item/year/text()" "$imdbpage")
time=$(xmllint --xpath "//IMDBDocumentList/item/runtime/item/text()" "$imdbpage" | Totxt)
real=$(xmllint --xpath "//IMDBDocumentList/item/directors/item/text()" "$imdbpage" | Totxt)
type="IMDb 2"
rm $imdbpage
}
omdbapi () {
wget -qO- -O $imdbpage "http://www.omdbapi.com/?r=XML&plot=full&t=$titre"
image=$(xmllint --xpath "//root/movie/@poster" "$imdbpage" | awk -F"\"" '{print $2}')
rating=$(xmllint --xpath "//root/movie/@imdbRating" "$imdbpage" | awk -F"\"" '{print $2}')
plot=$(xmllint --xpath "//root/movie/@plot" "$imdbpage" | awk -F"\"" '{print $2}' | Totxt)
title=$(xmllint --xpath "//root/movie/@title" "$imdbpage" | awk -F"\"" '{print $2}' | Totxt)
year=$(xmllint --xpath "//root/movie/@year" "$imdbpage" | awk -F"\"" '{print $2}')
time=$(xmllint --xpath "//root/movie/@runtime" "$imdbpage" | awk -F"\"" '{print $2}' | Totxt)
real=$(xmllint --xpath "//root/movie/@director" "$imdbpage" | awk -F"\"" '{print $2}' | Totxt)
type="IMDb 1"
rm $imdbpage
}
wikipedia () {
wget -qO- -O $imdbpage "http://fr.wikipedia.org/w/api.php?format=xml&action=query&titles=$titre&prop=revisions&rvprop=content&redirects"
title=$(grep -m 1 "| titre" $imdbpage | awk -F"=" '{print $2 }')
time=$(grep "| durée" $imdbpage | awk -F"=" '{print $2 }')
year=$(grep "| sortie" $imdbpage | awk -F"= " '{print $2 }')
type="Wikipedia"
#image=$(grep "| image" $imdbpage | awk -F"=" '{print $2 }')
plot=$(grep -A 50 -E "\=\=.*Synopsis.*\=\=" $imdbpage | tr "\n$" " " | awk -F"==" '{print $3}' | sed 's/\[\[[^]]*|//g; s/\[\[//g; s/\]\]//g; s/\<ref\>.*\<\/ref\>.//g; s/\<ref.*\>//g; s/\ \ //g')
rating="42"
real=$(grep -m 1 "| réalisation" $imdbpage | awk -F"=" '{print $2 }' | sed 's/\[\[[^]]*|//g; s/\[\[//g; s/\]\]//g; s/\<.*\>.//g')
rm $imdbpage
}
# si que un argument on utilise zenity
if [ -z $2 ]
then
film=$1
arg="-i"
else
film=$2
arg=$1
fi
titre1=$(basename "$film" | sed 's/\.[^.]*$//' | sed 's/[\ _]/+/g' | ToHtml)
titre=$(links -dump "http://www.imdb.com/find?q=$titre1" | grep "\[IMG\]" | head -n 1 | awk -F"] " '{print $2}' | awk -F"\(" '{print $1}')
if [ -z "$titre" ]
then
titre=$titre1
fi
$premier
if [ -z "$title" ]
then
$deuxieme
if [ -z "$title" ]
then
$troisieme
if [ -z "$title" ]
then
if [ $arg = -c ]
then
echo Info manquante désolé...
else
notify-send "Info manquante" désolé...
fi
exit 1
fi
fi
fi
if [ $arg == "-i" ]
then
if [ -n "$image" ]
then
imagedl $image &
fi
echo -e "$title ($year) - $time \n de $real \n $rating/10 \n $plot" | zenity --text-info --title="$type info"
pkill display
else
if [ $arg == "-v" ]
then
recherche=$(echo $title site:http://www.youtube.com | sed s/" "/%20/g)
$browser "http://www.google.fr/search?q="$recherche"&btnI=Im+Feeling+Lucky"
else
if [ $arg == "-c" ]
then
echo -e "$title ($year) - $time \n de $real \n $rating/10 \n $plot"
fi
fi
fi
Autre chose le script dépend de : libxml2-utils (pour xmllint), links, imagemagik (pour display) et zenity.
Il peut aussi s'exécuter en console avec le paramètre "-c", et permet aussi d'afficher la bande annonce du film sur youtube avec "-v".
Voilà, dites poi si vous avez des idées d'amélioration ou autre.