Skip to content

Instantly share code, notes, and snippets.

@ejherran
Created July 14, 2015 01:04
Show Gist options
  • Save ejherran/b9cb6f62fbc7e5876b6d to your computer and use it in GitHub Desktop.
Save ejherran/b9cb6f62fbc7e5876b6d to your computer and use it in GitHub Desktop.
Script para descargar y compilar capítulos de manga en formato pdf. Probado con el servidor de submanga.com, aunque en teoría debería funcionar con cualquier lista indexada de ficheros jpg.
#
# Javier Herran ([email protected])
# V 1.0 (2015-07-13)
# Ejemplo de uso (descarga el primer episodio de Air Gear):
# python3 get_submanga.py http://omg.submanga.com/pages/4/6/678935f
#
import subprocess as sub
import shlex as lex
import os
import sys
try:
URL = sys.argv[1]
FNULL = open(os.devnull, 'w')
print('\n\t==== START ====\n')
cok = 0
for i in range(1, 1001):
turl = URL+'/'+str(i)+'.jpg'
tname = '0'*(4-len(str(i)))+str(i)
cmd = lex.split('wget -O '+tname+'.jpg '+URL+'/'+str(i)+'.jpg')
print('\t====> Try: '+turl)
rcode = sub.call(cmd, stdout=FNULL, stderr=sub.STDOUT)
if rcode == 0:
cmd = lex.split('convert '+tname+'.jpg '+tname+'.pdf')
sub.call(cmd)
cok += 1
print('\t\tOK. File created: '+tname+'.pdf', '\n')
else:
break
print('\t\tFinished downloads!.', '\n')
if cok > 0:
sub.call("pdftk *.pdf cat output result.tmp", shell=True)
sub.call("rm -fr *.jpg", shell=True)
sub.call("rm -fr *.pdf", shell=True)
sub.call("mv result.tmp result.pdf", shell=True)
print("\t\tOK. File created: result.pdf", '\n')
else:
print("\t\tError, nothing to download.", '\n')
print('\n\t==== FINISH ====\n')
except:
print("Use python3 get_submanga.py URL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment