Added simplistic keyword searching to mrnet and local libraries.
[automanga.git] / manga / local.py
index d1a839c..2d79b20 100644 (file)
@@ -128,6 +128,8 @@ class manga(lib.manga):
         ordered, files = self.imglist()
         pages, orig = self.bakenames(files)
         mx = maxstruct(pages)
+        if mx is None:
+            raise TypeError("could not figure out any structure")
         var = [i for i, part in enumerate(mx) if part == int]
         structs = [(nm, decode1(nm)) for nm in pages]
         if not ordered:
@@ -151,9 +153,15 @@ class manga(lib.manga):
                         oids.append(cur)
                 ret = []
                 for id in oids:
-                    cur = interm(id, id, p.stack + [(p, len(ret))], [])
-                    cur.direct = constree(cur, [(nm, st) for nm, st in structs if st[var[idx]] == id], idx + 1)
-                    ret.append(cur)
+                    sub = [(nm, st) for nm, st in structs if st[var[idx]] == id]
+                    if len(sub) == 1:
+                        nm, st = sub[0]
+                        id = "".join(st[var[idx]:])
+                        ret.append(page(self, pj(self.path, orig[nm]), id, id, p.stack + [(p, len(ret))]))
+                    else:
+                        cur = interm(id, id, p.stack + [(p, len(ret))], [])
+                        cur.direct = constree(cur, sub, idx + 1)
+                        ret.append(cur)
                 return ret
         return constree(self, structs, 0)
 
@@ -177,8 +185,13 @@ class directory(dumb):
                 ret.append(manga(pj(self.path, dent)))
         return ret
 
+    def search(self, expr):
+        expr = expr.lower()
+        return [manga(pj(self.path, dent)) for dent in os.listdir(self.path) if expr in dent.lower()]
+
     def __iter__(self):
         for dent in os.listdir(self.path):
             yield manga(pj(self.path, dent))
 
+
 library = dumb