_library_path = None
-def download(archive, filename):
- global _library_path
- if _library_path is None:
- _library_path = get_config().get('library', 'path')
+def download(archive, filename, path=None):
+ if path is None:
+ global _library_path
+ if _library_path is None:
+ _library_path = get_config().get('library', 'path')
+ path = _library_path
- zf = ZipFile(os.path.join(_library_path, archive), 'r')
+ zf = ZipFile(os.path.join(path, archive), 'r')
infile = zf.open(filename)
outfile = open(filename, 'wb')
copyfileobj(infile, outfile)
"(found %d).\n" % count)
sys.exit(1)
book = books[0]
- download(book.archive, '%s.%s' % (book.file, book.extension.name))
+ download(book.archive, '%s.%s' % (book.file, book.extension.name),
+ args.path)
return
count = 0
for book in books:
parser.add_argument('-s', '--series', help='search by series')
parser.add_argument('-a', '--archive', help='search by archive (zip file)')
parser.add_argument('-f', '--file', help='search by file name')
+ parser.add_argument('-p', '--path', help='path to the library archives')
parser.add_argument('--get', action='store_true',
help='download exactly one book')
parser.add_argument('--id', help='search by database id')