12 while p < len(nm) and nm[p].isdigit():
18 while p < len(nm) and nm[p].isalpha():
35 class imgstream(lib.imgstream):
36 def __init__(self, path):
37 self.bk = open(path, 'rb')
38 self.clen = os.fstat(self.bk.fileno()).st_size
43 def read(self, sz=None):
44 return self.bk.read(sz)
47 def __init__(self, manga, path, name, id, stack):
55 return imgstream(self.path)
57 class interm(lib.pagelist):
58 def __init__(self, name, id, stack, direct):
65 return len(self.direct)
67 def __getitem__(self, n):
73 s = genstr(decode1(dent))
78 for p, n in zip(mx, s):
86 class manga(lib.manga):
87 exts = ["jpg", "jpeg", "png", "gif"]
89 def __init__(self, path):
90 path = os.path.abspath(path)
91 if not os.path.isdir(path):
92 raise IOError("No such directory: " + path)
96 if os.path.exists(pj(self.path, "name")):
97 with open(pj(self.path, "name")) as s:
98 self.name = s.readline().strip()
100 self.name = os.path.basename(path)
101 self.direct = self.destruct()
104 return len(self.direct)
106 def __getitem__(self, idx):
107 return self.direct[idx]
110 if os.path.exists(pj(self.path, "order")):
111 with open(pj(self.path, "order")) as s:
112 return True, [line.strip() for line in s if os.path.exists(pj(self.path, line.strip()))]
114 return False, [dent for dent in os.listdir(self.path) if '.' in dent and dent[dent.rindex('.') + 1:] in self.exts]
116 def bakenames(self, files):
122 nm = nm[:nm.rindex('.')]
128 ordered, files = self.imglist()
129 pages, orig = self.bakenames(files)
130 mx = maxstruct(pages)
132 raise TypeError("could not figure out any structure")
133 var = [i for i, part in enumerate(mx) if part == int]
134 structs = [(nm, decode1(nm)) for nm in pages]
136 structs.sort(key=lambda o: "".join(o[1][len(mx):]))
137 for i in reversed(var):
138 structs.sort(key=lambda o: int(o[1][i]))
139 def constree(p, structs, idx):
142 for nm, st in structs:
143 id = "".join(st[len(mx):])
144 pages.append(page(self, pj(self.path, orig[nm]), id, id, p.stack + [(p, len(pages))]))
149 for nm, st in structs:
156 sub = [(nm, st) for nm, st in structs if st[var[idx]] == id]
159 id = "".join(st[var[idx]:])
160 ret.append(page(self, pj(self.path, orig[nm]), id, id, p.stack + [(p, len(ret))]))
162 cur = interm(id, id, p.stack + [(p, len(ret))], [])
163 cur.direct = constree(cur, sub, idx + 1)
166 return constree(self, structs, 0)
168 class dumb(lib.library):
170 if not os.path.isdir(id):
174 class directory(dumb):
175 def __init__(self, path):
176 if not os.path.isdir(path):
177 raise IOError("No such directory: " + path)
180 def byname(self, prefix):
182 prefix = prefix.lower()
183 for dent in os.listdir(self.path):
184 if dent[:len(prefix)].lower() == prefix:
185 ret.append(manga(pj(self.path, dent)))
188 def search(self, expr):
190 return [manga(pj(self.path, dent)) for dent in os.listdir(self.path) if expr in dent.lower()]
193 for dent in os.listdir(self.path):
194 yield manga(pj(self.path, dent))