3 import sys, getopt, pathlib
4 import manga.lib, manga.reader, manga.profile, manga.local
5 from gi.repository import Gtk, Gdk, GObject
8 out.write("usage: automanga [-h] [-p PROFILE] {DIRECTORY|-l LIBRARY ID|-a ALIAS}\n")
9 out.write(" automanga -a ALIAS=LIBRARY:ID\n")
10 out.write(" automanga -t {DIRECTORY|-l LIBRARY ID|-a ALIAS} [-]TAG...\n")
11 out.write(" automanga -{s|S} LIBRARY NAME\n")
12 out.write(" automanga -L TAG\n")
20 opts, args = getopt.getopt(sys.argv[1:], "hl:sSp:a:tL:")
44 profile = manga.profile.profile.last()
46 profile = manga.profile.profile.byname("default")
47 elif profile is not None:
48 profile = manga.profile.profile.byname(profile)
58 lib = manga.lib.findlib(args[0])
60 sys.stderr.write("automanga: no such library: %s\n" % args[0])
64 results = lib.byname(args[1])
65 elif search == "match":
66 results = lib.search(args[1])
67 if hasattr(results, "__length_hint__"):
68 sys.stderr.write("%i results:\n" % results.__length_hint__())
69 except NotImplementedError:
70 sys.stderr.write("automanga: %s does not support searching\n" % args[0])
73 sys.stdout.write("\"%s\": %s\n" % (mng.name, mng.id))
76 if listtag is not None:
77 if profile is not None:
78 for mprof in profile.bytag(listtag):
82 sys.stderr.write("%s %s: no longer found\n" % (mprof.libnm, mprof.id))
84 sys.stdout.write("%s %s: \"%s\"\n" % (mprof.libnm, mprof.id, mng.name))
87 if alias and (alias.find('=') > 0):
88 tgt, nm = alias.split('=', 1)
92 libname, mid = nm.split(':', 1)
94 lib = manga.lib.findlib(libname)
96 sys.stderr.write("automanga: no such library: %s\n" % libname)
100 except KeyError as e:
101 sys.stderr.write("automanga: no such manga: %s\n" % str(e))
103 profile.setalias(tgt, libname, mng.id)
108 libname, mid = profile.getalias(alias)
110 sys.stderr.write("automanga: no such alias: %s\n" % alias)
113 lib = manga.lib.findlib(libname)
115 sys.stderr.write("automanga: no such library: %s\n" % libname)
120 sys.stderr.write("automanga: manga no longer found: %s\n" % mid)
122 elif libname is not None:
127 lib = manga.lib.findlib(libname)
129 sys.stderr.write("automanga: no such library: %s\n" % libname)
132 mng = lib.byid(args.pop(0))
133 except KeyError as e:
134 sys.stderr.write("automanga: no such manga: %s\n" % str(e))
143 mng = manga.local.manga(pathlib.Path(mdir))
145 sys.stderr.write("automanga: not a valid manga directory: %s\n" % mdir)
148 mprof = None if profile is None else profile.getmanga(libname, mng.id, True)
149 if profile is not None:
153 if mprof is not None:
154 ntags = [tag for tag in args if tag[:1] != "-"]
155 rtags = [tag[1:] for tag in args if tag[:1] == "-"]
156 if ntags: mprof.tags.add(*ntags)
157 if rtags: mprof.tags.remove(*rtags)
160 reader = manga.reader.reader(mng, mprof)
166 except KeyboardInterrupt: