X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=manga%2Fmangafox.py;h=c95a77be7c33219c7a1d9281252159a4280c02a9;hb=59e32d8da9a36ba7b2395d8168d335786e9b4c5d;hp=110be990c4b08e827688489f5412dae9207bea3a;hpb=699d0c171c7482ce6c6a2835df7e0ba7b7505729;p=automanga.git diff --git a/manga/mangafox.py b/manga/mangafox.py index 110be99..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,8 +6,16 @@ soup = BeautifulSoup.BeautifulSoup class imgstream(lib.imgstream): def __init__(self, url): self.bk = urllib.urlopen(url) - self.ctype = self.bk.info()["Content-Type"] - self.clen = int(self.bk.info()["Content-Length"]) + 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() @@ -109,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 @@ -127,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") @@ -146,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):