def _ok_clicked(self): ''' Build an index of the selected titles ''' if len(self.books_table.selectedItems()): self.accept() else: msg = 'You must make a selection!' showErrorDlg(msg, self)
def launchObok(self): ''' Main processing/distribution method ''' self.count = 0 self.books_to_add = [] self.formats_to_add = [] self.add_books_cancelled = False self.decryption_errors = [] self.userkeys = [] self.duplicate_book_list = [] self.no_home_for_book = [] self.ids_of_new_books = [] self.successful_format_adds =[] self.add_formats_cancelled = False self.tdir = PersistentTemporaryDirectory('_obok', prefix='') self.db = self.gui.current_db.new_api self.current_idx = self.gui.library_view.currentIndex() print ('Running {}'.format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) # # search for connected device in case serials are saved tmpserials = cfg['kobo_serials'] device_path = None try: device = self.parent().device_manager.connected_device if (device): device_path = device._main_prefix debug_print("get_device_settings - device_path=", device_path) else: debug_print("didn't find device") except: debug_print("Exception getting device path. Probably not an E-Ink Kobo device") # Get the Kobo Library object (obok v3.01) self.library = KoboLibrary(tmpserials, device_path, cfg['kobo_directory']) debug_print ("got kobodir %s" % self.library.kobodir) if (self.library.kobodir == ''): # linux and no device connected, but could be extended # to the case where on Windows/Mac the prog is not installed msg = _('<p>Could not find Kobo Library\n<p>Windows/Mac: do you have Kobo Desktop installed?\n<p>Windows/Mac/Linux: In case you have an Kobo eInk device, connect the device.') showErrorDlg(msg, None) return # Get a list of Kobo titles books = self.build_book_list() if len(books) < 1: msg = _('<p>No books found in Kobo Library\nAre you sure it\'s installed\configured\synchronized?') showErrorDlg(msg, None) return # Check to see if a key can be retrieved using the legacy obok method. legacy_key = legacy_obok().get_legacy_cookie_id if legacy_key is not None: print (_('Legacy key found: '), legacy_key.encode('hex_codec')) self.userkeys.append(legacy_key) # Add userkeys found through the normal obok method to the list to try. try: candidate_keys = self.library.userkeys except: print (_('Trouble retrieving keys with newer obok method.')) traceback.print_exc() else: if len(candidate_keys): self.userkeys.extend(candidate_keys) print (_('Found {0} possible keys to try.').format(len(self.userkeys))) if not len(self.userkeys): msg = _('<p>No userkeys found to decrypt books with. No point in proceeding.') showErrorDlg(msg, None) return # Launch the Dialog so the user can select titles. dlg = SelectionDialog(self.gui, self, books) if dlg.exec_(): books_to_import = dlg.getBooks() self.count = len(books_to_import) debug_print("InterfacePluginAction::launchObok - number of books to decrypt: %d" % self.count) # Feed the titles, the callback function (self.get_decrypted_kobo_books) # and the Kobo library object to the ProgressDialog dispatcher. d = DecryptAddProgressDialog(self.gui, books_to_import, self.get_decrypted_kobo_books, self.library, 'kobo', status_msg_type='Kobo books', action_type=('Decrypting', 'Decryption')) # Canceled the decryption process; clean up and exit. if d.wasCanceled(): print (_('{} - Decryption canceled by user.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.library.close() remove_dir(self.tdir) return else: # Canceled the selection process; clean up and exit. self.library.close() remove_dir(self.tdir) return # Close Kobo Library object self.library.close() # If we have decrypted books to work with, feed the list of decrypted books details # and the callback function (self.add_new_books) to the ProgressDialog dispatcher. if len(self.books_to_add): d = DecryptAddProgressDialog(self.gui, self.books_to_add, self.add_new_books, self.db, 'calibre', status_msg_type='new calibre books', action_type=('Adding','Addition')) # Canceled the "add new books to calibre" process; # show the results of what got added before cancellation. if d.wasCanceled(): print (_('{} - "Add books" canceled by user.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.add_books_cancelled = True print (_('{} - wrapping up results.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.wrap_up_results() remove_dir(self.tdir) return # If books couldn't be added because of duplicate entries in calibre, ask # if we should try to add the decrypted epubs to existing calibre library entries. if len(self.duplicate_book_list): if cfg['finding_homes_for_formats'] == 'Always': self.process_epub_formats() elif cfg['finding_homes_for_formats'] == 'Never': self.no_home_for_book.extend([entry[0] for entry in self.duplicate_book_list]) else: if self.ask_about_inserting_epubs(): # Find homes for the epub decrypted formats in existing calibre library entries. self.process_epub_formats() else: print (_('{} - User opted not to try to insert EPUB formats').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.no_home_for_book.extend([entry[0] for entry in self.duplicate_book_list]) print (_('{} - wrapping up results.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.wrap_up_results() remove_dir(self.tdir) return
def launchObok(self): ''' Main processing/distribution method ''' self.count = 0 self.books_to_add = [] self.formats_to_add = [] self.add_books_cancelled = False self.decryption_errors = [] self.userkeys = [] self.duplicate_book_list = [] self.no_home_for_book = [] self.ids_of_new_books = [] self.successful_format_adds =[] self.add_formats_cancelled = False self.tdir = PersistentTemporaryDirectory('_obok', prefix='') self.db = self.gui.current_db.new_api self.current_idx = self.gui.library_view.currentIndex() print ('Running {}'.format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) # # search for connected device in case serials are saved tmpserials = cfg['kobo_serials'] device = self.parent().device_manager.connected_device device_path = None if (device): device_path = device._main_prefix debug_print("get_device_settings - device_path=", device_path) # get serial from device_path/.adobe-digital-editions/device.xml if can_parse_xml: devicexml = os.path.join(device_path, '.adobe-digital-editions', 'device.xml') debug_print("trying to load %s" % devicexml) if (os.path.exists(devicexml)): debug_print("trying to parse %s" % devicexml) xmltree = ET.parse(devicexml) for node in xmltree.iter(): if "deviceSerial" in node.tag: serial = node.text debug_print ("found serial %s" % serial) tmpserials.append(serial) break else: debug_print("didn't find device") # Get the Kobo Library object (obok v3.01) self.library = KoboLibrary(tmpserials, device_path) debug_print ("got kobodir %s" % self.library.kobodir) if (self.library.kobodir == ''): # linux and no device connected, but could be extended # to the case where on Windows/Mac the prog is not installed msg = _('<p>Could not find Kobo Library\n<p>Windows/Mac: do you have Kobo Desktop installed?\n<p>Windows/Mac/Linux: In case you have an Kobo eInk device, connect the device.') showErrorDlg(msg, None) return # Get a list of Kobo titles books = self.build_book_list() if len(books) < 1: msg = _('<p>No books found in Kobo Library\nAre you sure it\'s installed\configured\synchronized?') showErrorDlg(msg, None) return # Check to see if a key can be retrieved using the legacy obok method. legacy_key = legacy_obok().get_legacy_cookie_id if legacy_key is not None: print (_('Legacy key found: '), legacy_key.encode('hex_codec')) self.userkeys.append(legacy_key) # Add userkeys found through the normal obok method to the list to try. try: candidate_keys = self.library.userkeys except: print (_('Trouble retrieving keys with newer obok method.')) traceback.print_exc() else: if len(candidate_keys): self.userkeys.extend(candidate_keys) print (_('Found {0} possible keys to try.').format(len(self.userkeys))) if not len(self.userkeys): msg = _('<p>No userkeys found to decrypt books with. No point in proceeding.') showErrorDlg(msg, None) return # Launch the Dialog so the user can select titles. dlg = SelectionDialog(self.gui, self, books) if dlg.exec_(): books_to_import = dlg.getBooks() self.count = len(books_to_import) debug_print("InterfacePluginAction::launchObok - number of books to decrypt: %d" % self.count) # Feed the titles, the callback function (self.get_decrypted_kobo_books) # and the Kobo library object to the ProgressDialog dispatcher. d = DecryptAddProgressDialog(self.gui, books_to_import, self.get_decrypted_kobo_books, self.library, 'kobo', status_msg_type='Kobo books', action_type=('Decrypting', 'Decryption')) # Canceled the decryption process; clean up and exit. if d.wasCanceled(): print (_('{} - Decryption canceled by user.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.library.close() remove_dir(self.tdir) return else: # Canceled the selection process; clean up and exit. self.library.close() remove_dir(self.tdir) return # Close Kobo Library object self.library.close() # If we have decrypted books to work with, feed the list of decrypted books details # and the callback function (self.add_new_books) to the ProgressDialog dispatcher. if len(self.books_to_add): d = DecryptAddProgressDialog(self.gui, self.books_to_add, self.add_new_books, self.db, 'calibre', status_msg_type='new calibre books', action_type=('Adding','Addition')) # Canceled the "add new books to calibre" process; # show the results of what got added before cancellation. if d.wasCanceled(): print (_('{} - "Add books" canceled by user.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.add_books_cancelled = True print (_('{} - wrapping up results.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.wrap_up_results() remove_dir(self.tdir) return # If books couldn't be added because of duplicate entries in calibre, ask # if we should try to add the decrypted epubs to existing calibre library entries. if len(self.duplicate_book_list): if cfg['finding_homes_for_formats'] == 'Always': self.process_epub_formats() elif cfg['finding_homes_for_formats'] == 'Never': self.no_home_for_book.extend([entry[0] for entry in self.duplicate_book_list]) else: if self.ask_about_inserting_epubs(): # Find homes for the epub decrypted formats in existing calibre library entries. self.process_epub_formats() else: print (_('{} - User opted not to try to insert EPUB formats').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.no_home_for_book.extend([entry[0] for entry in self.duplicate_book_list]) print (_('{} - wrapping up results.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.wrap_up_results() remove_dir(self.tdir) return
def launchObok(self): ''' Main processing/distribution method ''' self.count = 0 self.books_to_add = [] self.formats_to_add = [] self.add_books_cancelled = False self.decryption_errors = [] self.userkeys = [] self.duplicate_book_list = [] self.no_home_for_book = [] self.ids_of_new_books = [] self.successful_format_adds =[] self.add_formats_cancelled = False self.tdir = PersistentTemporaryDirectory('_obok', prefix='') self.db = self.gui.current_db.new_api self.current_idx = self.gui.library_view.currentIndex() print ('Running {}'.format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) # Get the Kobo Library object (obok v3.01) self.library = KoboLibrary() # Get a list of Kobo titles books = self.build_book_list() if len(books) < 1: msg = _('<p>No books found in Kobo Library\nAre you sure it\'s installed\configured\synchronized?') showErrorDlg(msg, None) return # Check to see if a key can be retrieved using the legacy obok method. legacy_key = legacy_obok().get_legacy_cookie_id if legacy_key is not None: print (_('Legacy key found: '), legacy_key.encode('hex_codec')) self.userkeys.append(legacy_key) # Add userkeys found through the normal obok method to the list to try. try: candidate_keys = self.library.userkeys except: print (_('Trouble retrieving keys with newer obok method.')) traceback.print_exc() else: if len(candidate_keys): self.userkeys.extend(candidate_keys) print (_('Found {0} possible keys to try.').format(len(self.userkeys))) if not len(self.userkeys): msg = _('<p>No userkeys found to decrypt books with. No point in proceeding.') showErrorDlg(msg, None) return # Launch the Dialog so the user can select titles. dlg = SelectionDialog(self.gui, self, books) if dlg.exec_(): books_to_import = dlg.getBooks() self.count = len(books_to_import) debug_print("InterfacePluginAction::launchObok - number of books to decrypt: %d" % self.count) # Feed the titles, the callback function (self.get_decrypted_kobo_books) # and the Kobo library object to the ProgressDialog dispatcher. d = DecryptAddProgressDialog(self.gui, books_to_import, self.get_decrypted_kobo_books, self.library, 'kobo', status_msg_type='Kobo books', action_type=('Decrypting', 'Decryption')) # Canceled the decryption process; clean up and exit. if d.wasCanceled(): print (_('{} - Decryption canceled by user.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.library.close() remove_dir(self.tdir) return else: # Canceled the selection process; clean up and exit. self.library.close() remove_dir(self.tdir) return # Close Kobo Library object self.library.close() # If we have decrypted books to work with, feed the list of decrypted books details # and the callback function (self.add_new_books) to the ProgressDialog dispatcher. if len(self.books_to_add): d = DecryptAddProgressDialog(self.gui, self.books_to_add, self.add_new_books, self.db, 'calibre', status_msg_type='new calibre books', action_type=('Adding','Addition')) # Canceled the "add new books to calibre" process; # show the results of what got added before cancellation. if d.wasCanceled(): print (_('{} - "Add books" canceled by user.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.add_books_cancelled = True print (_('{} - wrapping up results.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.wrap_up_results() remove_dir(self.tdir) return # If books couldn't be added because of duplicate entries in calibre, ask # if we should try to add the decrypted epubs to existing calibre library entries. if len(self.duplicate_book_list): if cfg['finding_homes_for_formats'] == 'Always': self.process_epub_formats() elif cfg['finding_homes_for_formats'] == 'Never': self.no_home_for_book.extend([entry[0] for entry in self.duplicate_book_list]) else: if self.ask_about_inserting_epubs(): # Find homes for the epub decrypted formats in existing calibre library entries. self.process_epub_formats() else: print (_('{} - User opted not to try to insert EPUB formats').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.no_home_for_book.extend([entry[0] for entry in self.duplicate_book_list]) print (_('{} - wrapping up results.').format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) self.wrap_up_results() remove_dir(self.tdir) return