Implement decrypting of all books
This commit is contained in:
parent
ceacdbbb1b
commit
6f0c36b67a
|
@ -674,7 +674,7 @@ def decrypt_book(book, lib):
|
||||||
print u"DRM-free book, conversion is not needed"
|
print u"DRM-free book, conversion is not needed"
|
||||||
shutil.copyfile(book.filename, outname)
|
shutil.copyfile(book.filename, outname)
|
||||||
print u"Book saved as {0}".format(os.path.join(os.getcwd(), outname))
|
print u"Book saved as {0}".format(os.path.join(os.getcwd(), outname))
|
||||||
exit(0)
|
return 0
|
||||||
result = 1
|
result = 1
|
||||||
for userkey in lib.userkeys:
|
for userkey in lib.userkeys:
|
||||||
print u"Trying key: {0}".format(userkey.encode('hex_codec'))
|
print u"Trying key: {0}".format(userkey.encode('hex_codec'))
|
||||||
|
@ -718,19 +718,23 @@ def cli_main():
|
||||||
print u"{0}: {1}".format(i + 1, book.title)
|
print u"{0}: {1}".format(i + 1, book.title)
|
||||||
print u"Or 'all'"
|
print u"Or 'all'"
|
||||||
|
|
||||||
num_string = raw_input(u"Convert book number... ")
|
choice = raw_input(u"Convert book number... ")
|
||||||
|
if choice == u'all':
|
||||||
|
books = list(lib.books)
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
num = int(num_string)
|
num = int(choice)
|
||||||
book = lib.books[num - 1]
|
books = [lib.books[num - 1]]
|
||||||
except (ValueError, IndexError):
|
except (ValueError, IndexError):
|
||||||
print u"Invalid choice. Exiting..."
|
print u"Invalid choice. Exiting..."
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
result = decrypt_book(book, lib)
|
results = [decrypt_book(book, lib) for book in books]
|
||||||
lib.close()
|
lib.close()
|
||||||
if result != 0:
|
overall_result = all(result != 0 for result in results)
|
||||||
|
if overall_result != 0:
|
||||||
print u"Could not decrypt book with any of the keys found."
|
print u"Could not decrypt book with any of the keys found."
|
||||||
return result
|
return overall_result
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue