Fix Kindle for real

This commit is contained in:
NoDRM 2022-03-20 14:32:22 +01:00
parent 726d72217e
commit 76ce6d9c5c
2 changed files with 12 additions and 14 deletions

View file

@ -959,30 +959,28 @@ class DeDRM(FileTypePlugin):
traceback.print_exc() traceback.print_exc()
pass pass
newkeys = [] newkeys = {}
newnames = [] newnames = []
for i,keyvalue in enumerate(defaultkeys): for i,keyvalue in enumerate(defaultkeys):
try:
keyname = "default_key_" + defaultnames[i]
except:
keyname = "default_key_{0:d}".format(i+1)
if keyvalue not in dedrmprefs['kindlekeys'].values(): if keyvalue not in dedrmprefs['kindlekeys'].values():
newkeys.append(keyvalue) newkeys["key_{0:d}".format(i)] = keyvalue
newnames.append(keyname)
if len(newkeys) > 0: if len(newkeys) > 0:
print("{0} v{1}: Found {2} new {3}".format(PLUGIN_NAME, PLUGIN_VERSION, len(newkeys), "key" if len(newkeys)==1 else "keys")) print("{0} v{1}: Found {2} new {3}".format(PLUGIN_NAME, PLUGIN_VERSION, len(newkeys), "key" if len(newkeys)==1 else "keys"))
try: try:
book = k4mobidedrm.GetDecryptedBook(path_to_ebook,list(newkeys),[],[],[],self.starttime) book = k4mobidedrm.GetDecryptedBook(path_to_ebook,newkeys.items(),[],[],[],self.starttime)
decoded = True decoded = True
# store the new successful keys in the defaults # store the new successful keys in the defaults
print("{0} v{1}: Saving {2} new {3}".format(PLUGIN_NAME, PLUGIN_VERSION, len(newkeys), "key" if len(newkeys)==1 else "keys")) print("{0} v{1}: Saving {2} new {3}".format(PLUGIN_NAME, PLUGIN_VERSION, len(newkeys), "key" if len(newkeys)==1 else "keys"))
for i,keyvalue in enumerate(newkeys): i = 1
dedrmprefs.addnamedvaluetoprefs('kindlekeys',newnames[i],keyvalue) for keyvalue in newkeys.values():
while "kindle_key_{0:d}_{1:d}".format(int(time.time()), i) in dedrmprefs['kindlekeys']:
i = i + 1
dedrmprefs.addnamedvaluetoprefs('kindlekeys',"kindle_key_{0:d}_{1:d}".format(int(time.time()), i),keyvalue)
dedrmprefs.writeprefs() dedrmprefs.writeprefs()
except Exception as e: except Exception as e:
traceback.print_exc()
pass pass
if not decoded: if not decoded:
#if you reached here then no luck raise and exception #if you reached here then no luck raise and exception

View file

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
# Python 3, September 2020 # Python 3, September 2020
# Standard Python modules. # Standard Python modules.
import sys, os, traceback, json, codecs, base64 import sys, os, traceback, json, codecs, base64, time
from PyQt5.Qt import (Qt, QWidget, QHBoxLayout, QVBoxLayout, QLabel, QLineEdit, from PyQt5.Qt import (Qt, QWidget, QHBoxLayout, QVBoxLayout, QLabel, QLineEdit,
QGroupBox, QPushButton, QListWidget, QListWidgetItem, QCheckBox, QGroupBox, QPushButton, QListWidget, QListWidgetItem, QCheckBox,
@ -1237,7 +1237,7 @@ class AddKindleDialog(QDialog):
from wineutils import WineGetKeys from wineutils import WineGetKeys
scriptpath = os.path.join(parent.parent.alfdir,"kindlekey.py") scriptpath = os.path.join(parent.parent.alfdir,"kindlekey.py")
defaultkeys = WineGetKeys(scriptpath, ".k4i",parent.getwineprefix()) defaultkeys, defaultnames = WineGetKeys(scriptpath, ".k4i",parent.getwineprefix())
self.default_key = defaultkeys[0] self.default_key = defaultkeys[0]
except: except:
@ -1255,7 +1255,7 @@ class AddKindleDialog(QDialog):
key_group = QHBoxLayout() key_group = QHBoxLayout()
data_group_box_layout.addLayout(key_group) data_group_box_layout.addLayout(key_group)
key_group.addWidget(QLabel("Unique Key Name:", self)) key_group.addWidget(QLabel("Unique Key Name:", self))
self.key_ledit = QLineEdit("default_key", self) self.key_ledit = QLineEdit("default_key_" + str(int(time.time())), self)
self.key_ledit.setToolTip("<p>Enter an identifying name for the current default Kindle for Mac/PC key.") self.key_ledit.setToolTip("<p>Enter an identifying name for the current default Kindle for Mac/PC key.")
key_group.addWidget(self.key_ledit) key_group.addWidget(self.key_ledit)