Last active
March 16, 2021 01:10
-
-
Save crissilvaeng/b99feccd341f99aa24ac to your computer and use it in GitHub Desktop.
Mango: Informações, Busca e Download de diversos títulos de Mangá.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""Mango: Informações, Busca e Download de diversos títulos de Mangá. | |
Através da string do titulo do mangá fornecida como parâmetro, | |
o script faz uma busca em serviços de leitura online de Mangá a procura | |
do titulo informado. Caso ache, providencia informações, e disponibiliza | |
para download. | |
Repositórios suportados até o momento: | |
* Mangahost | |
""" | |
import os | |
import sys | |
import re | |
import urllib2 | |
import requests | |
from bs4 import BeautifulSoup | |
__author__ = "Cristina Silva" | |
__copyright__ = "Copyright 2014, mango" | |
__credits__ = "Cristina Silva" | |
__license__ = "MIT" | |
__version__ = "1.0" | |
__maintainer__ = "Cristina Silva" | |
__email__ = "cristina.silva@openmailbox.org" | |
__status__ = "Development" | |
directory = os.path.expanduser('~/mango') | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
if len(sys.argv) == 2: | |
if sys.argv[1] in ('-h', '-help', '--h', '--help', 'h', 'help'): | |
print "mango 1.0" | |
print "Usage: mango [options] \"title manga\"" | |
elif re.match('[A-Za-z0-9]+', sys.argv[1]): | |
title = sys.argv[1].lower().replace(" ", "-") | |
url = "http://br.mangahost.com/manga/" + title + "/" | |
header = {'User-Agent': 'Mozilla/5.0'} | |
req = urllib2.Request(url, headers=header) | |
page = urllib2.urlopen(req) | |
text = page.read().decode("utf-8") | |
soup = BeautifulSoup(text) | |
chapters = [] | |
for chapter in soup.find(attrs={'class':"list_chapters"}).findAll('a'): | |
value = str(chapter['id']) | |
chapters.append(url+value) | |
chapters.reverse() | |
print "Manga\'s Title:\t" + sys.argv[1] | |
print "Availabe Chapters:\t" + str(len(chapters)) | |
chapter = input("Download Chapter:\t") | |
directory = directory+"/"+sys.argv[1] | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
directory = directory+"/"+"Chapter_"+str('{0:04}'.format(chapter)) | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
req = urllib2.Request(chapters[chapter-1], headers=header) | |
page = urllib2.urlopen(req) | |
text = page.read().decode("utf-8") | |
soup = BeautifulSoup(text) | |
pages = [] | |
number = [] | |
for page in soup.find(attrs={'name':"Pages"}).findAll('option'): | |
number.append(int( page['value'])) | |
pages.append(sys.argv[1]+" - Capítulo "+str(chapter)+" - Página "+page['value']) | |
links = [] | |
for num in number: | |
url_page = chapters[chapter-1]+"/"+str(num) | |
req = urllib2.Request(url_page, headers=header) | |
page = urllib2.urlopen(req) | |
text = page.read().decode("utf-8") | |
soup = BeautifulSoup(text) | |
link = soup.find('img', attrs={'alt':pages[num-1]}) | |
links.append(str(link['src'])) | |
for num in number: | |
url = links[num] | |
req = urllib2.Request(url, headers=header) | |
r = urllib2.urlopen(req) | |
f = open(directory + '/' + "Page_"+str('{0:04}'.format(num))+".jpg", 'wb') | |
f.write(r.read()) | |
f.close() | |
elif len(sys.argv) == 1: | |
print "Try --help for more information." | |
else: | |
print "Invalids parameters numbers." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exemplo de uso:
Meu eu do passado não garante o resto.