X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=manga%2Fbatoto.py;h=5d6a47df9dc6d117c8f277a8030b17282f7b48ea;hb=acdde6cabb481343d32450ac88873cf0ee063c9a;hp=4e957b519b8a23ac1641eeef1fd41cbb49f07c63;hpb=08e259d771fc5de37b151dafaf0373e603b2f7c6;p=automanga.git diff --git a/manga/batoto.py b/manga/batoto.py index 4e957b5..5d6a47d 100644 --- a/manga/batoto.py +++ b/manga/batoto.py @@ -83,6 +83,7 @@ class manga(lib.manga): self.url = url self.cch = None self.stack = [] + self.cnames = None def __getitem__(self, i): return self.ch()[i] @@ -109,11 +110,34 @@ class manga(lib.manga): cid = m.group(1) url = self.lib.base + "read/_/" + cid name = ch.td.a.text - cch.append(chapter(self, [(self, len(cch))], cid, name, url)) + cch.append((cid, name, url)) cch.reverse() - self.cch = cch + rch = [] + for n, (cid, name, url) in enumerate(cch): + rch.append(chapter(self, [(self, n)], cid, name, url)) + self.cch = rch return self.cch + def altnames(self): + if self.cnames is None: + page = soup(htcache.fetch(self.url)) + cnames = None + for tbl in page.findAll("table", attrs={"class": "ipb_table"}): + if tbl.tbody is not None: tbl = tbl.tbody + for tr in tbl.findAll("tr"): + if u"Alt Names:" in tr.td.text: + nls = nextel(tr.td) + if nls.name != u"td" or nls.span is None: + raise Exception("Weird altnames table in " + self.id) + cnames = [nm.text.strip() for nm in nls.findAll("span")] + break + if cnames is not None: + break + if cnames is None: + raise Exception("Could not find altnames for " + self.id) + self.cnames = cnames + return self.cnames + def __str__(self): return self.name @@ -141,6 +165,9 @@ class library(lib.library): page = soup(resp.read()) finally: resp.close() + none = page.find("p", attrs={"class": "no_messages"}) + if none is not None and u"No results" in none.text: + return [] ret = [] for child in page.find("div", id="search_results").ol.childGenerator(): if isinstance(child, BeautifulSoup.Tag) and child.name == u"li": @@ -152,3 +179,45 @@ class library(lib.library): name = info.h3.a.string.strip() ret.append(manga(self, id, name, url)) return ret + + rure = re.compile(r"/comic/_/([^/]*)$") + def byname(self, prefix): + if not isinstance(prefix, unicode): + prefix = prefix.decode("utf8") + p = 1 + while True: + resp = urllib.urlopen(self.base + "search?" + urllib.urlencode({"name": prefix.encode("utf8"), "name_cond": "s", "p": str(p)})) + try: + page = soup(resp.read()) + finally: + resp.close() + rls = page.find("div", id="comic_search_results").table + if rls.tbody is not None: + rls = rls.tbody + hasmore = False + for child in rls.findAll("tr"): + if child.th is not None: continue + if child.get("id") == u"show_more_row": + hasmore = True + continue + link = child.td.strong.a + url = link["href"].encode("us-ascii") + m = self.rure.search(url) + if m is None: raise Exception("Got weird manga URL: %r" % url) + id = m.group(1) + name = link.text.strip() + if name[:len(prefix)].lower() != prefix.lower(): + m = manga(self, id, name, url) + for aname in m.altnames(): + if aname[:len(prefix)].lower() == prefix.lower(): + name = aname + break + else: + if False: + print "eliding " + name + print m.altnames() + continue + yield manga(self, id, name, url) + p += 1 + if not hasmore: + break