X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=manga%2Fmangafox.py;h=c95a77be7c33219c7a1d9281252159a4280c02a9;hb=59e32d8da9a36ba7b2395d8168d335786e9b4c5d;hp=8c23630c42a43b1419581ec9150b0eb394272c05;hpb=46b3b90eef4007f3f4e871afd4854f7a06c8bfc8;p=automanga.git diff --git a/manga/mangafox.py b/manga/mangafox.py index 8c23630..c95a77b 100644 --- a/manga/mangafox.py +++ b/manga/mangafox.py @@ -1,4 +1,4 @@ -import urllib +import urllib, re import BeautifulSoup import lib, htcache soup = BeautifulSoup.BeautifulSoup @@ -6,7 +6,19 @@ soup = BeautifulSoup.BeautifulSoup class imgstream(lib.imgstream): def __init__(self, url): self.bk = urllib.urlopen(url) - self.ctype = self.bk.info()["Content-Type"] + ok = False + try: + if self.bk.getcode() != 200: + raise IOError("Server error: " + str(self.bk.getcode())) + self.ctype = self.bk.info()["Content-Type"] + self.clen = int(self.bk.info()["Content-Length"]) + ok = True + finally: + if not ok: + self.bk.close() + + def fileno(self): + return self.bk.fileno() def close(self): self.bk.close() @@ -25,6 +37,7 @@ class page(lib.page): self.manga = self.volume.manga self.n = n self.id = str(n) + self.name = u"Page %s" % n self.url = url self.ciurl = None @@ -37,6 +50,12 @@ class page(lib.page): def open(self): return imgstream(self.iurl()) + def __str__(self): + return self.name + + def __repr__(self): + return "" % (self.manga.name, self.volume.name, self.chapter.name, self.name) + class chapter(lib.pagelist): def __init__(self, volume, stack, id, name, url): self.stack = stack @@ -98,6 +117,8 @@ def nextel(el): return el class manga(lib.manga): + cure = re.compile(r"/v\d+/c[\d.]+/$") + def __init__(self, lib, id, name, url): self.lib = lib self.id = id @@ -116,7 +137,7 @@ class manga(lib.manga): if self.cvol is None: page = soup(htcache.fetch(self.url)) vls = page.find("div", id="chapters").findAll("div", attrs={"class": "slide"}) - self.cvol = [] + cvol = [] for i, vn in enumerate(reversed(vls)): name = vn.find("h3", attrs={"class": "volume"}).contents[0].strip() vid = name.encode("utf8") @@ -135,10 +156,15 @@ class manga(lib.manga): except KeyError: pass url = n.a["href"].encode("us-ascii") - if url[-7:] != "/1.html": + if url[-7:] == "/1.html": + url = url[:-6] + elif self.cure.search(url) is not None: + pass + else: raise Exception("parse error: unexpected chapter URL for %r: %s" % (self, url)) - vol.ch.append(chapter(vol, vol.stack + [(vol, o)], chid, name, url[:-6])) - self.cvol.append(vol) + vol.ch.append(chapter(vol, vol.stack + [(vol, o)], chid, name, url)) + cvol.append(vol) + self.cvol = cvol return self.cvol def __str__(self): @@ -152,7 +178,7 @@ def libalphacmp(a, b): class library(lib.library): def __init__(self): - self.base = "http://www.mangafox.com/" + self.base = "http://mangafox.me/" def alphapage(self, pno): page = soup(htcache.fetch(self.base + ("directory/%i.htm?az" % pno)))