2011-01-17 13:24:53 +06:00
|
|
|
|
#!/usr/bin/env python
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
|
|
|
|
from __future__ import with_statement
|
|
|
|
|
|
2017-02-05 02:25:12 +06:00
|
|
|
|
# k4mobidedrm.py, version 5.5
|
|
|
|
|
# Copyright © 2009-2017 by ApprenticeHarper et al.
|
2012-12-19 19:48:11 +06:00
|
|
|
|
|
2015-07-29 23:11:19 +06:00
|
|
|
|
# engine to remove drm from Kindle and Mobipocket ebooks
|
2011-01-17 13:24:53 +06:00
|
|
|
|
# for personal use for archiving and converting your ebooks
|
|
|
|
|
|
2012-03-07 00:24:28 +06:00
|
|
|
|
# PLEASE DO NOT PIRATE EBOOKS!
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
2015-07-29 23:11:19 +06:00
|
|
|
|
# We want all authors and publishers, and ebook stores to live
|
2012-03-07 00:24:28 +06:00
|
|
|
|
# long and prosperous lives but at the same time we just want to
|
|
|
|
|
# be able to read OUR books on whatever device we want and to keep
|
2011-01-17 13:24:53 +06:00
|
|
|
|
# readable for a long, long time
|
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# This borrows very heavily from works by CMBDTC, IHeartCabbages, skindle,
|
2012-03-07 00:24:28 +06:00
|
|
|
|
# unswindle, DarkReverser, ApprenticeAlf, DiapDealer, some_updates
|
2011-01-17 13:24:53 +06:00
|
|
|
|
# and many many others
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# Special thanks to The Dark Reverser for MobiDeDrm and CMBDTC for cmbdtc_dump
|
|
|
|
|
# from which this script borrows most unashamedly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Changelog
|
|
|
|
|
# 1.0 - Name change to k4mobidedrm. Adds Mac support, Adds plugin code
|
|
|
|
|
# 1.1 - Adds support for additional kindle.info files
|
|
|
|
|
# 1.2 - Better error handling for older Mobipocket
|
|
|
|
|
# 1.3 - Don't try to decrypt Topaz books
|
|
|
|
|
# 1.7 - Add support for Topaz books and Kindle serial numbers. Split code.
|
|
|
|
|
# 1.9 - Tidy up after Topaz, minor exception changes
|
|
|
|
|
# 2.1 - Topaz fix and filename sanitizing
|
|
|
|
|
# 2.2 - Topaz Fix and minor Mac code fix
|
|
|
|
|
# 2.3 - More Topaz fixes
|
|
|
|
|
# 2.4 - K4PC/Mac key generation fix
|
|
|
|
|
# 2.6 - Better handling of non-K4PC/Mac ebooks
|
|
|
|
|
# 2.7 - Better trailing bytes handling in mobidedrm
|
|
|
|
|
# 2.8 - Moved parsing of kindle.info files to mac & pc util files.
|
|
|
|
|
# 3.1 - Updated for new calibre interface. Now __init__ in plugin.
|
|
|
|
|
# 3.5 - Now support Kindle for PC/Mac 1.6
|
|
|
|
|
# 3.6 - Even better trailing bytes handling in mobidedrm
|
|
|
|
|
# 3.7 - Add support for Amazon Print Replica ebooks.
|
|
|
|
|
# 3.8 - Improved Topaz support
|
|
|
|
|
# 4.1 - Improved Topaz support and faster decryption with alfcrypto
|
|
|
|
|
# 4.2 - Added support for Amazon's KF8 format ebooks
|
|
|
|
|
# 4.4 - Linux calls to Wine added, and improved configuration dialog
|
|
|
|
|
# 4.5 - Linux works again without Wine. Some Mac key file search changes
|
|
|
|
|
# 4.6 - First attempt to handle unicode properly
|
|
|
|
|
# 4.7 - Added timing reports, and changed search for Mac key files
|
|
|
|
|
# 4.8 - Much better unicode handling, matching the updated inept and ignoble scripts
|
|
|
|
|
# - Moved back into plugin, __init__ in plugin now only contains plugin code.
|
2013-01-19 20:50:57 +06:00
|
|
|
|
# 4.9 - Missed some invalid characters in cleanup_name
|
2013-03-20 16:23:54 +06:00
|
|
|
|
# 5.0 - Extraction of info from Kindle for PC/Mac moved into kindlekey.py
|
|
|
|
|
# - tweaked GetDecryptedBook interface to leave passed parameters unchanged
|
2013-03-26 22:38:18 +06:00
|
|
|
|
# 5.1 - moved unicode_argv call inside main for Windows DeDRM compatibility
|
2013-04-10 16:50:10 +06:00
|
|
|
|
# 5.2 - Fixed error in command line processing of unicode arguments
|
2015-07-29 23:11:19 +06:00
|
|
|
|
# 5.3 - Changed Android support to allow passing of backup .ab files
|
2017-01-12 13:24:42 +06:00
|
|
|
|
# 5.4 - Recognise KFX files masquerading as azw, even if we can't decrypt them yet.
|
2017-02-05 02:25:12 +06:00
|
|
|
|
# 5.5 - Support multiple input files
|
2012-12-19 19:48:11 +06:00
|
|
|
|
|
2017-01-12 13:24:42 +06:00
|
|
|
|
__version__ = '5.4'
|
2012-12-19 19:48:11 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import sys, os, re
|
|
|
|
|
import csv
|
|
|
|
|
import getopt
|
2017-02-05 02:25:12 +06:00
|
|
|
|
import glob
|
2011-01-17 13:24:53 +06:00
|
|
|
|
import re
|
2011-10-28 12:24:15 +06:00
|
|
|
|
import traceback
|
2012-11-20 19:28:12 +06:00
|
|
|
|
import time
|
2012-12-19 19:48:11 +06:00
|
|
|
|
import htmlentitydefs
|
2013-03-20 16:23:54 +06:00
|
|
|
|
import json
|
2012-03-07 00:24:28 +06:00
|
|
|
|
|
2011-01-17 13:24:53 +06:00
|
|
|
|
class DrmException(Exception):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if 'calibre' in sys.modules:
|
|
|
|
|
inCalibre = True
|
|
|
|
|
else:
|
|
|
|
|
inCalibre = False
|
|
|
|
|
|
2011-06-16 11:59:20 +06:00
|
|
|
|
if inCalibre:
|
2013-03-20 16:23:54 +06:00
|
|
|
|
from calibre_plugins.dedrm import mobidedrm
|
|
|
|
|
from calibre_plugins.dedrm import topazextract
|
|
|
|
|
from calibre_plugins.dedrm import kgenpids
|
2015-03-17 13:05:00 +06:00
|
|
|
|
from calibre_plugins.dedrm import androidkindlekey
|
2011-06-16 11:59:20 +06:00
|
|
|
|
else:
|
|
|
|
|
import mobidedrm
|
|
|
|
|
import topazextract
|
|
|
|
|
import kgenpids
|
2015-03-17 13:05:00 +06:00
|
|
|
|
import androidkindlekey
|
2012-03-07 00:24:28 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# Wrap a stream so that output gets flushed immediately
|
|
|
|
|
# and also make sure that any unicode strings get
|
|
|
|
|
# encoded using "replace" before writing them.
|
|
|
|
|
class SafeUnbuffered:
|
|
|
|
|
def __init__(self, stream):
|
|
|
|
|
self.stream = stream
|
|
|
|
|
self.encoding = stream.encoding
|
|
|
|
|
if self.encoding == None:
|
|
|
|
|
self.encoding = "utf-8"
|
|
|
|
|
def write(self, data):
|
|
|
|
|
if isinstance(data,unicode):
|
|
|
|
|
data = data.encode(self.encoding,"replace")
|
|
|
|
|
self.stream.write(data)
|
|
|
|
|
self.stream.flush()
|
|
|
|
|
def __getattr__(self, attr):
|
|
|
|
|
return getattr(self.stream, attr)
|
|
|
|
|
|
|
|
|
|
iswindows = sys.platform.startswith('win')
|
|
|
|
|
isosx = sys.platform.startswith('darwin')
|
|
|
|
|
|
|
|
|
|
def unicode_argv():
|
|
|
|
|
if iswindows:
|
|
|
|
|
# Uses shell32.GetCommandLineArgvW to get sys.argv as a list of Unicode
|
|
|
|
|
# strings.
|
|
|
|
|
|
|
|
|
|
# Versions 2.x of Python don't support Unicode in sys.argv on
|
|
|
|
|
# Windows, with the underlying Windows API instead replacing multi-byte
|
|
|
|
|
# characters with '?'.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from ctypes import POINTER, byref, cdll, c_int, windll
|
|
|
|
|
from ctypes.wintypes import LPCWSTR, LPWSTR
|
|
|
|
|
|
|
|
|
|
GetCommandLineW = cdll.kernel32.GetCommandLineW
|
|
|
|
|
GetCommandLineW.argtypes = []
|
|
|
|
|
GetCommandLineW.restype = LPCWSTR
|
|
|
|
|
|
|
|
|
|
CommandLineToArgvW = windll.shell32.CommandLineToArgvW
|
|
|
|
|
CommandLineToArgvW.argtypes = [LPCWSTR, POINTER(c_int)]
|
|
|
|
|
CommandLineToArgvW.restype = POINTER(LPWSTR)
|
|
|
|
|
|
|
|
|
|
cmd = GetCommandLineW()
|
|
|
|
|
argc = c_int(0)
|
|
|
|
|
argv = CommandLineToArgvW(cmd, byref(argc))
|
|
|
|
|
if argc.value > 0:
|
|
|
|
|
# Remove Python executable and commands if present
|
|
|
|
|
start = argc.value - len(sys.argv)
|
|
|
|
|
return [argv[i] for i in
|
|
|
|
|
xrange(start, argc.value)]
|
|
|
|
|
# if we don't have any arguments at all, just pass back script name
|
|
|
|
|
# this should never happen
|
|
|
|
|
return [u"mobidedrm.py"]
|
|
|
|
|
else:
|
|
|
|
|
argvencoding = sys.stdin.encoding
|
|
|
|
|
if argvencoding == None:
|
|
|
|
|
argvencoding = "utf-8"
|
|
|
|
|
return [arg if (type(arg) == unicode) else unicode(arg,argvencoding) for arg in sys.argv]
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# cleanup unicode filenames
|
2011-01-17 13:24:53 +06:00
|
|
|
|
# borrowed from calibre from calibre/src/calibre/__init__.py
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# added in removal of control (<32) chars
|
|
|
|
|
# and removal of . at start and end
|
|
|
|
|
# and with some (heavily edited) code from Paul Durrant's kindlenamer.py
|
2011-01-17 13:24:53 +06:00
|
|
|
|
def cleanup_name(name):
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# substitute filename unfriendly characters
|
2013-01-19 20:50:57 +06:00
|
|
|
|
name = name.replace(u"<",u"[").replace(u">",u"]").replace(u" : ",u" – ").replace(u": ",u" – ").replace(u":",u"—").replace(u"/",u"_").replace(u"\\",u"_").replace(u"|",u"_").replace(u"\"",u"\'").replace(u"*",u"_").replace(u"?",u"")
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# delete control characters
|
|
|
|
|
name = u"".join(char for char in name if ord(char)>=32)
|
|
|
|
|
# white space to single space, delete leading and trailing while space
|
|
|
|
|
name = re.sub(ur"\s", u" ", name).strip()
|
|
|
|
|
# remove leading dots
|
|
|
|
|
while len(name)>0 and name[0] == u".":
|
|
|
|
|
name = name[1:]
|
|
|
|
|
# remove trailing dots (Windows doesn't like them)
|
|
|
|
|
if name.endswith(u'.'):
|
|
|
|
|
name = name[:-1]
|
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
# must be passed unicode
|
|
|
|
|
def unescape(text):
|
|
|
|
|
def fixup(m):
|
|
|
|
|
text = m.group(0)
|
|
|
|
|
if text[:2] == u"&#":
|
|
|
|
|
# character reference
|
|
|
|
|
try:
|
|
|
|
|
if text[:3] == u"&#x":
|
|
|
|
|
return unichr(int(text[3:-1], 16))
|
|
|
|
|
else:
|
|
|
|
|
return unichr(int(text[2:-1]))
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
# named entity
|
|
|
|
|
try:
|
|
|
|
|
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
|
|
|
|
|
except KeyError:
|
|
|
|
|
pass
|
|
|
|
|
return text # leave as is
|
|
|
|
|
return re.sub(u"&#?\w+;", fixup, text)
|
|
|
|
|
|
2015-07-29 23:11:19 +06:00
|
|
|
|
def GetDecryptedBook(infile, kDatabases, androidFiles, serials, pids, starttime = time.time()):
|
2011-01-17 13:24:53 +06:00
|
|
|
|
# handle the obvious cases at the beginning
|
|
|
|
|
if not os.path.isfile(infile):
|
2013-06-12 00:41:21 +06:00
|
|
|
|
raise DrmException(u"Input file does not exist.")
|
2012-11-20 19:28:12 +06:00
|
|
|
|
|
2011-01-17 13:24:53 +06:00
|
|
|
|
mobi = True
|
2017-01-12 13:24:42 +06:00
|
|
|
|
magic8 = open(infile,'rb').read(8)
|
|
|
|
|
if magic8 == '\xeaDRMION\xee':
|
|
|
|
|
raise DrmException(u"KFX format detected. This format cannot be decrypted yet.")
|
|
|
|
|
|
|
|
|
|
magic3 = magic8[:3]
|
2011-01-17 13:24:53 +06:00
|
|
|
|
if magic3 == 'TPZ':
|
|
|
|
|
mobi = False
|
|
|
|
|
|
|
|
|
|
if mobi:
|
|
|
|
|
mb = mobidedrm.MobiBook(infile)
|
|
|
|
|
else:
|
2011-06-16 11:59:20 +06:00
|
|
|
|
mb = topazextract.TopazBook(infile)
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
bookname = unescape(mb.getBookTitle())
|
|
|
|
|
print u"Decrypting {1} ebook: {0}".format(bookname, mb.getBookType())
|
2012-03-07 00:24:28 +06:00
|
|
|
|
|
2013-03-20 16:23:54 +06:00
|
|
|
|
# copy list of pids
|
|
|
|
|
totalpids = list(pids)
|
2015-07-29 23:11:19 +06:00
|
|
|
|
# extend list of serials with serials from android databases
|
|
|
|
|
for aFile in androidFiles:
|
|
|
|
|
serials.extend(androidkindlekey.get_serials(aFile))
|
|
|
|
|
# extend PID list with book-specific PIDs from seriala and kDatabases
|
2011-01-17 13:24:53 +06:00
|
|
|
|
md1, md2 = mb.getPIDMetaInfo()
|
2013-03-20 16:23:54 +06:00
|
|
|
|
totalpids.extend(kgenpids.getPidList(md1, md2, serials, kDatabases))
|
2015-07-29 23:11:19 +06:00
|
|
|
|
# remove any duplicates
|
2017-01-12 13:24:42 +06:00
|
|
|
|
totalpids = list(set(totalpids))
|
2013-03-20 16:23:54 +06:00
|
|
|
|
print u"Found {1:d} keys to try after {0:.1f} seconds".format(time.time()-starttime, len(totalpids))
|
2017-01-12 13:24:42 +06:00
|
|
|
|
#print totalpids
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
|
|
|
|
try:
|
2013-03-20 16:23:54 +06:00
|
|
|
|
mb.processBook(totalpids)
|
2012-12-19 19:48:11 +06:00
|
|
|
|
except:
|
|
|
|
|
mb.cleanup
|
|
|
|
|
raise
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
print u"Decryption succeeded after {0:.1f} seconds".format(time.time()-starttime)
|
|
|
|
|
return mb
|
|
|
|
|
|
|
|
|
|
|
2013-03-20 16:23:54 +06:00
|
|
|
|
# kDatabaseFiles is a list of files created by kindlekey
|
2015-07-29 23:11:19 +06:00
|
|
|
|
def decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serials, pids):
|
2012-12-19 19:48:11 +06:00
|
|
|
|
starttime = time.time()
|
2013-03-20 16:23:54 +06:00
|
|
|
|
kDatabases = []
|
|
|
|
|
for dbfile in kDatabaseFiles:
|
|
|
|
|
kindleDatabase = {}
|
|
|
|
|
try:
|
|
|
|
|
with open(dbfile, 'r') as keyfilein:
|
|
|
|
|
kindleDatabase = json.loads(keyfilein.read())
|
|
|
|
|
kDatabases.append([dbfile,kindleDatabase])
|
|
|
|
|
except Exception, e:
|
|
|
|
|
print u"Error getting database from file {0:s}: {1:s}".format(dbfile,e)
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
try:
|
2015-07-29 23:11:19 +06:00
|
|
|
|
book = GetDecryptedBook(infile, kDatabases, androidFiles, serials, pids, starttime)
|
2011-01-17 13:24:53 +06:00
|
|
|
|
except Exception, e:
|
2012-12-19 19:48:11 +06:00
|
|
|
|
print u"Error decrypting book after {1:.1f} seconds: {0}".format(e.args[0],time.time()-starttime)
|
2013-01-19 20:50:57 +06:00
|
|
|
|
traceback.print_exc()
|
2011-06-16 11:59:20 +06:00
|
|
|
|
return 1
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# if we're saving to the same folder as the original, use file name_
|
|
|
|
|
# if to a different folder, use book name
|
|
|
|
|
if os.path.normcase(os.path.normpath(outdir)) == os.path.normcase(os.path.normpath(os.path.dirname(infile))):
|
|
|
|
|
outfilename = os.path.splitext(os.path.basename(infile))[0]
|
|
|
|
|
else:
|
|
|
|
|
outfilename = cleanup_name(book.getBookTitle())
|
2012-11-20 19:28:12 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# avoid excessively long file names
|
|
|
|
|
if len(outfilename)>150:
|
2015-07-29 23:11:19 +06:00
|
|
|
|
outfilename = outfilename[:99]+"--"+outfilename[-49:]
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
outfilename = outfilename+u"_nodrm"
|
|
|
|
|
outfile = os.path.join(outdir, outfilename + book.getBookExtension())
|
2011-06-16 11:59:20 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
book.getFile(outfile)
|
|
|
|
|
print u"Saved decrypted book {1:s} after {0:.1f} seconds".format(time.time()-starttime, outfilename)
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
if book.getBookType()==u"Topaz":
|
|
|
|
|
zipname = os.path.join(outdir, outfilename + u"_SVG.zip")
|
|
|
|
|
book.getSVGZip(zipname)
|
|
|
|
|
print u"Saved SVG ZIP Archive for {1:s} after {0:.1f} seconds".format(time.time()-starttime, outfilename)
|
2011-06-16 11:59:20 +06:00
|
|
|
|
|
|
|
|
|
# remove internal temporary directory of Topaz pieces
|
2012-12-19 19:48:11 +06:00
|
|
|
|
book.cleanup()
|
2013-01-19 20:50:57 +06:00
|
|
|
|
return 0
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def usage(progname):
|
2012-12-19 19:48:11 +06:00
|
|
|
|
print u"Removes DRM protection from Mobipocket, Amazon KF8, Amazon Print Replica and Amazon Topaz ebooks"
|
|
|
|
|
print u"Usage:"
|
2017-02-05 02:25:12 +06:00
|
|
|
|
print u" {0} [-k <kindle.k4i>] [-p <comma separated PIDs>] [-s <comma separated Kindle serial numbers>] [ -a <AmazonSecureStorage.xml|backup.ab> ] <infile, infiles, or indir> <outdir>".format(progname)
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Main
|
2012-03-07 00:24:28 +06:00
|
|
|
|
#
|
2013-03-26 22:38:18 +06:00
|
|
|
|
def cli_main():
|
|
|
|
|
argv=unicode_argv()
|
2011-01-17 13:24:53 +06:00
|
|
|
|
progname = os.path.basename(argv[0])
|
2013-03-20 16:23:54 +06:00
|
|
|
|
print u"K4MobiDeDrm v{0}.\nCopyright © 2008-2013 The Dark Reverser et al.".format(__version__)
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
|
|
|
|
try:
|
2013-10-03 00:59:40 +06:00
|
|
|
|
opts, args = getopt.getopt(argv[1:], "k:p:s:a:")
|
2011-01-17 13:24:53 +06:00
|
|
|
|
except getopt.GetoptError, err:
|
2012-12-19 19:48:11 +06:00
|
|
|
|
print u"Error in options or arguments: {0}".format(err.args[0])
|
2011-01-17 13:24:53 +06:00
|
|
|
|
usage(progname)
|
|
|
|
|
sys.exit(2)
|
|
|
|
|
if len(args)<2:
|
|
|
|
|
usage(progname)
|
|
|
|
|
sys.exit(2)
|
2012-03-07 00:24:28 +06:00
|
|
|
|
|
2017-02-05 02:25:12 +06:00
|
|
|
|
outdir = args.pop()
|
2013-03-20 16:23:54 +06:00
|
|
|
|
kDatabaseFiles = []
|
2015-07-29 23:11:19 +06:00
|
|
|
|
androidFiles = []
|
2012-12-19 19:48:11 +06:00
|
|
|
|
serials = []
|
|
|
|
|
pids = []
|
|
|
|
|
|
2011-01-17 13:24:53 +06:00
|
|
|
|
for o, a in opts:
|
|
|
|
|
if o == "-k":
|
|
|
|
|
if a == None :
|
|
|
|
|
raise DrmException("Invalid parameter for -k")
|
2013-03-20 16:23:54 +06:00
|
|
|
|
kDatabaseFiles.append(a)
|
2011-01-17 13:24:53 +06:00
|
|
|
|
if o == "-p":
|
|
|
|
|
if a == None :
|
|
|
|
|
raise DrmException("Invalid parameter for -p")
|
|
|
|
|
pids = a.split(',')
|
|
|
|
|
if o == "-s":
|
|
|
|
|
if a == None :
|
|
|
|
|
raise DrmException("Invalid parameter for -s")
|
|
|
|
|
serials = a.split(',')
|
2013-10-03 00:59:40 +06:00
|
|
|
|
if o == '-a':
|
|
|
|
|
if a == None:
|
2015-08-02 16:09:35 +06:00
|
|
|
|
raise DrmException("Invalid parameter for -a")
|
|
|
|
|
androidFiles.append(a)
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
2012-12-19 19:48:11 +06:00
|
|
|
|
# try with built in Kindle Info files if not on Linux
|
|
|
|
|
k4 = not sys.platform.startswith('linux')
|
|
|
|
|
|
2017-02-05 02:25:12 +06:00
|
|
|
|
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
|
2011-01-17 13:24:53 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-12-19 19:48:11 +06:00
|
|
|
|
sys.stdout=SafeUnbuffered(sys.stdout)
|
|
|
|
|
sys.stderr=SafeUnbuffered(sys.stderr)
|
|
|
|
|
sys.exit(cli_main())
|