Bonjour à tous, et aux amoureux de mangas en particuliers
Je suis en train de développer (et d’apprendre par la même occasion ) un script bash qui permet de télécharger les tomes de votre choix depuis le site lecture-en-ligne.com afin de les lire quand vous le souhaitez avec le confort de comix par exemple.
boomeranga! permet aujourd’hui :
- récupération des chapitres désirés pour les mangas de votre choix
- conversion automatique en .cbz
- possibilité de conversion en .pdf pour liseuses par exemple (grâce à Calibre)
#!/bin/bash
#weetabix' 2013 v0.8
##################
# Boomeranga! #
##################
#ne fonctionne que pour http://www.lecture-en-ligne.com pour le moment - à étendre si besoin
manga=`zenity --title "boomeranga!" --entry --text "Nom du manga ?"`
#si manga vide
if [ -z $manga ]
then zenity --error --title "boomeranga!" --text "Erreur dans le nom - abandon" & exit
fi
mkdir -p $HOME/téléchargements/boomeranga/
cd $HOME/téléchargements/boomeranga/
mkdir $manga
cd $PWD/$manga/
#connaitre chapitre max d'1 manga
wget http://www.lecture-en-ligne.com/$manga/1/0/0/1.html -O infochap
grep -A 1 'id="chap"' infochap > infochap2
head -2 infochap2 | tail -1 > infochap
cut -d ">" -f2 infochap | cut -d "<" -f1 > infochap2
chap_man=`cat $PWD/infochap2`
#Poursuivre série ?
test -f $PWD/chaplast
if [ $? = 0 ]
then
`zenity --title "boomeranga!" --info --timeout "1" --text "Poursuite de la série déjà commencée"`
chap=`cat $PWD/chaplast`
else
chap=`zenity --title "boomeranga!" --entry --text "Commencer à quel chapitre ?"`
fi
im=01
`zenity --title "boomeranga!" --question --text "Télécharger tous les chapitres disponibles ? ($chap_man)"`
#si sélection perso
if [ $? = 0 ]
then
chapmax=$chap_man
let chapmax=chapmax+1
else
chapmax=`zenity --title "boomeranga!" --entry --text "Stopper à quel chapitre ?"`
let chapmax=chapmax+1
fi
pdf=`zenity --title "boomeranga!" --entry --text "Convertir également en .pdf (pour liseuse par ex.) (o/n)"`
while [ $chap != $chapmax ]
do
#insérer test si chapitre présent chap+1 dans boucle while?
mkdir $chap
cd $PWD/$chap/
#rechercher le nb de pages du chapitre
wget http://www.lecture-en-ligne.com/$manga/$chap/0/0/1.html -O info
grep 'current_total_pages' info > info2
cut -d "'" -f2 info2 > info3
imax=`cat $PWD/info3`
let imaxi=imax+1
#vérif page 404
erreur=`grep -c 'ERREUR 404' info`
if [ $erreur = 1 ]
then zenity --error --title "boomeranga!" --text "Manga/chapitre non trouvé - abandon"
rm $PWD/info & rm $PWD/info2 & rm $PWD/info3 & exit
fi
#info
notify-send -i /usr/share/pixmaps/boomeranga.svg -t 2000 "Téléchargement du chapitre $chap"
#récupérer les images 1 à 7
while [ $im != 08 ]
do
wget http://www.lecture-en-ligne.com/images/mangas/$manga/$chap/$im.jpg
let im=im+1
im=0$im
done
#récupérer les images 8 & 9 (erreur boucle while pour 08, à corriger plus tard)
im=08
wget http://www.lecture-en-ligne.com/images/mangas/$manga/$chap/$im.jpg
im=09
wget http://www.lecture-en-ligne.com/images/mangas/$manga/$chap/$im.jpg
#récupérer les images suivantes - envisager chapitres courts !
im=10
while [ $im != $imaxi ]
do
wget http://www.lecture-en-ligne.com/images/mangas/$manga/$chap/$im.jpg
let im=im+1
done
#création du .cbz
rm $PWD/info & rm $PWD/info2 & rm $PWD/info3
zip -r $chap.cbz .
mv $chap.cbz ..
cd ..
rm -r $PWD/$chap
#conversion pdf
if [ $pdf = "o" ]
then
ebook-convert $chap.cbz $chap.pdf --right2left | zenity --title "boomeranga!" --progress --text "Création de $manga $chap.pdf" --auto-close --auto-kill
fi
#changement de chapitre
let chap=chap+1
im=01
done
rm $PWD/infochap
echo $chapmax > $PWD/chaplast
zenity --info --title "boomeranga!" --text "Vous trouverez les chapitres téléchargés dans le dossier <b>$HOME/téléchargements/boomeranga/</b> Bonne lecture! "
Je suis à votre écoute si vous avez des propositions d’améliorations ou des conseils concernant le scripting.
Pour info, j’ai aussi posté un fil sur le forum d’ubuntu, tous les avis sont bons à prendre