Starting on Version 7.0 using the work done by others. Completely untested. I will be testing things, but I thought I'd get this base version up for others to give pull requests.
THIS IS ON THE MASTER BRANCH. The Master branch will be Python 3.0 from now on. While Python 2.7 support will not be deliberately broken, all efforts should now focus on Python 3.0 compatibility.
I can see a lot of work has been done. There's more to do. I've bumped the version number of everything I came across to the next major number for Python 3.0 compatibility indication.
Thanks everyone. I hope to update here at least once a week until we have a stable 7.0 release for calibre 5.0
printu"{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
except:
printu"{0} v{1}: Exception saving a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Exception saving a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
traceback.print_exc()
# Return the modified PersistentTemporary file to calibre.
returnof.name
printu"{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
exceptException,e:
print(u"{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
exceptExceptionase:
pass
printu"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
raiseDeDRMError(u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
# import the Adobe Adept ePub handler
importcalibre_plugins.dedrm.ineptepubasineptepub
ifineptepub.adeptBook(inf.name):
printu"{0} v{1}: {2} is a secure Adobe Adept ePub".format(PLUGIN_NAME,PLUGIN_VERSION,os.path.basename(path_to_ebook))
print("{0} v{1}: {2} is a secure Adobe Adept ePub".format(PLUGIN_NAME,PLUGIN_VERSION,os.path.basename(path_to_ebook)))
# Attempt to decrypt epub with each encryption key (generated or provided).
printu"{0} v{1}: Exception when decrypting after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Exception when decrypting after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
traceback.print_exc()
result=1
try:
of.close()
except:
printu"{0} v{1}: Exception closing temporary file after {2:.1f} seconds. Ignored.".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Exception closing temporary file after {2:.1f} seconds. Ignored.".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
ifresult==0:
# Decryption was successful.
# Return the modified PersistentTemporary file to calibre.
printu"{0} v{1}: Decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname,time.time()-self.starttime)
print("{0} v{1}: Decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname,time.time()-self.starttime))
returnof.name
printu"{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname,time.time()-self.starttime)
print("{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname,time.time()-self.starttime))
# perhaps we need to get a new default ADE key
printu"{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
# get the default Adobe keys
defaultkeys=[]
@ -356,7 +358,7 @@ class DeDRM(FileTypePlugin):
self.default_key=defaultkeys[0]
except:
printu"{0} v{1}: Exception when getting default Adobe Key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Exception when getting default Adobe Key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
traceback.print_exc()
self.default_key=u""
@ -368,14 +370,14 @@ class DeDRM(FileTypePlugin):
iflen(newkeys)>0:
try:
fori,userkeyinenumerate(newkeys):
printu"{0} v{1}: Trying a new default key".format(PLUGIN_NAME,PLUGIN_VERSION)
print("{0} v{1}: Trying a new default key".format(PLUGIN_NAME,PLUGIN_VERSION))
of=self.temporary_file(u".epub")
# Give the user key, ebook and TemporaryPersistent file to the decryption function.
printu"{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
except:
printu"{0} v{1}: Exception when saving a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Exception when saving a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
traceback.print_exc()
printu"{0} v{1}: Decrypted with new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Decrypted with new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
# Return the modified PersistentTemporary file to calibre.
returnof.name
printu"{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
exceptException,e:
printu"{0} v{1}: Unexpected Exception trying a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print(u"{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
exceptExceptionase:
print(u"{0} v{1}: Unexpected Exception trying a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
traceback.print_exc()
pass
# Something went wrong with decryption.
printu"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
raiseDeDRMError(u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
# Not a Barnes & Noble nor an Adobe Adept
# Import the fixed epub.
printu"{0} v{1}: “{2}” is neither an Adobe Adept nor a Barnes & Noble encrypted ePub".format(PLUGIN_NAME,PLUGIN_VERSION,os.path.basename(path_to_ebook))
print("{0} v{1}: “{2}” is neither an Adobe Adept nor a Barnes & Noble encrypted ePub".format(PLUGIN_NAME,PLUGIN_VERSION,os.path.basename(path_to_ebook)))
raiseDeDRMError(u"{0} v{1}: Couldn't decrypt after {2:.1f} seconds. DRM free perhaps?".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
defPDFDecrypt(self,path_to_ebook):
@ -417,17 +419,17 @@ class DeDRM(FileTypePlugin):
dedrmprefs=prefs.DeDRM_Prefs()
# Attempt to decrypt epub with each encryption key (generated or provided).
printu"{0} v{1}: {2} is a PDF ebook".format(PLUGIN_NAME,PLUGIN_VERSION,os.path.basename(path_to_ebook))
print("{0} v{1}: {2} is a PDF ebook".format(PLUGIN_NAME,PLUGIN_VERSION,os.path.basename(path_to_ebook)))
printu"{0} v{1}: Exception when decrypting after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Exception when decrypting after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
traceback.print_exc()
result=1
@ -438,10 +440,10 @@ class DeDRM(FileTypePlugin):
# Return the modified PersistentTemporary file to calibre.
returnof.name
printu"{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname,time.time()-self.starttime)
print("{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname,time.time()-self.starttime))
# perhaps we need to get a new default ADE key
printu"{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
# get the default Adobe keys
defaultkeys=[]
@ -459,7 +461,7 @@ class DeDRM(FileTypePlugin):
self.default_key=defaultkeys[0]
except:
printu"{0} v{1}: Exception when getting default Adobe Key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Exception when getting default Adobe Key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
traceback.print_exc()
self.default_key=u""
@ -471,14 +473,14 @@ class DeDRM(FileTypePlugin):
iflen(newkeys)>0:
try:
fori,userkeyinenumerate(newkeys):
printu"{0} v{1}: Trying a new default key".format(PLUGIN_NAME,PLUGIN_VERSION)
print("{0} v{1}: Trying a new default key".format(PLUGIN_NAME,PLUGIN_VERSION))
of=self.temporary_file(u".pdf")
# Give the user key, ebook and TemporaryPersistent file to the decryption function.
printu"{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
except:
printu"{0} v{1}: Exception when saving a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Exception when saving a new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
traceback.print_exc()
# Return the modified PersistentTemporary file to calibre.
returnof.name
printu"{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
exceptException,e:
print(u"{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
exceptExceptionase:
pass
# Something went wrong with decryption.
printu"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
raiseDeDRMError(u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
#if you reached here then no luck raise and exception
printu"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
raiseDeDRMError(u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
of=self.temporary_file(book.getBookExtension())
@ -590,7 +592,7 @@ class DeDRM(FileTypePlugin):
# Attempt to decrypt epub with each encryption key (generated or provided).
# Give the userkey, ebook and TemporaryPersistent file to the decryption function.
@ -601,12 +603,12 @@ class DeDRM(FileTypePlugin):
# Decryption was successful return the modified PersistentTemporary
# file to Calibre's import process.
ifresult==0:
printu"{0} v{1}: Successfully decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname_masked,time.time()-self.starttime)
print("{0} v{1}: Successfully decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname_masked,time.time()-self.starttime))
returnof.name
printu"{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname_masked,time.time()-self.starttime)
print("{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME,PLUGIN_VERSION,keyname_masked,time.time()-self.starttime))
printu"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime)
print("{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
raiseDeDRMError(u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME,PLUGIN_VERSION,time.time()-self.starttime))
@ -616,7 +618,7 @@ class DeDRM(FileTypePlugin):
sys.stdout=SafeUnbuffered(sys.stdout)
sys.stderr=SafeUnbuffered(sys.stderr)
printu"{0} v{1}: Trying to decrypt {2}".format(PLUGIN_NAME,PLUGIN_VERSION,os.path.basename(path_to_ebook))
print("{0} v{1}: Trying to decrypt {2}".format(PLUGIN_NAME,PLUGIN_VERSION,os.path.basename(path_to_ebook)))
@ -6,6 +6,8 @@ from __future__ import print_function
__license__='GPL v3'
# Added Python 3 compatibility, September 2020
# Standard Python modules.
importos,traceback,json
@ -22,7 +24,7 @@ try:
fromPyQt5importQtasQtGui
exceptImportError:
fromPyQt4importQtGui
fromzipfileimportZipFile
# calibre modules and constants.
@ -123,7 +125,7 @@ class ConfigWidget(QWidget):
defkindle_serials(self):
d=ManageKeysDialog(self,u"EInk Kindle Serial Number",self.tempdedrmprefs['serials'],AddSerialDialog)
d.exec_()
defkindle_android(self):
d=ManageKeysDialog(self,u"Kindle for Android Key",self.tempdedrmprefs['androidkeys'],AddAndroidDialog,'k4a')
d.exec_()
@ -289,7 +291,7 @@ class ManageKeysDialog(QDialog):
defgetwineprefix(self):
ifself.wineprefixisnotNone:
returnunicode(self.wp_lineedit.text()).strip()
returnself.wp_lineedit.text().strip()
returnu""
defpopulate_list(self):
@ -338,7 +340,7 @@ class ManageKeysDialog(QDialog):
ifd.result()!=d.Accepted:
# rename cancelled or moot.
return
keyname=unicode(self.listy.currentItem().text())
keyname=self.listy.currentItem().text()
ifnotquestion_dialog(self,"{0}{1}: Confirm Rename".format(PLUGIN_NAME,PLUGIN_VERSION),u"Do you really want to rename the {2} named <strong>{0}</strong> to <strong>{1}</strong>?".format(keyname,d.key_name,self.key_type_name),show_copy_button=False,default_yes=False):
@ -350,7 +352,7 @@ class ManageKeysDialog(QDialog):
defdelete_key(self):
ifnotself.listy.currentItem():
return
keyname=unicode(self.listy.currentItem().text())
keyname=self.listy.currentItem().text()
ifnotquestion_dialog(self,"{0}{1}: Confirm Delete".format(PLUGIN_NAME,PLUGIN_VERSION),u"Do you really want to delete the {1} <strong>{0}</strong>?".format(keyname,self.key_type_name),show_copy_button=False,default_yes=False):
return
iftype(self.plugin_keys)==dict:
@ -388,7 +390,7 @@ class ManageKeysDialog(QDialog):
withopen(fpath,'rb')askeyfile:
new_key_value=keyfile.read()
ifself.binary_file:
new_key_value=new_key_value.encode('hex')
new_key_value=new_key_value.hex()
elifself.json_file:
new_key_value=json.loads(new_key_value)
elifself.android_file:
@ -412,7 +414,7 @@ class ManageKeysDialog(QDialog):
else:
counter+=1
self.plugin_keys[new_key_name]=new_key_value
msg=u""
ifcounter+skipped>1:
ifcounter>0:
@ -434,7 +436,7 @@ class ManageKeysDialog(QDialog):
printu"{0} v{1}: {2:d} Barnes and Noble {3} imported from old Ignoble plugin configuration string".format(PLUGIN_NAME,PLUGIN_VERSION,addedkeycount,u"key"ifaddedkeycount==1elseu"keys")
print(u"{0} v{1}: {2:d} Barnes and Noble {3} imported from old Ignoble plugin configuration string".format(PLUGIN_NAME,PLUGIN_VERSION,addedkeycount,u"key"ifaddedkeycount==1elseu"keys"))
printu"{0} v{1}: {2:d}{3} and {4:d}{5} imported from old Kindle plugin configuration string.".format(PLUGIN_NAME,PLUGIN_VERSION,addedpidcount,u"PID"ifaddedpidcount==1elseu"PIDs",addedserialcount,u"serial number"ifaddedserialcount==1elseu"serial numbers")
print(u"{0} v{1}: {2:d}{3} and {4:d}{5} imported from old Kindle plugin configuration string.".format(PLUGIN_NAME,PLUGIN_VERSION,addedpidcount,u"PID"ifaddedpidcount==1elseu"PIDs",addedserialcount,u"serial number"ifaddedserialcount==1elseu"serial numbers"))
@ -306,10 +307,10 @@ class InterfacePluginAction(InterfaceAction):
sd=ResultsSummaryDialog(self.gui,caption,msg,log)
sd.exec_()
return
defask_about_inserting_epubs(self):
'''
Buildquestiondialogwithdetailsaboutkobobooks
Buildquestiondialogwithdetailsaboutkobobooks
thatcouldn't be added to calibre as new books.
'''
''' Terisa: Improve the message
@ -327,13 +328,13 @@ class InterfacePluginAction(InterfaceAction):
msg=_('<p><b>{0}</b> -- not added because of {1} in your library.<br /><br />').format(self.duplicate_book_list[0][0].title,self.duplicate_book_list[0][2])
msg+=_('Would you like to try and add the EPUB format to an available calibre duplicate?<br /><br />')
msg+=_('NOTE: no pre-existing EPUB will be overwritten.')
@ -165,7 +165,7 @@ class ManageKeysDialog(QDialog):
defdelete_key(self):
ifnotself.listy.currentItem():
return
keyname=unicode(self.listy.currentItem().text())
keyname=self.listy.currentItem().text()
ifnotquestion_dialog(self,"{0}{1}: Confirm Delete".format(PLUGIN_NAME,PLUGIN_VERSION),u"Do you really want to delete the {1} <strong>{0}</strong>?".format(keyname,self.key_type_name),show_copy_button=False,default_yes=False):
return
self.plugin_keys.remove(keyname)
@ -202,11 +202,11 @@ class AddSerialDialog(QDialog):