X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=getmanga;h=bd8401eda887715d90b91db93983f8c92877206f;hb=aaab61eebf2f076758cd55033a1f6af2db8ea10d;hp=f678e3398a02e533c4a1752e4d5a7fd8d895c1ac;hpb=da9e5bf6b53708f4237936d0f0804e6a705f4875;p=automanga.git diff --git a/getmanga b/getmanga index f678e33..bd8401e 100755 --- a/getmanga +++ b/getmanga @@ -12,7 +12,7 @@ def msg(vl, msg, *args): sys.stderr.write("getmanga: " + (msg % args) + "\n") def getprop(nm, default=None): - if "dl-" + nm in mprof.props: + if mprof and "dl-" + nm in mprof.props: return mprof.props["dl-" + nm] if nm in props: return props[nm] @@ -83,11 +83,17 @@ def download(mng, tdir, pattern): msg(1, "getting %s...", nm) with page.open() as fp: with open(path, "wb") as out: - while True: - data = fp.read(65536) - if data == b"": - break - out.write(data) + done = False + try: + while True: + data = fp.read(65536) + if data == b"": + done = True + break + out.write(data) + finally: + if not done: + os.unlink(path) try: img = Image.open(path) except OSError: @@ -105,12 +111,16 @@ def download(mng, tdir, pattern): def usage(out): out.write("usage: getmanga [-hv] [-w WAIT] [-p PROFILE] [-P PATTERN] DIRECTORY [LIBRARY ID]\n") + out.write("\tpattern templates:\n") + out.write("\t %i\tSequence number\n") + out.write("\t %n\tName\n") + out.write("\t %d\tID\n") def main(): global verbose, wait, mprof, props opts, args = getopt.getopt(sys.argv[1:], "hvp:w:P:") - profnm = "" + profnm = None pattern = None for o, a in opts: if o == "-h": @@ -143,8 +153,10 @@ def main(): elif words[0] == "lset" and len(words) > 1: props[words[1]] = words[2:] - if profnm == "": + if profnm is None: profile = manga.profile.profile.last() + elif profnm == "": + profile = None else: profile = manga.profile.profile.byname(profnm) @@ -168,9 +180,12 @@ def main(): except KeyError: sys.stderr.write("getmanga: no such manga: %s\n" % (mid)) sys.exit(1) - mprof = profile.getmanga(libnm, mng.id) + if profile is not None: + mprof = profile.getmanga(libnm, mng.id) + else: + mprof = None - download(mprof.open(), tdir, pattern or getprop("pattern")) + download(mng, tdir, pattern or getprop("pattern")) if __name__ == "__main__": try: