]> xmof Git - DeDRM.git/commitdiff
tools v5.5.3
authorApprentice Alf <apprenticealf@gmail.com>
Wed, 26 Dec 2012 23:17:56 +0000 (23:17 +0000)
committerApprentice Alf <apprenticealf@gmail.com>
Sat, 7 Mar 2015 14:02:17 +0000 (14:02 +0000)
17 files changed:
Calibre_Plugins/K4MobiDeDRM_plugin/__init__.py
Calibre_Plugins/K4MobiDeDRM_plugin/convert2xml.py
Calibre_Plugins/K4MobiDeDRM_plugin/stylexml2css.py
Calibre_Plugins/K4MobiDeDRM_plugin/topazextract.py
Calibre_Plugins/k4mobidedrm_plugin.zip
DeDRM_Macintosh_Application/DeDRM ReadMe.rtf
DeDRM_Macintosh_Application/DeDRM.app/Contents/Info.plist
DeDRM_Macintosh_Application/DeDRM.app/Contents/Resources/convert2xml.py
DeDRM_Macintosh_Application/DeDRM.app/Contents/Resources/getk4pcpids.py
DeDRM_Macintosh_Application/DeDRM.app/Contents/Resources/stylexml2css.py
DeDRM_Macintosh_Application/DeDRM.app/Contents/Resources/topazextract.py
DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/DeDRM_app.pyw
DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/convert2xml.py
DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/getk4pcpids.py
DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/stylexml2css.py
DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/topazextract.py
DeDRM_Windows_Application/DeDRM_ReadMe.txt

index e5a1702a66384c89b97ff7fdbeb22df00649d383..46b57c94b2ab029fa97b85580581638a92dea316 100644 (file)
@@ -21,13 +21,14 @@ __docformat__ = 'restructuredtext en'
 #   0.4.10 - Another Topaz Fix (class added to page and group and region)
 #   0.4.11 - Fixed Linux support of K4PC
 #   0.4.12 - More Linux Wine fixes
+#   0.4.13 - Ancient Mobipocket files fix
 
 """
 Decrypt Amazon Kindle and Mobipocket encrypted ebooks.
 """
 
 PLUGIN_NAME = u"Kindle and Mobipocket DeDRM"
-PLUGIN_VERSION_TUPLE = (0, 4, 12)
+PLUGIN_VERSION_TUPLE = (0, 4, 13)
 PLUGIN_VERSION = '.'.join([str(x) for x in PLUGIN_VERSION_TUPLE])
 
 import sys, os, re
index 0f64a1b9991ce10807bc249c22476c354a82e5b2..6c8fa83cd5cdeb1fbb00b44a746d4ed085e9ade9 100644 (file)
@@ -277,6 +277,7 @@ class PageParser(object):
 
         'word_semantic'           : (1, 'snippets', 1, 1),
         'word_semantic.type'      : (1, 'scalar_text', 0, 0),
+        'word_semantic.class'     : (1, 'scalar_text', 0, 0),
         'word_semantic.firstWord' : (1, 'scalar_number', 0, 0),
         'word_semantic.lastWord'  : (1, 'scalar_number', 0, 0),
 
@@ -287,6 +288,7 @@ class PageParser(object):
         'word.lastGlyph'  : (1, 'scalar_number', 0, 0),
 
         '_span'           : (1, 'snippets', 1, 0),
+        '_span.class'     : (1, 'scalar_text', 0, 0),
         '_span.firstWord' : (1, 'scalar_number', 0, 0),
         '_span.lastWord'  : (1, 'scalar_number', 0, 0),
         '_span.gridSize'  : (1, 'scalar_number', 0, 0),
@@ -350,16 +352,18 @@ class PageParser(object):
         'version.paragraph_continuation'   : (1, 'scalar_text', 0, 0),
         'version.toc'                      : (1, 'scalar_text', 0, 0),
 
-        'stylesheet'   : (1, 'snippets', 1, 0),
-        'style'              : (1, 'snippets', 1, 0),
-        'style._tag'         : (1, 'scalar_text', 0, 0),
-        'style.type'         : (1, 'scalar_text', 0, 0),
-        'style._parent_type' : (1, 'scalar_text', 0, 0),
-        'style.class'        : (1, 'scalar_text', 0, 0),
-        'style._after_class' : (1, 'scalar_text', 0, 0),
-        'rule'               : (1, 'snippets', 1, 0),
-        'rule.attr'          : (1, 'scalar_text', 0, 0),
-        'rule.value'         : (1, 'scalar_text', 0, 0),
+        'stylesheet'                : (1, 'snippets', 1, 0),
+        'style'                     : (1, 'snippets', 1, 0),
+        'style._tag'                : (1, 'scalar_text', 0, 0),
+        'style.type'                : (1, 'scalar_text', 0, 0),
+        'style._after_type'         : (1, 'scalar_text', 0, 0),
+        'style._parent_type'        : (1, 'scalar_text', 0, 0),
+        'style._after_parent_type'  : (1, 'scalar_text', 0, 0),
+        'style.class'               : (1, 'scalar_text', 0, 0),
+        'style._after_class'        : (1, 'scalar_text', 0, 0),
+        'rule'                      : (1, 'snippets', 1, 0),
+        'rule.attr'                 : (1, 'scalar_text', 0, 0),
+        'rule.value'                : (1, 'scalar_text', 0, 0),
 
         'original'      : (0, 'number', 1, 1),
         'original.pnum' : (1, 'number', 0, 0),
index 2347f6aeb128bd5cdfc22f8d52dc5d8c05ba63b2..c111850a5e8a2cb9b79b5bd117ad59ab799b8a8f 100644 (file)
@@ -10,6 +10,7 @@ import re
 from struct import pack
 from struct import unpack
 
+debug = False
 
 class DocParser(object):
     def __init__(self, flatxml, fontsize, ph, pw):
@@ -113,7 +114,9 @@ class DocParser(object):
 
         # process each style converting what you can
 
+        if debug: print '          ', 'Processing styles.'
         for j in xrange(stylecnt):
+            if debug: print '          ', 'Processing style %d' %(j)
             start = styleList[j]
             end = styleList[j+1]
 
@@ -132,6 +135,8 @@ class DocParser(object):
                 else :
                     sclass = ''
 
+                if debug: print 'sclass', sclass
+
                 # check for any "after class" specifiers
                 (pos, aftclass) = self.findinDoc('style._after_class',start,end)
                 if aftclass != None:
@@ -140,6 +145,8 @@ class DocParser(object):
                 else :
                     aftclass = ''
 
+                if debug: print 'aftclass', aftclass
+
                 cssargs = {}
 
                 while True :
@@ -147,6 +154,9 @@ class DocParser(object):
                     (pos1, attr) = self.findinDoc('style.rule.attr', start, end)
                     (pos2, val) = self.findinDoc('style.rule.value', start, end)
 
+                    if debug: print 'attr', attr
+                    if debug: print 'val', val
+
                     if attr == None : break
 
                     if (attr == 'display') or (attr == 'pos') or (attr == 'align'):
@@ -164,7 +174,7 @@ class DocParser(object):
                                 scale = self.pw
                             elif attr == 'line-space':
                                 scale = self.fontsize * 2.0
-                            
+
                             if val == "":
                                 val = 0
 
@@ -179,6 +189,7 @@ class DocParser(object):
                 if aftclass != "" : keep = False
 
                 if keep :
+                    if debug: print 'keeping style'
                     # make sure line-space does not go below 100% or above 300% since
                     # it can be wacky in some styles
                     if 'line-space' in cssargs:
@@ -256,7 +267,9 @@ def convert2CSS(flatxml, fontsize, ph, pw):
 
     # create a document parser
     dp = DocParser(flatxml, fontsize, ph, pw)
+    if debug: print '          ', 'Created DocParser.'
     csspage = dp.process()
+    if debug: print '          ', 'Processed DocParser.'
     return csspage
 
 
index a343922f4d2637e7ce3047e7b6d3354294e3e894..3e4db392c0ab65ad68e0357e7d18b335e38bf9be 100644 (file)
@@ -69,6 +69,9 @@ def unicode_argv():
             argvencoding = 'utf-8'
         return [arg if (type(arg) == unicode) else unicode(arg,argvencoding) for arg in sys.argv]
 
+#global switch
+debug = False
+
 if 'calibre' in sys.modules:
     inCalibre = True
     from calibre_plugins.k4mobidedrm import kgenpids
@@ -206,6 +209,7 @@ class TopazBook:
             # Read and return the data of one header record at the current book file position
             # [[offset,decompressedLength,compressedLength],...]
             nbValues = bookReadEncodedNumber(self.fo)
+            if debug: print "%d records in header " % nbValues,
             values = []
             for i in range (0,nbValues):
                 values.append([bookReadEncodedNumber(self.fo),bookReadEncodedNumber(self.fo),bookReadEncodedNumber(self.fo)])
@@ -219,9 +223,10 @@ class TopazBook:
             record = bookReadHeaderRecordData()
             return [tag,record]
         nbRecords = bookReadEncodedNumber(self.fo)
+        if debug: print "Headers: %d" % nbRecords
         for i in range (0,nbRecords):
             result = parseTopazHeaderRecord()
-            # print result[0], result[1]
+            if debug: print result[0], ": ", result[1]
             self.bookHeaderRecords[result[0]] = result[1]
         if ord(self.fo.read(1))  != 0x64 :
             raise DrmException(u"Parse Error : Invalid Header")
@@ -235,12 +240,12 @@ class TopazBook:
             raise DrmException(u"Parse Error : Record Names Don't Match")
         flags = ord(self.fo.read(1))
         nbRecords = ord(self.fo.read(1))
-        # print nbRecords
+        if debug: print "Metadata Records: %d" % nbRecords
         for i in range (0,nbRecords) :
             keyval = bookReadString(self.fo)
             content = bookReadString(self.fo)
-            # print keyval
-            # print content
+            if debug: print keyval
+            if debug: print content
             self.bookMetadata[keyval] = content
         return self.bookMetadata
 
index 9c00bfea26f49c6fceef326db423a46237d0bc45..37436f659be8f7074febd5354355d436f7191492 100644 (file)
Binary files a/Calibre_Plugins/k4mobidedrm_plugin.zip and b/Calibre_Plugins/k4mobidedrm_plugin.zip differ
index 63da82513174f4d95ca87a8db2330bd50a8010a7..9293969dab322cd0cebfde82818895b3b13d73ae 100644 (file)
@@ -41,7 +41,7 @@ Mac OS X 10.5 and above: You do
 \i not
 \i0  need to install Python.\
 \
-Drag the DeDRM application from from tools_v5.5\\DeDRM_Applications\\Macintosh (the location of this ReadMe) to your Applications folder, or anywhere else you find convenient.\
+Drag the DeDRM application from from tools_v5.5.3\\DeDRM_Applications\\Macintosh (the location of this ReadMe) to your Applications folder, or anywhere else you find convenient.\
 \
 \
 
index 2d8ce5a753378d10bc149332a80cdf26540f1f18..64cc357d5551795b31a29d58bcf435fd6d9205c2 100644 (file)
        <key>CFBundleExecutable</key>
        <string>droplet</string>
        <key>CFBundleGetInfoString</key>
-       <string>DeDRM 5.5. AppleScript written 2010–2012 by Apprentice Alf and others.</string>
+       <string>DeDRM 5.5.3. AppleScript written 2010–2012 by Apprentice Alf and others.</string>
        <key>CFBundleIconFile</key>
        <string>DeDRM</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
-       <string>DeDRM 5.5</string>
+       <string>DeDRM 5.5.3</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleShortVersionString</key>
-       <string>5.5</string>
+       <string>5.5.3</string>
        <key>CFBundleSignature</key>
        <string>dplt</string>
        <key>LSRequiresCarbon</key>
index 0f64a1b9991ce10807bc249c22476c354a82e5b2..6c8fa83cd5cdeb1fbb00b44a746d4ed085e9ade9 100644 (file)
@@ -277,6 +277,7 @@ class PageParser(object):
 
         'word_semantic'           : (1, 'snippets', 1, 1),
         'word_semantic.type'      : (1, 'scalar_text', 0, 0),
+        'word_semantic.class'     : (1, 'scalar_text', 0, 0),
         'word_semantic.firstWord' : (1, 'scalar_number', 0, 0),
         'word_semantic.lastWord'  : (1, 'scalar_number', 0, 0),
 
@@ -287,6 +288,7 @@ class PageParser(object):
         'word.lastGlyph'  : (1, 'scalar_number', 0, 0),
 
         '_span'           : (1, 'snippets', 1, 0),
+        '_span.class'     : (1, 'scalar_text', 0, 0),
         '_span.firstWord' : (1, 'scalar_number', 0, 0),
         '_span.lastWord'  : (1, 'scalar_number', 0, 0),
         '_span.gridSize'  : (1, 'scalar_number', 0, 0),
@@ -350,16 +352,18 @@ class PageParser(object):
         'version.paragraph_continuation'   : (1, 'scalar_text', 0, 0),
         'version.toc'                      : (1, 'scalar_text', 0, 0),
 
-        'stylesheet'   : (1, 'snippets', 1, 0),
-        'style'              : (1, 'snippets', 1, 0),
-        'style._tag'         : (1, 'scalar_text', 0, 0),
-        'style.type'         : (1, 'scalar_text', 0, 0),
-        'style._parent_type' : (1, 'scalar_text', 0, 0),
-        'style.class'        : (1, 'scalar_text', 0, 0),
-        'style._after_class' : (1, 'scalar_text', 0, 0),
-        'rule'               : (1, 'snippets', 1, 0),
-        'rule.attr'          : (1, 'scalar_text', 0, 0),
-        'rule.value'         : (1, 'scalar_text', 0, 0),
+        'stylesheet'                : (1, 'snippets', 1, 0),
+        'style'                     : (1, 'snippets', 1, 0),
+        'style._tag'                : (1, 'scalar_text', 0, 0),
+        'style.type'                : (1, 'scalar_text', 0, 0),
+        'style._after_type'         : (1, 'scalar_text', 0, 0),
+        'style._parent_type'        : (1, 'scalar_text', 0, 0),
+        'style._after_parent_type'  : (1, 'scalar_text', 0, 0),
+        'style.class'               : (1, 'scalar_text', 0, 0),
+        'style._after_class'        : (1, 'scalar_text', 0, 0),
+        'rule'                      : (1, 'snippets', 1, 0),
+        'rule.attr'                 : (1, 'scalar_text', 0, 0),
+        'rule.value'                : (1, 'scalar_text', 0, 0),
 
         'original'      : (0, 'number', 1, 1),
         'original.pnum' : (1, 'number', 0, 0),
index cc8bcd45ac6139e86c5326528a02a36d7f3644d5..1614a534ffce3d02f082dbea8b1d03221354b7b4 100644 (file)
@@ -11,15 +11,21 @@ __version__ = '1.01'
 
 import sys
 
-class Unbuffered:
+class SafeUnbuffered:
     def __init__(self, stream):
         self.stream = stream
+        self.encoding = stream.encoding
+        if self.encoding == None:
+            self.encoding = "utf-8"
     def write(self, data):
+        if isinstance(data,unicode):
+            data = data.encode(self.encoding,"replace")
         self.stream.write(data)
         self.stream.flush()
     def __getattr__(self, attr):
         return getattr(self.stream, attr)
-sys.stdout=Unbuffered(sys.stdout)
+sys.stdout=SafeUnbuffered(sys.stdout)
+sys.stderr=SafeUnbuffered(sys.stderr)
 
 import os
 import struct
@@ -41,7 +47,7 @@ def getK4PCpids(path_to_ebook):
         mobi = False
 
     if mobi:
-        mb = mobidedrm.MobiBook(path_to_ebook,False)
+        mb = mobidedrm.MobiBook(path_to_ebook)
     else:
         mb = topazextract.TopazBook(path_to_ebook)
 
index 2347f6aeb128bd5cdfc22f8d52dc5d8c05ba63b2..c111850a5e8a2cb9b79b5bd117ad59ab799b8a8f 100644 (file)
@@ -10,6 +10,7 @@ import re
 from struct import pack
 from struct import unpack
 
+debug = False
 
 class DocParser(object):
     def __init__(self, flatxml, fontsize, ph, pw):
@@ -113,7 +114,9 @@ class DocParser(object):
 
         # process each style converting what you can
 
+        if debug: print '          ', 'Processing styles.'
         for j in xrange(stylecnt):
+            if debug: print '          ', 'Processing style %d' %(j)
             start = styleList[j]
             end = styleList[j+1]
 
@@ -132,6 +135,8 @@ class DocParser(object):
                 else :
                     sclass = ''
 
+                if debug: print 'sclass', sclass
+
                 # check for any "after class" specifiers
                 (pos, aftclass) = self.findinDoc('style._after_class',start,end)
                 if aftclass != None:
@@ -140,6 +145,8 @@ class DocParser(object):
                 else :
                     aftclass = ''
 
+                if debug: print 'aftclass', aftclass
+
                 cssargs = {}
 
                 while True :
@@ -147,6 +154,9 @@ class DocParser(object):
                     (pos1, attr) = self.findinDoc('style.rule.attr', start, end)
                     (pos2, val) = self.findinDoc('style.rule.value', start, end)
 
+                    if debug: print 'attr', attr
+                    if debug: print 'val', val
+
                     if attr == None : break
 
                     if (attr == 'display') or (attr == 'pos') or (attr == 'align'):
@@ -164,7 +174,7 @@ class DocParser(object):
                                 scale = self.pw
                             elif attr == 'line-space':
                                 scale = self.fontsize * 2.0
-                            
+
                             if val == "":
                                 val = 0
 
@@ -179,6 +189,7 @@ class DocParser(object):
                 if aftclass != "" : keep = False
 
                 if keep :
+                    if debug: print 'keeping style'
                     # make sure line-space does not go below 100% or above 300% since
                     # it can be wacky in some styles
                     if 'line-space' in cssargs:
@@ -256,7 +267,9 @@ def convert2CSS(flatxml, fontsize, ph, pw):
 
     # create a document parser
     dp = DocParser(flatxml, fontsize, ph, pw)
+    if debug: print '          ', 'Created DocParser.'
     csspage = dp.process()
+    if debug: print '          ', 'Processed DocParser.'
     return csspage
 
 
index a343922f4d2637e7ce3047e7b6d3354294e3e894..3e4db392c0ab65ad68e0357e7d18b335e38bf9be 100644 (file)
@@ -69,6 +69,9 @@ def unicode_argv():
             argvencoding = 'utf-8'
         return [arg if (type(arg) == unicode) else unicode(arg,argvencoding) for arg in sys.argv]
 
+#global switch
+debug = False
+
 if 'calibre' in sys.modules:
     inCalibre = True
     from calibre_plugins.k4mobidedrm import kgenpids
@@ -206,6 +209,7 @@ class TopazBook:
             # Read and return the data of one header record at the current book file position
             # [[offset,decompressedLength,compressedLength],...]
             nbValues = bookReadEncodedNumber(self.fo)
+            if debug: print "%d records in header " % nbValues,
             values = []
             for i in range (0,nbValues):
                 values.append([bookReadEncodedNumber(self.fo),bookReadEncodedNumber(self.fo),bookReadEncodedNumber(self.fo)])
@@ -219,9 +223,10 @@ class TopazBook:
             record = bookReadHeaderRecordData()
             return [tag,record]
         nbRecords = bookReadEncodedNumber(self.fo)
+        if debug: print "Headers: %d" % nbRecords
         for i in range (0,nbRecords):
             result = parseTopazHeaderRecord()
-            # print result[0], result[1]
+            if debug: print result[0], ": ", result[1]
             self.bookHeaderRecords[result[0]] = result[1]
         if ord(self.fo.read(1))  != 0x64 :
             raise DrmException(u"Parse Error : Invalid Header")
@@ -235,12 +240,12 @@ class TopazBook:
             raise DrmException(u"Parse Error : Record Names Don't Match")
         flags = ord(self.fo.read(1))
         nbRecords = ord(self.fo.read(1))
-        # print nbRecords
+        if debug: print "Metadata Records: %d" % nbRecords
         for i in range (0,nbRecords) :
             keyval = bookReadString(self.fo)
             content = bookReadString(self.fo)
-            # print keyval
-            # print content
+            if debug: print keyval
+            if debug: print content
             self.bookMetadata[keyval] = content
         return self.bookMetadata
 
index d0a2bead11b76a6713c6f7b6af22b4127bec9868..23cc30a1ed331b136c52b340a763948740d50091 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-# DeDRM.pyw, version 5.5
+# DeDRM.pyw, version 5.5.3
 # By some_updates and Apprentice Alf
 
 import sys
@@ -24,7 +24,7 @@ import re
 import simpleprefs
 
 
-__version__ = '5.5'
+__version__ = '5.5.3'
 
 class DrmException(Exception):
     pass
@@ -441,10 +441,10 @@ class ConvDialog(Toplevel):
                 self.log += text
                 self.log += msg
             else:
+                msg = u"\nFailed\n"
                 text = self.p2.read().decode('utf8')
                 text += self.p2.readerr().decode('utf8')
                 msg += text
-                msg += u"\nFailed\n"
                 self.numbad += 1
                 self.log += msg
             self.showCmdOutput(msg)
index 0f64a1b9991ce10807bc249c22476c354a82e5b2..6c8fa83cd5cdeb1fbb00b44a746d4ed085e9ade9 100644 (file)
@@ -277,6 +277,7 @@ class PageParser(object):
 
         'word_semantic'           : (1, 'snippets', 1, 1),
         'word_semantic.type'      : (1, 'scalar_text', 0, 0),
+        'word_semantic.class'     : (1, 'scalar_text', 0, 0),
         'word_semantic.firstWord' : (1, 'scalar_number', 0, 0),
         'word_semantic.lastWord'  : (1, 'scalar_number', 0, 0),
 
@@ -287,6 +288,7 @@ class PageParser(object):
         'word.lastGlyph'  : (1, 'scalar_number', 0, 0),
 
         '_span'           : (1, 'snippets', 1, 0),
+        '_span.class'     : (1, 'scalar_text', 0, 0),
         '_span.firstWord' : (1, 'scalar_number', 0, 0),
         '_span.lastWord'  : (1, 'scalar_number', 0, 0),
         '_span.gridSize'  : (1, 'scalar_number', 0, 0),
@@ -350,16 +352,18 @@ class PageParser(object):
         'version.paragraph_continuation'   : (1, 'scalar_text', 0, 0),
         'version.toc'                      : (1, 'scalar_text', 0, 0),
 
-        'stylesheet'   : (1, 'snippets', 1, 0),
-        'style'              : (1, 'snippets', 1, 0),
-        'style._tag'         : (1, 'scalar_text', 0, 0),
-        'style.type'         : (1, 'scalar_text', 0, 0),
-        'style._parent_type' : (1, 'scalar_text', 0, 0),
-        'style.class'        : (1, 'scalar_text', 0, 0),
-        'style._after_class' : (1, 'scalar_text', 0, 0),
-        'rule'               : (1, 'snippets', 1, 0),
-        'rule.attr'          : (1, 'scalar_text', 0, 0),
-        'rule.value'         : (1, 'scalar_text', 0, 0),
+        'stylesheet'                : (1, 'snippets', 1, 0),
+        'style'                     : (1, 'snippets', 1, 0),
+        'style._tag'                : (1, 'scalar_text', 0, 0),
+        'style.type'                : (1, 'scalar_text', 0, 0),
+        'style._after_type'         : (1, 'scalar_text', 0, 0),
+        'style._parent_type'        : (1, 'scalar_text', 0, 0),
+        'style._after_parent_type'  : (1, 'scalar_text', 0, 0),
+        'style.class'               : (1, 'scalar_text', 0, 0),
+        'style._after_class'        : (1, 'scalar_text', 0, 0),
+        'rule'                      : (1, 'snippets', 1, 0),
+        'rule.attr'                 : (1, 'scalar_text', 0, 0),
+        'rule.value'                : (1, 'scalar_text', 0, 0),
 
         'original'      : (0, 'number', 1, 1),
         'original.pnum' : (1, 'number', 0, 0),
index cc8bcd45ac6139e86c5326528a02a36d7f3644d5..1614a534ffce3d02f082dbea8b1d03221354b7b4 100644 (file)
@@ -11,15 +11,21 @@ __version__ = '1.01'
 
 import sys
 
-class Unbuffered:
+class SafeUnbuffered:
     def __init__(self, stream):
         self.stream = stream
+        self.encoding = stream.encoding
+        if self.encoding == None:
+            self.encoding = "utf-8"
     def write(self, data):
+        if isinstance(data,unicode):
+            data = data.encode(self.encoding,"replace")
         self.stream.write(data)
         self.stream.flush()
     def __getattr__(self, attr):
         return getattr(self.stream, attr)
-sys.stdout=Unbuffered(sys.stdout)
+sys.stdout=SafeUnbuffered(sys.stdout)
+sys.stderr=SafeUnbuffered(sys.stderr)
 
 import os
 import struct
@@ -41,7 +47,7 @@ def getK4PCpids(path_to_ebook):
         mobi = False
 
     if mobi:
-        mb = mobidedrm.MobiBook(path_to_ebook,False)
+        mb = mobidedrm.MobiBook(path_to_ebook)
     else:
         mb = topazextract.TopazBook(path_to_ebook)
 
index 2347f6aeb128bd5cdfc22f8d52dc5d8c05ba63b2..c111850a5e8a2cb9b79b5bd117ad59ab799b8a8f 100644 (file)
@@ -10,6 +10,7 @@ import re
 from struct import pack
 from struct import unpack
 
+debug = False
 
 class DocParser(object):
     def __init__(self, flatxml, fontsize, ph, pw):
@@ -113,7 +114,9 @@ class DocParser(object):
 
         # process each style converting what you can
 
+        if debug: print '          ', 'Processing styles.'
         for j in xrange(stylecnt):
+            if debug: print '          ', 'Processing style %d' %(j)
             start = styleList[j]
             end = styleList[j+1]
 
@@ -132,6 +135,8 @@ class DocParser(object):
                 else :
                     sclass = ''
 
+                if debug: print 'sclass', sclass
+
                 # check for any "after class" specifiers
                 (pos, aftclass) = self.findinDoc('style._after_class',start,end)
                 if aftclass != None:
@@ -140,6 +145,8 @@ class DocParser(object):
                 else :
                     aftclass = ''
 
+                if debug: print 'aftclass', aftclass
+
                 cssargs = {}
 
                 while True :
@@ -147,6 +154,9 @@ class DocParser(object):
                     (pos1, attr) = self.findinDoc('style.rule.attr', start, end)
                     (pos2, val) = self.findinDoc('style.rule.value', start, end)
 
+                    if debug: print 'attr', attr
+                    if debug: print 'val', val
+
                     if attr == None : break
 
                     if (attr == 'display') or (attr == 'pos') or (attr == 'align'):
@@ -164,7 +174,7 @@ class DocParser(object):
                                 scale = self.pw
                             elif attr == 'line-space':
                                 scale = self.fontsize * 2.0
-                            
+
                             if val == "":
                                 val = 0
 
@@ -179,6 +189,7 @@ class DocParser(object):
                 if aftclass != "" : keep = False
 
                 if keep :
+                    if debug: print 'keeping style'
                     # make sure line-space does not go below 100% or above 300% since
                     # it can be wacky in some styles
                     if 'line-space' in cssargs:
@@ -256,7 +267,9 @@ def convert2CSS(flatxml, fontsize, ph, pw):
 
     # create a document parser
     dp = DocParser(flatxml, fontsize, ph, pw)
+    if debug: print '          ', 'Created DocParser.'
     csspage = dp.process()
+    if debug: print '          ', 'Processed DocParser.'
     return csspage
 
 
index a343922f4d2637e7ce3047e7b6d3354294e3e894..3e4db392c0ab65ad68e0357e7d18b335e38bf9be 100644 (file)
@@ -69,6 +69,9 @@ def unicode_argv():
             argvencoding = 'utf-8'
         return [arg if (type(arg) == unicode) else unicode(arg,argvencoding) for arg in sys.argv]
 
+#global switch
+debug = False
+
 if 'calibre' in sys.modules:
     inCalibre = True
     from calibre_plugins.k4mobidedrm import kgenpids
@@ -206,6 +209,7 @@ class TopazBook:
             # Read and return the data of one header record at the current book file position
             # [[offset,decompressedLength,compressedLength],...]
             nbValues = bookReadEncodedNumber(self.fo)
+            if debug: print "%d records in header " % nbValues,
             values = []
             for i in range (0,nbValues):
                 values.append([bookReadEncodedNumber(self.fo),bookReadEncodedNumber(self.fo),bookReadEncodedNumber(self.fo)])
@@ -219,9 +223,10 @@ class TopazBook:
             record = bookReadHeaderRecordData()
             return [tag,record]
         nbRecords = bookReadEncodedNumber(self.fo)
+        if debug: print "Headers: %d" % nbRecords
         for i in range (0,nbRecords):
             result = parseTopazHeaderRecord()
-            # print result[0], result[1]
+            if debug: print result[0], ": ", result[1]
             self.bookHeaderRecords[result[0]] = result[1]
         if ord(self.fo.read(1))  != 0x64 :
             raise DrmException(u"Parse Error : Invalid Header")
@@ -235,12 +240,12 @@ class TopazBook:
             raise DrmException(u"Parse Error : Record Names Don't Match")
         flags = ord(self.fo.read(1))
         nbRecords = ord(self.fo.read(1))
-        # print nbRecords
+        if debug: print "Metadata Records: %d" % nbRecords
         for i in range (0,nbRecords) :
             keyval = bookReadString(self.fo)
             content = bookReadString(self.fo)
-            # print keyval
-            # print content
+            if debug: print keyval
+            if debug: print content
             self.bookMetadata[keyval] = content
         return self.bookMetadata
 
index df13eb5b0236ce16aa53086817654ae8cb59ca20..ad52d33098f04f4724cd2ca8d3b1fcdef570e9e6 100644 (file)
@@ -1,7 +1,7 @@
-ReadMe_DeDRM_v5.5_WinApp
+ReadMe_DeDRM_v5.5.3_WinApp
 ========================
 
-DeDRM_v5.5_WinApp is a pure python drag and drop application that allows users to drag and drop ebooks or folders of ebooks onto the DeDRM_Drop_Target to have the DRM removed.  It repackages all the "tools" python software in one easy to use program that remembers preferences and settings.
+DeDRM_v5.5.3_WinApp is a pure python drag and drop application that allows users to drag and drop ebooks or folders of ebooks onto the DeDRM_Drop_Target to have the DRM removed.  It repackages all the "tools" python software in one easy to use program that remembers preferences and settings.
 
 It will work without manual configuration for Kindle for PC ebooks and Adobe Adept epub and pdf ebooks.
 
@@ -23,9 +23,9 @@ Installation
 
 0. If you don't already have a correct version of Python and PyCrypto installed, follow the "Installing Python on Windows" and "Installing PyCrypto on Windows" sections below before continuing.
 
-1. Drag the DeDRM_5.5 folder from tools_v5.5/DeDRM_Applications/Windows to your "My Documents" folder.
+1. Drag the DeDRM_5.5.3 folder from tools_v5.5.3/DeDRM_Applications/Windows to your "My Documents" folder.
 
-2. Open the DeDRM_5.5 folder you've just dragged, and make a short-cut of the DeDRM_Drop_Target.bat file (right-click/Create Shortcut). Drag the shortcut file onto your Desktop.
+2. Open the DeDRM_5.5.3 folder you've just dragged, and make a short-cut of the DeDRM_Drop_Target.bat file (right-click/Create Shortcut). Drag the shortcut file onto your Desktop.
 
 3. To set the preferences simply double-click on your just created short-cut.