X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=manga%2Fmangafox.py;h=9831a8106bbb3ee3f61be3a13f8bed9f0e9f81f1;hb=b9e558ac507f4e6c11c8c9837b5bf22b5da90fce;hp=c95a77be7c33219c7a1d9281252159a4280c02a9;hpb=59e32d8da9a36ba7b2395d8168d335786e9b4c5d;p=automanga.git diff --git a/manga/mangafox.py b/manga/mangafox.py index c95a77b..9831a81 100644 --- a/manga/mangafox.py +++ b/manga/mangafox.py @@ -1,34 +1,8 @@ import urllib, re -import BeautifulSoup +import BeautifulSoup, json import lib, htcache soup = BeautifulSoup.BeautifulSoup -class imgstream(lib.imgstream): - def __init__(self, url): - self.bk = urllib.urlopen(url) - 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() - - def read(self, sz = None): - if sz is None: - return self.bk.read() - else: - return self.bk.read(sz) - class page(lib.page): def __init__(self, chapter, stack, n, url): self.stack = stack @@ -48,7 +22,7 @@ class page(lib.page): return self.ciurl def open(self): - return imgstream(self.iurl()) + return lib.stdimgstream(self.iurl()) def __str__(self): return self.name @@ -117,7 +91,7 @@ def nextel(el): return el class manga(lib.manga): - cure = re.compile(r"/v\d+/c[\d.]+/$") + cure = re.compile(r"/c[\d.]+/$") def __init__(self, lib, id, name, url): self.lib = lib @@ -233,6 +207,14 @@ class library(lib.library): ls = self.alphapage(pno) i = 0 + def search(self, expr): + resp = urllib.urlopen(self.base + ("ajax/search.php?term=%s" % urllib.quote(expr))) + try: + rc = json.load(resp) + finally: + resp.close() + return [manga(self, id.encode("utf8"), name, self.base + ("manga/%s/" % id.encode("utf8"))) for num, name, id, genres, author in rc] + def byid(self, id): url = self.base + ("manga/%s/" % id) page = soup(htcache.fetch(url))