Advertisement
due204

Mc_Tux

Jul 5th, 2014
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.48 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #===============================================================================
  4. #
  5. #          FILE: Mc_Tux.sh
  6. #  
  7. #         USAGE: ./Mc_Tux.sh  
  8. #  
  9. #   DESCRIPTION: Script creado para bajar mangas de la McAnime.
  10. #  
  11. #       OPTIONS: None
  12. #  REQUIREMENTS: yad, curl, wget, notify-send
  13. #          BUGS: None
  14. #         NOTES: El ejecutable llamado Andrade es el Yad portable.
  15. #        AUTHOR: Due204
  16. #  ORGANIZATION: ---
  17. #       CREATED: 22/03/14 22:57:01 ART
  18. #      REVISION: 0.1
  19. #===============================================================================
  20.  
  21. # Ruta de trabajo.
  22. RUUTO="$(dirname "$(readlink -f "$0")")"
  23. # Exportando ruta de trabajo.
  24. export PATH="$RUUTO/":"${PATH}"
  25.  
  26. # Primera gráfica.
  27. LINKP=`Andrade --title="Mc Tux" --window-icon="$RUUTO/iconos/icono.png" --text="\n \n \t Ingrese el link del manga: " --entry --entry-text="Link" --image="$RUUTO/iconos/link.png" --button="Acerca de:1" --button="Aceptar:0" --width=430 --height=190`
  28.  
  29. case $? in
  30. 1)
  31. Andrade --image="$RUUTO/iconos/icono.png" --window-icon="$RUUTO/iconos/icono.png" --button="Aceptar:0" --title="Acerca de..." --text="\nMc Tux es un simple script creado por due204 para bajar mangas de http://www.mcanime.net \nPor dudas o sugerencias: due204@gmail.com \n\nSientete libre de adaptar este codigo a tus necesidades." --width=260 ; exit;;
  32. 252)
  33. exit;;
  34. 0)
  35. echo "Bajando...";;
  36. esac
  37.  
  38. # Comprueba la coneccion a la mcanime.net.
  39. #if [ `ping -c 1 mcanime.net | grep "0 received" | wc -l` = 0 ]; then
  40. #   Andrade --image="$RUUTO/iconos/error.png" --window-icon="$RUUTO/iconos/icono.png" --button="Aceptar:0" --title="Error" --text="\n \n \n \No hay conección con la Mc." --width=260
  41. #   exit
  42. #fi
  43.  
  44. # Comprobar que el link sea correcto (McAnime).
  45. if [ `echo $LINKP | grep "http://www.mcanime.net" | grep "#ver" | wc -l` = 0 ]; then
  46.     Andrade --image="$RUUTO/iconos/error.png" --window-icon="$RUUTO/iconos/icono.png" --button="Aceptar:0" --title="Error" --text="\n \n \n \nLink no valido." --width=260
  47.     exit
  48. fi
  49.  
  50. Andrade --progress --window-icon="$RUUTO/iconos/icono.png" --pulsate --button="Cancelar:1"--auto-close --auto-kill --title="Descargando..." --text="\t Por favor espere." --width=200 --height=70 &
  51.  
  52. # Pagina
  53. LINK_PAG=`curl -l $LINKP 2> /dev/null`
  54.  
  55. # Titulo del manga
  56. TITULO=`echo "$LINK_PAG" | grep "Manga:" | cut -d '>' -f2 | cut -d '<' -f1`
  57.  
  58. # Capitulo del manga
  59. CAPITULO=`echo "$LINK_PAG" | grep "selected>" | cut -d '>' -f2 | awk '{ print $1 }'`
  60.  
  61. # Fansub del manga
  62. FANSUB=`echo "$LINK_PAG" | grep "Fansub:" | cut -d '>' -f2 | cut -d '<' -f1`
  63.  
  64. # Imagen a bajar
  65. PAGIN=`echo "$LINK_PAG" | grep "#ver" | tail -n 1 | cut -d '"' -f4`
  66.  
  67. # Cantidad de imagenes a bajar
  68. CAT_PAG=`echo "$LINK_PAG" | grep "selected" | tail -n1 | awk '{ print $NF }' | cut -d '>' -f2 | cut -d '<' -f1`
  69.  
  70. # Crea el archivo en el /tmp
  71. echo "" > /tmp/mc_manga
  72. echo "Titulo del manga: $TITULO" >> /tmp/mc_manga
  73. echo "" >> /tmp/mc_manga
  74. echo "Capitulo: $CAPITULO" >> /tmp/mc_manga
  75. echo "" >> /tmp/mc_manga
  76. echo "Fansub: $FANSUB" >> /tmp/mc_manga
  77. echo "" >> /tmp/mc_manga
  78. echo "Cantidad de paginas a bajar: $CAT_PAG" >> /tmp/mc_manga
  79.  
  80. killall Andrade
  81.  
  82. # Grafica
  83. Andrade --text-info --title="$TITULO" --window-icon="$RUUTO/iconos/icono.png" --image="$RUUTO/iconos/bajar.png" --filename=/tmp/mc_manga --button="Bajar:0" --width=500 --height=200
  84.  
  85. case $? in
  86. 1)
  87. exit;;
  88. 252)
  89. exit;;
  90. 0)
  91. echo "Bajando...";;
  92. esac
  93.  
  94. rm /tmp/mc_manga
  95.  
  96. LI_MA=`echo "$LINKP" | cut -d '/' -f1-7`
  97.  
  98. # crea la carpeta con el nombre y capitulo del manga
  99. mkdir "$TITULO $CAPITULO"
  100.  
  101. # Ingresa a la carpate
  102. cd "$TITULO $CAPITULO"
  103.  
  104. for MANGA in `seq 1 $CAT_PAG`; do
  105.     Andrade --progress --window-icon="$RUUTO/iconos/icono.png" --pulsate --button="Cancelar:1"--auto-close --auto-kill --title="Procesando..." --text="\tProcesando página "$MANGA" de "$CAT_PAG" \n \t Por favor espere." --width=200 --height=70 &
  106.     LINK_PAG=`curl -l "$LI_MA/$MANGA#ver" 2> /dev/null`
  107.     if [ "$MANGA" = "$CAT_PAG" ]; then
  108.         PAGIN=`echo "$LINK_PAG" | grep "><img src=" | tail -n 2 | head -n 1 | cut -d '"' -f4`
  109.     else
  110.         PAGIN=`echo "$LINK_PAG" | grep "#ver" | tail -n 1 | cut -d '"' -f4`
  111.     fi
  112.     killall Andrade
  113.     wget "$PAGIN" 2>&1 | tee /dev/stderr | sed -u "s/^ *[0-9]*K[ .]*\([0-9]*%\).*/\1/" | Andrade --title="Bajando: $TITULO " --text="\t Bajando página $MANGA de $CAT_PAG." --progress --window-icon="$RUUTO/iconos/icono.png" --width=380 --height=70 --center --button="Cancelar:1" --auto-close --auto-kill 2> /dev/null
  114. done
  115.  
  116. # Renombrando archivos.
  117. for NAMAE in `ls ?.*`; do
  118.     EXT=`echo "$NAMAE" | cut -d '.' -f2`
  119.     NOM=`echo "$NAMAE" | cut -d '.' -f1`
  120.     mv "$NAMAE" "0$NOM.$EXT"
  121. done
  122.  
  123. RESUL=`Andrade --form --window-icon="$RUUTO/iconos/icono.png" --title="$TITULO" --text="\n Descaga completa" --image="$RUUTO/iconos/descarga.png" --field="Convertir imagenes PNG a JPG:CHK" --field="Convertir imagenes a pdf:CHK" --button="Continuar:0" --button="Terminar:1"`
  124.  
  125. case $? in
  126. 1)
  127. exit;;
  128. 252)
  129. exit;;
  130. 0)
  131. echo "Bajando...";;
  132. esac
  133.  
  134. IMAGEN=`echo "$RESUL" | cut -d '|' -f1`
  135. PDF=`echo "$RESUL" | cut -d '|' -f2`
  136.  
  137. if [ $IMAGEN = TRUE ]; then
  138.     # Convierte todas las imagenes .png en .jpg.
  139.     for file in *.png ; do mv $file `echo $file | sed 's/\(.*\.\)png/\1jpg/'` ; done
  140. fi
  141. if [ $PDF = TRUE ]; then
  142.     # Convierte todas las imagenes .png en .jpg.
  143.     for file in *.png ; do mv $file `echo $file | sed 's/\(.*\.\)png/\1jpg/'` ; done
  144.     convert * $CAPITULO.pdf
  145. fi
  146.  
  147. notify-send --icon="$RUUTO/iconos/notify.png" "$TITULO $CAPITULO" "Descargado correctamente."
  148.  
  149. # Final del camino.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement