Skip to content

Instantly share code, notes, and snippets.

@minitech
Created June 30, 2012 18:38
Show Gist options
  • Save minitech/3025010 to your computer and use it in GitHub Desktop.
Save minitech/3025010 to your computer and use it in GitHub Desktop.
Manga Downloader
# My first Python program.
# Feedback please; anything non-Pythonic here?
manga = raw_input("Enter the slug name of the manga: ")
while True:
try:
start = int(raw_input("Start chapter: "))
break
except ValueError:
pass
while True:
try:
end = int(raw_input("End chapter: "))
break
except ValueError:
pass
print("Getting chapters from %d to %d of %s." % (start, end, manga))
import urllib2
import re
for chapter in xrange(start, end + 1):
page = 0
try:
while True:
page += 1
print("Fetching page %d of chapter %d..." % (page, chapter))
handle = urllib2.urlopen("http://manga.animea.net/%s-chapter-%d-page-%d.html" % (manga, chapter, page))
content = handle.read()
handle.close()
m = re.search(r'src="(.+?)"[^>]+class="mangaimg"', content)
if m is not None:
url = m.group(1)
m = re.search(r'\.([a-zA-Z]+)$', url)
if m is None:
break
local = open("%s-%d-%d.%s" % (manga, chapter, page, m.group(1)), 'w')
handle = urllib2.urlopen(url)
local.write(handle.read())
handle.close()
local.close()
else:
print("Failed to find data for page %d." % (page,))
break
except urllib2.URLError:
print("Got a URLError trying to fetch page %d of chapter %d" % (page, chapter))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment