noDRM / DeDRM_tools

DeDRM tools for ebooks
6.56k stars 287 forks source link

Failed to deDRM a KFX book from Kindle #519

Closed vhosouza closed 3 months ago

vhosouza commented 3 months ago

Question / bug report

I received the Kindle files from a friend (both xxx.kfx and the xxx.sdr). I imported it to Calibre with both plugins installed KFX Input and DeDRM_tools. However, when I try to convert it is not being able to deDRM the file. What am I doing wrong? From the log it seems that it doesn't find the voucher, but there is a voucher file inside the xxx.sdr directory.

Thanks a lot for the support.

Which version of Calibre are you running?

6.29

Which version of the DeDRM plugin are you running?

v10.0.9

If applicable, which version of the Kindle software are you running?

No response

Log output

Worker Launch took: 0.02 seconds
Job: 14 Convert book 1 of 1 (The Comeback Quotient) finished
Convert book 1 of 1 (The Comeback Quotient)
    DeDRM v10.0.9: Trying to decrypt m_x3c26n.kfx-zip
    Decrypting KFX-ZIP ebook: m_x3c26n
    Found 0 keys to try after 0.2 seconds
    Decrypting KFX DRM voucher: voucher
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Traceback (most recent call last):
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/kfxdedrm.py", line 105, in decrypt_voucher
        voucher.decryptvoucher()
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/ion.py", line 1368, in decryptvoucher
        raise ex
    UnboundLocalError: local variable 'ex' referenced before assignment
    DeDRM v10.0.9: Failed to decrypt with error: Failed to decrypt KFX DRM voucher with any key
    DeDRM v10.0.9: Looking for new default Kindle Key after 0.2 seconds
    No k4Mac kindle-info/rainier/kinf2011 files have been found.
    DeDRM v10.0.9: Ultimately failed to decrypt after 0.3 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
    Running file type plugin DeDRM failed with traceback:
    Traceback (most recent call last):
      File "calibre_plugins.dedrm.__init__", line 931, in KindleMobiDecrypt
        book = k4mobidedrm.GetDecryptedBook(path_to_ebook,kindleDatabases,androidFiles,serials,pids,self.starttime)
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/k4mobidedrm.py", line 203, in GetDecryptedBook
        mb.processBook(totalpids)
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/kfxdedrm.py", line 67, in processBook
        self.decrypt_voucher(totalpids)
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/kfxdedrm.py", line 111, in decrypt_voucher
        raise Exception("Failed to decrypt KFX DRM voucher with any key")
    Exception: Failed to decrypt KFX DRM voucher with any key

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "calibre/customize/ui.py", line 187, in _run_filetype_plugins
      File "calibre_plugins.dedrm.__init__", line 1030, in run
        decrypted_ebook = self.KindleMobiDecrypt(path_to_ebook)
      File "calibre_plugins.dedrm.__init__", line 981, in KindleMobiDecrypt
        raise DeDRMError("{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
    calibre_plugins.dedrm.DeDRMError: DeDRM v10.0.9: Ultimately failed to decrypt after 0.3 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
    Conversion options changed from defaults:
      read_metadata_from_opf: '/var/folders/3k/tr22qcqx0jg9blc862xz725c0000gn/C/calibre_6.29.0_tmp_gdxkt2wn/3az23r8j.opf'
      verbose: 2
      cover: '/var/folders/3k/tr22qcqx0jg9blc862xz725c0000gn/C/calibre_6.29.0_tmp_gdxkt2wn/dam_rta0.jpeg'
      output_profile: 'kindle_pw3'
    Resolved conversion options
    calibre version: 6.29.0
    {'allow_conversion_with_errors': False,
     'asciiize': False,
     'author_sort': None,
     'authors': None,
     'base_font_size': 0.0,
     'book_producer': None,
     'change_justification': 'original',
     'chapter': "//*[((name()='h1' or name()='h2') and re:test(., "
                "'\\s*((chapter|book|section|part)\\s+)|((prolog|prologue|epilogue)(\\s+|$))', "
                "'i')) or @class = 'chapter']",
     'chapter_mark': 'pagebreak',
     'comments': None,
     'cover': '/var/folders/3k/tr22qcqx0jg9blc862xz725c0000gn/C/calibre_6.29.0_tmp_gdxkt2wn/dam_rta0.jpeg',
     'debug_pipeline': None,
     'dehyphenate': True,
     'delete_blank_paragraphs': True,
     'disable_font_rescaling': False,
     'dont_split_on_page_breaks': False,
     'duplicate_links_in_toc': False,
     'embed_all_fonts': False,
     'embed_font_family': None,
     'enable_heuristics': False,
     'epub_flatten': False,
     'epub_inline_toc': False,
     'epub_max_image_size': 'none',
     'epub_toc_at_end': False,
     'epub_version': '2',
     'expand_css': False,
     'extra_css': None,
     'extract_to': None,
     'filter_css': '',
     'fix_indents': True,
     'flow_size': 260,
     'font_size_mapping': None,
     'format_scene_breaks': True,
     'html_unwrap_factor': 0.4,
     'input_encoding': None,
     'input_profile': <calibre.customize.profiles.InputProfile object at 0x10db1cee0>,
     'insert_blank_line': False,
     'insert_blank_line_size': 0.5,
     'insert_metadata': False,
     'isbn': None,
     'italicize_common_cases': True,
     'keep_ligatures': False,
     'language': None,
     'level1_toc': None,
     'level2_toc': None,
     'level3_toc': None,
     'line_height': 0.0,
     'linearize_tables': False,
     'margin_bottom': 5.0,
     'margin_left': 5.0,
     'margin_right': 5.0,
     'margin_top': 5.0,
     'markup_chapter_headings': True,
     'max_toc_links': 50,
     'minimum_line_height': 120.0,
     'no_chapters_in_toc': False,
     'no_default_epub_cover': False,
     'no_inline_navbars': False,
     'no_svg_cover': False,
     'output_profile': <calibre.customize.profiles.KindlePaperWhite3Output object at 0x10db1c8e0>,
     'page_breaks_before': '/',
     'prefer_metadata_cover': False,
     'preserve_cover_aspect_ratio': False,
     'pretty_print': True,
     'pubdate': None,
     'publisher': None,
     'rating': None,
     'read_metadata_from_opf': '/var/folders/3k/tr22qcqx0jg9blc862xz725c0000gn/C/calibre_6.29.0_tmp_gdxkt2wn/3az23r8j.opf',
     'remove_fake_margins': True,
     'remove_first_image': False,
     'remove_paragraph_spacing': False,
     'remove_paragraph_spacing_indent_size': 1.5,
     'renumber_headings': True,
     'replace_scene_breaks': '',
     'search_replace': '[]',
     'series': None,
     'series_index': None,
     'smarten_punctuation': False,
     'sr1_replace': None,
     'sr1_search': None,
     'sr2_replace': None,
     'sr2_search': None,
     'sr3_replace': None,
     'sr3_search': None,
     'start_reading_at': None,
     'subset_embedded_fonts': False,
     'tags': None,
     'timestamp': None,
     'title': None,
     'title_sort': None,
     'toc_filter': None,
     'toc_threshold': 6,
     'toc_title': None,
     'transform_css_rules': '[]',
     'transform_html_rules': '[]',
     'unsmarten_punctuation': False,
     'unwrap_lines': True,
     'use_auto_toc': False,
     'verbose': 2}
    DeDRM v10.0.9: Trying to decrypt m_x3c26n.kfx-zip
    Decrypting KFX-ZIP ebook: m_x3c26n
    Found 0 keys to try after 0.0 seconds
    Decrypting KFX DRM voucher: voucher
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Decryption failed, trying next fallback 
    Traceback (most recent call last):
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/kfxdedrm.py", line 105, in decrypt_voucher
        voucher.decryptvoucher()
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/ion.py", line 1368, in decryptvoucher
        raise ex
    UnboundLocalError: local variable 'ex' referenced before assignment
    DeDRM v10.0.9: Failed to decrypt with error: Failed to decrypt KFX DRM voucher with any key
    DeDRM v10.0.9: Looking for new default Kindle Key after 0.0 seconds
    No k4Mac kindle-info/rainier/kinf2011 files have been found.
    DeDRM v10.0.9: Ultimately failed to decrypt after 0.0 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
    Running file type plugin DeDRM failed with traceback:
    Traceback (most recent call last):
      File "calibre_plugins.dedrm.__init__", line 931, in KindleMobiDecrypt
        book = k4mobidedrm.GetDecryptedBook(path_to_ebook,kindleDatabases,androidFiles,serials,pids,self.starttime)
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/k4mobidedrm.py", line 203, in GetDecryptedBook
        mb.processBook(totalpids)
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/kfxdedrm.py", line 67, in processBook
        self.decrypt_voucher(totalpids)
      File "/Users/vhosouza/Library/Preferences/calibre/plugins/DeDRM.zip/kfxdedrm.py", line 111, in decrypt_voucher
        raise Exception("Failed to decrypt KFX DRM voucher with any key")
    Exception: Failed to decrypt KFX DRM voucher with any key

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "calibre/customize/ui.py", line 187, in _run_filetype_plugins
      File "calibre_plugins.dedrm.__init__", line 1030, in run
        decrypted_ebook = self.KindleMobiDecrypt(path_to_ebook)
      File "calibre_plugins.dedrm.__init__", line 981, in KindleMobiDecrypt
        raise DeDRMError("{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
    calibre_plugins.dedrm.DeDRMError: DeDRM v10.0.9: Ultimately failed to decrypt after 0.0 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
    InputFormatPlugin: KFX Input running
    on /var/folders/3k/tr22qcqx0jg9blc862xz725c0000gn/C/calibre_6.29.0_tmp_gdxkt2wn/m_x3c26n.kfx-zip
    Software versions: KFX Input 2.9.0, calibre 6.29, macOS-14.4.1-arm64-arm-64bit
    KFX Input plugin help is available at https://www.mobileread.com/forums/showthread.php?t=291290
    Converting /var/folders/3k/tr22qcqx0jg9blc862xz725c0000gn/C/calibre_6.29.0_tmp_gdxkt2wn/m_x3c26n.kfx-zip
    Processing container: CR!TA1MGN6R896RH568R9SH5V7QG8FC.kfx
    Processing container: The Comeback Quotient_ Mastering Mental Fitness for Sport and Life (English Edition)_B08RZ9Z8ZS.kfx
    Traceback (most recent call last):
      File "calibre_plugins.kfx_input.__init__", line 102, in convert
      File "calibre_plugins.kfx_input.kfxlib.yj_book", line 212, in decode_book
      File "calibre_plugins.kfx_input.kfxlib.yj_book", line 321, in get_container
    calibre_plugins.kfx_input.kfxlib.utilities.KFXDRMError: Book container The Comeback Quotient_ Mastering Mental Fitness for Sport and Life (English Edition)_B08RZ9Z8ZS.kfx has DRM and cannot be converted

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "runpy.py", line 196, in _run_module_as_main
      File "runpy.py", line 86, in _run_code
      File "site.py", line 41, in <module>
      File "site.py", line 37, in main
      File "calibre/utils/ipc/worker.py", line 215, in main
      File "calibre/gui2/convert/gui_conversion.py", line 38, in gui_convert_override
      File "calibre/gui2/convert/gui_conversion.py", line 25, in gui_convert
      File "calibre/ebooks/conversion/plumber.py", line 1108, in run
      File "calibre/customize/conversion.py", line 242, in __call__
      File "calibre_plugins.kfx_input.__init__", line 121, in convert
    calibre.ebooks.DRMError: This book has DRM!
ElleKayEm commented 3 months ago

Were those files from an E-ink Kindle (not a Fire)? If so, you need to enter the Kindle's serial number into DeDRM's customization.

vhosouza commented 3 months ago

@ElleKayEm thanks for the super fast solution. Adding the serial number sovled the issue.