summaryrefslogtreecommitdiffstats
path: root/Other_Tools
diff options
context:
space:
mode:
authorApprentice Harper <[email protected]>2017-01-12 07:24:42 +0000
committerApprentice Harper <[email protected]>2017-01-12 07:24:42 +0000
commit956f3034ada12a07f8df4f08d134a2c70c9a4d05 (patch)
tree5d5b9a5936a341bb7130d75b6c10859f0f7deaf1 /Other_Tools
parentfca7eaab8e26bf79d0515b3e33317e23b09c5c29 (diff)
Explicitly warn about KFX files. Bump version number to 6.5.3
Diffstat (limited to 'Other_Tools')
-rw-r--r--Other_Tools/Kobo/obok.py42
1 files changed, 39 insertions, 3 deletions
diff --git a/Other_Tools/Kobo/obok.py b/Other_Tools/Kobo/obok.py
index 149d09c..d2188e3 100644
--- a/Other_Tools/Kobo/obok.py
+++ b/Other_Tools/Kobo/obok.py
@@ -1,6 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+# Version 3.2.5 December 2016
+# Improve detection of good text decryption.
+#
+# Version 3.2.4 December 2016
+# Remove incorrect support for Kobo Desktop under Wine
+#
# Version 3.2.3 October 2016
# Fix for windows network user and more xml fixes
#
@@ -145,7 +151,7 @@
#
"""Manage all Kobo books, either encrypted or DRM-free."""
-__version__ = '3.2.3'
+__version__ = '3.2.4'
__about__ = u"Obok v{0}\nCopyright © 2012-2016 Physisticated et al.".format(__version__)
import sys
@@ -351,9 +357,9 @@ class KoboLibrary(object):
self.kobodir = os.path.join(self.kobodir, u"Kobo", u"Kobo Desktop Edition")
elif sys.platform.startswith('darwin'):
self.kobodir = os.path.join(os.environ['HOME'], u"Library", u"Application Support", u"Kobo", u"Kobo Desktop Edition")
- elif linux_path != None:
+ #elif linux_path != None:
# Probably Linux, let's get the wine prefix and path to Kobo.
- self.kobodir = os.path.join(linux_path, u"Local Settings", u"Application Data", u"Kobo", u"Kobo Desktop Edition")
+ # self.kobodir = os.path.join(linux_path, u"Local Settings", u"Application Data", u"Kobo", u"Kobo Desktop Edition")
# desktop versions use Kobo.sqlite
kobodb = os.path.join(self.kobodir, u"Kobo.sqlite")
# check for existence of file
@@ -582,6 +588,36 @@ class KoboFile(object):
Returns True if the content was checked, False if it was not
checked."""
if self.mimetype == 'application/xhtml+xml':
+ # assume utf-8 with no BOM
+ textoffset = 0
+ stride = 1
+ print u"Checking text:{0}:".format(contents[:10])
+ # check for byte order mark
+ if contents[:3]=="\xef\xbb\xbf":
+ # seems to be utf-8 with BOM
+ print u"Could be utf-8 with BOM"
+ textoffset = 3
+ elif contents[:2]=="\xfe\xff":
+ # seems to be utf-16BE
+ print u"Could be utf-16BE"
+ textoffset = 3
+ stride = 2
+ elif contents[:2]=="\xff\xfe":
+ # seems to be utf-16LE
+ print u"Could be utf-16LE"
+ textoffset = 2
+ stride = 2
+ else:
+ print u"Perhaps utf-8 without BOM"
+
+ # now check that the first few characters are in the ASCII range
+ for i in xrange(textoffset,textoffset+5*stride,stride):
+ if ord(contents[i])<32 or ord(contents[i])>127:
+ # Non-ascii, so decryption probably failed
+ print u"Bad character at {0}, value {1}".format(i,ord(contents[i]))
+ raise ValueError
+ print u"Seems to be good text"
+ return True
if contents[:5]=="<?xml" or contents[:8]=="\xef\xbb\xbf<?xml":
# utf-8
return True