Boomeranga! pour les amateurs de mangas

Bonjour à tous, et aux amoureux de mangas en particuliers :wink:

Je suis en train de développer (et d’apprendre par la même occasion :mrgreen: ) 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 :wink:

Voilà la dernière version du script :

[code]#!/bin/bash
#weetabix’ 2013 v0.8.1-1

##################

Boomeranga!

##################

#ne fonctionne que pour http://www.lecture-en-ligne.com pour le moment - à étendre si besoin

ch=$HOME/téléchargements/boomeranga/

mkdir -p $ch/ #option choix répertoire ?
cd $ch
test -f $PWD/séries
if [ $? = 1 ]
then

séries
fi

#fonction télécharger()
function télécharger {
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
chap=cat $PWD/chaplast
else
chap=zenity --title "boomeranga!" --entry --text "Commencer à quel chapitre ?"
fi

im=01

zenity --title "boomeranga!" --question --text "$manga - 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

while [ $chap != $chapmax ]
do

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"
cd $ch
mv $PWD/$manga $HOME/.local/share/Trash/files & 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

#inscrire manga dans liste ‘séries’ sauf si déjà présent
cd …
grep $manga séries
if [ $? != 0 ]
then
echo $manga >> séries
fi
}

#intro
zenity --info --ok-label “Go!” --timeout “10” --title “boomeranga!” --text "boomeranga! vous permet de télécharger
des planches de manga depuis lecture-en-ligne.com

Bonne lecture

Manuel disponible à l’adresse :
blog.goupil.eu/?boomeranga"

#pdf ?
pdf=zenity --title "boomeranga!" --entry --text "Convertir les chapitres téléchargés en .pdf (pour liseuse par ex.) (o/n)"

#menu1 - poursuivre séries en cours ? ajouter option pas de série en cours
zenity --title "boomeranga!" --question --text "Poursuivre les séries en cours ?"
if [ $? = 0 ]
then
nb_ligm=wc -l séries | cut -d " " -f1
let nb_ligm=nb_ligm+1
nb_lig=1
while [ $nb_lig != $nb_ligm ]
do
manga=head -n $nb_lig séries | tail -n 1
télécharger
let nb_lig=nb_lig+1
done
else
manga=zenity --title "boomeranga!" --entry --text "Nouveau manga - nom du manga ?"

#si manga vide
if [ -z $manga ]
then zenity --error --title “boomeranga!” --text “Erreur dans le nom - abandon” & exit
fi

télécharger
fi

zenity --info --title “boomeranga!” --text "Vous trouverez les chapitres téléchargés dans le dossier $ch Bonne lecture! "
[/code]

Des paquets .deb sont disponibles : ils permettent l’inscription du script dans les menus avec icône.