diff --git a/DeDRM_plugin/__init__.py b/DeDRM_plugin/__init__.py index ad2e38f..ad68ab4 100644 --- a/DeDRM_plugin/__init__.py +++ b/DeDRM_plugin/__init__.py @@ -959,30 +959,28 @@ class DeDRM(FileTypePlugin): traceback.print_exc() pass - newkeys = [] + newkeys = {} newnames = [] 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(): - newkeys.append(keyvalue) - newnames.append(keyname) + newkeys["key_{0:d}".format(i)] = keyvalue 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")) try: - book = k4mobidedrm.GetDecryptedBook(path_to_ebook,list(newkeys),[],[],[],self.starttime) + book = k4mobidedrm.GetDecryptedBook(path_to_ebook,newkeys.items(),[],[],[],self.starttime) decoded = True # 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")) - for i,keyvalue in enumerate(newkeys): - dedrmprefs.addnamedvaluetoprefs('kindlekeys',newnames[i],keyvalue) + i = 1 + 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() except Exception as e: + traceback.print_exc() pass if not decoded: #if you reached here then no luck raise and exception diff --git a/DeDRM_plugin/config.py b/DeDRM_plugin/config.py index b3d924c..193b8f6 100755 --- a/DeDRM_plugin/config.py +++ b/DeDRM_plugin/config.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' # Python 3, September 2020 # 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, QGroupBox, QPushButton, QListWidget, QListWidgetItem, QCheckBox, @@ -1237,7 +1237,7 @@ class AddKindleDialog(QDialog): from wineutils import WineGetKeys 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] except: @@ -1255,7 +1255,7 @@ class AddKindleDialog(QDialog): key_group = QHBoxLayout() data_group_box_layout.addLayout(key_group) 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("
Enter an identifying name for the current default Kindle for Mac/PC key.") key_group.addWidget(self.key_ledit)