From cb74bd8cef84cf632ec3c6331de90ee3a23e998d Mon Sep 17 00:00:00 2001 From: dunesmopy Date: Sat, 4 Feb 2017 12:25:12 -0800 Subject: [PATCH] Support multiple input Kindle files Sample bulk/batch usage: @echo off setlocal SET IN_DIR=%USERPROFILE%\My Documents\My Kindle Content SET DEST_DIR=%IN_DIR%_drmfree SET KEY_FILE=mykeyfile.k4i mkdir "%DEST_DIR% k4mobidedrm.py -k %KEY_FILE% "%IN_DIR%" "%DEST_DIR% echo done, see %DEST_DIR% cd /d "%DEST_DIR%" start . endlocal --- .../DeDRM_App/DeDRM_lib/lib/k4mobidedrm.py | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/k4mobidedrm.py b/DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/k4mobidedrm.py index c3e475c..321c596 100644 --- a/DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/k4mobidedrm.py +++ b/DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/k4mobidedrm.py @@ -3,8 +3,8 @@ from __future__ import with_statement -# k4mobidedrm.py, version 5.3 -# Copyright © 2009-2015 by ApprenticeHarper et al. +# k4mobidedrm.py, version 5.5 +# Copyright © 2009-2017 by ApprenticeHarper et al. # engine to remove drm from Kindle and Mobipocket ebooks # for personal use for archiving and converting your ebooks @@ -57,6 +57,7 @@ from __future__ import with_statement # 5.2 - Fixed error in command line processing of unicode arguments # 5.3 - Changed Android support to allow passing of backup .ab files # 5.4 - Recognise KFX files masquerading as azw, even if we can't decrypt them yet. +# 5.5 - Support multiple input files __version__ = '5.4' @@ -64,6 +65,7 @@ __version__ = '5.4' import sys, os, re import csv import getopt +import glob import re import traceback import time @@ -287,7 +289,7 @@ def decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serials, pids): def usage(progname): print u"Removes DRM protection from Mobipocket, Amazon KF8, Amazon Print Replica and Amazon Topaz ebooks" print u"Usage:" - print u" {0} [-k ] [-p ] [-s ] [ -a ] ".format(progname) + print u" {0} [-k ] [-p ] [-s ] [ -a ] ".format(progname) # # Main @@ -307,8 +309,7 @@ def cli_main(): usage(progname) sys.exit(2) - infile = args[0] - outdir = args[1] + outdir = args.pop() kDatabaseFiles = [] androidFiles = [] serials = [] @@ -335,7 +336,17 @@ def cli_main(): # try with built in Kindle Info files if not on Linux k4 = not sys.platform.startswith('linux') - return decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serials, pids) + if len(args) == 1: + arg = args[0] + if os.path.isdir(arg): + args = glob.glob(os.path.join(arg, '*.azw')) + + for infile in args: + result = decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serials, pids) + if result != 0: + print u'Error with %r' % infile + # return last result only + return result if __name__ == '__main__':