diff --git a/Obok_calibre_plugin/obok_plugin.zip b/Obok_calibre_plugin/obok_plugin.zip index 3e1b918..2e091bc 100644 Binary files a/Obok_calibre_plugin/obok_plugin.zip and b/Obok_calibre_plugin/obok_plugin.zip differ diff --git a/Obok_calibre_plugin/obok_plugin/__init__.py b/Obok_calibre_plugin/obok_plugin/__init__.py index dd643c7..5a5eea0 100644 --- a/Obok_calibre_plugin/obok_plugin/__init__.py +++ b/Obok_calibre_plugin/obok_plugin/__init__.py @@ -19,7 +19,7 @@ except NameError: PLUGIN_NAME = 'Obok DeDRM' PLUGIN_SAFE_NAME = PLUGIN_NAME.strip().lower().replace(' ', '_') PLUGIN_DESCRIPTION = _('Removes DRM from Kobo kepubs and adds them to the library.') -PLUGIN_VERSION_TUPLE = (3, 1, 5) +PLUGIN_VERSION_TUPLE = (3, 1, 6) PLUGIN_VERSION = '.'.join([str(x) for x in PLUGIN_VERSION_TUPLE]) HELPFILE_NAME = PLUGIN_SAFE_NAME + '_Help.htm' PLUGIN_AUTHORS = 'Anon' diff --git a/Obok_calibre_plugin/obok_plugin/obok/obok.py b/Obok_calibre_plugin/obok_plugin/obok/obok.py index ca74284..04b9075 100644 --- a/Obok_calibre_plugin/obok_plugin/obok/obok.py +++ b/Obok_calibre_plugin/obok_plugin/obok/obok.py @@ -1,6 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +# Version 3.1.6 September 2015 +# Enable support for Kobo devices +# More character encoding fixes (unicode strings) +# # Version 3.1.5 September 2015 # Removed requirement that a purchase has been made. # Also add in character encoding fixes @@ -119,7 +123,7 @@ # """Manage all Kobo books, either encrypted or DRM-free.""" -__version__ = '3.1.5' +__version__ = '3.1.6' import sys import os @@ -246,36 +250,41 @@ class KoboLibrary(object): def __init__ (self, serials = [], device_path = None): print u"Obok v{0}\nCopyright © 2012-2015 Physisticated et al.".format(__version__) - self.kobodir = '' - kobodb = '' + self.kobodir = u"" + kobodb = u"" # - first check whether serials have been found or are provided # and a device is connected. In this case, use the device # - otherwise fall back to Kobo Desktop Application for Windows and Mac if (device_path and (len(serials) > 0)): - self.kobodir = os.path.join(device_path, '.kobo') + self.kobodir = os.path.join(device_path, u".kobo") # devices use KoboReader.sqlite - kobodb = os.path.join(self.kobodir, 'KoboReader.sqlite') + kobodb = os.path.join(self.kobodir, u"KoboReader.sqlite") if (not(os.path.exists(kobodb))): # give up here, we haven't found anything useful - self.kobodir = '' - kobodb = '' + self.kobodir = u"" + kobodb = u"" - if (self.kobodir == ''): + if (self.kobodir == u""): # we haven't found a device with serials, so try desktop apps if sys.platform.startswith('win'): + import _winreg as winreg if sys.getwindowsversion().major > 5: - self.kobodir = os.environ['LOCALAPPDATA'] - else: - self.kobodir = os.path.join(os.environ['USERPROFILE'], 'Local Settings', 'Application Data') - self.kobodir = os.path.join(self.kobodir, 'Kobo', 'Kobo Desktop Edition') + if 'LOCALAPPDATA' in os.environ.keys(): + # Python 2.x does not return unicode env. Use Python 3.x + self.kobodir = winreg.ExpandEnvironmentStrings(u"%LOCALAPPDATA%") + if (self.kobodir == u""): + if 'USERPROFILE' in os.environ.keys(): + # Python 2.x does not return unicode env. Use Python 3.x + self.kobodir = os.path.join(winreg.ExpandEnvironmentStrings(u"%USERPROFILE%"), u"Local Settings", u"Application Data") + 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'], 'Library', 'Application Support', 'Kobo', 'Kobo Desktop Edition') + self.kobodir = os.path.join(os.environ['HOME'], u"Library", u"Application Support", u"Kobo", u"Kobo Desktop Edition") # desktop versions use Kobo.sqlite - kobodb = os.path.join(self.kobodir, 'Kobo.sqlite') + kobodb = os.path.join(self.kobodir, u"Kobo.sqlite") - if (self.kobodir != ''): - self.bookdir = os.path.join(self.kobodir, 'kepub') + if (self.kobodir != u""): + self.bookdir = os.path.join(self.kobodir, u"kepub") self.__sqlite = sqlite3.connect(kobodb) self.__cursor = self.__sqlite.cursor() self._userkeys = [] @@ -322,7 +331,7 @@ class KoboLibrary(object): def __bookfile (self, volumeid): """The filename needed to open a given book.""" - return os.path.join(self.kobodir, 'kepub', volumeid) + return os.path.join(self.kobodir, u"kepub", volumeid) def __getmacaddrs (self): """The list of all MAC addresses on this machine.""" @@ -338,7 +347,7 @@ class KoboLibrary(object): output = subprocess.check_output('/sbin/ifconfig -a', shell=True) matches = c.findall(output) for m in matches: - # print "m:",m[0] + # print u"m:{0}".format(m[0]) macaddrs.append(m[0].upper()) # extend the list of macaddrs in any case with the serials @@ -480,13 +489,13 @@ class KoboFile(object): if contents[:5]==" 5: - self.kobodir = os.environ['LOCALAPPDATA'] - else: - self.kobodir = os.path.join(os.environ['USERPROFILE'], 'Local Settings', 'Application Data') - self.kobodir = os.path.join(self.kobodir, 'Kobo', 'Kobo Desktop Edition') - elif sys.platform.startswith('darwin'): - self.kobodir = os.path.join(os.environ['HOME'], 'Library', 'Application Support', 'Kobo', 'Kobo Desktop Edition') - self.bookdir = os.path.join(self.kobodir, 'kepub') - kobodb = os.path.join(self.kobodir, 'Kobo.sqlite') - self.__sqlite = sqlite3.connect(kobodb) - self.__cursor = self.__sqlite.cursor() - self._userkeys = [] - self._books = [] - self._volumeID = [] + self.kobodir = u"" + kobodb = u"" + + # - first check whether serials have been found or are provided + # and a device is connected. In this case, use the device + # - otherwise fall back to Kobo Desktop Application for Windows and Mac + if (device_path and (len(serials) > 0)): + self.kobodir = os.path.join(device_path, u".kobo") + # devices use KoboReader.sqlite + kobodb = os.path.join(self.kobodir, u"KoboReader.sqlite") + if (not(os.path.exists(kobodb))): + # give up here, we haven't found anything useful + self.kobodir = u"" + kobodb = u"" + + if (self.kobodir == u""): + # we haven't found a device with serials, so try desktop apps + if sys.platform.startswith('win'): + import _winreg as winreg + if sys.getwindowsversion().major > 5: + if 'LOCALAPPDATA' in os.environ.keys(): + # Python 2.x does not return unicode env. Use Python 3.x + self.kobodir = winreg.ExpandEnvironmentStrings(u"%LOCALAPPDATA%") + if (self.kobodir == u""): + if 'USERPROFILE' in os.environ.keys(): + # Python 2.x does not return unicode env. Use Python 3.x + self.kobodir = os.path.join(winreg.ExpandEnvironmentStrings(u"%USERPROFILE%"), u"Local Settings", u"Application Data") + 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") + # desktop versions use Kobo.sqlite + kobodb = os.path.join(self.kobodir, u"Kobo.sqlite") + + if (self.kobodir != u""): + self.bookdir = os.path.join(self.kobodir, u"kepub") + self.__sqlite = sqlite3.connect(kobodb) + self.__cursor = self.__sqlite.cursor() + self._userkeys = [] + self._books = [] + self._volumeID = [] + self._serials = serials def close (self): """Closes the database used by the library.""" @@ -301,7 +331,7 @@ class KoboLibrary(object): def __bookfile (self, volumeid): """The filename needed to open a given book.""" - return os.path.join(self.kobodir, 'kepub', volumeid) + return os.path.join(self.kobodir, u"kepub", volumeid) def __getmacaddrs (self): """The list of all MAC addresses on this machine.""" @@ -317,8 +347,13 @@ class KoboLibrary(object): output = subprocess.check_output('/sbin/ifconfig -a', shell=True) matches = c.findall(output) for m in matches: - # print "m:",m[0] + # print u"m:{0}".format(m[0]) macaddrs.append(m[0].upper()) + + # extend the list of macaddrs in any case with the serials + # cannot hurt ;-) + macaddrs.extend(self._serials) + return macaddrs def __getuserids (self): @@ -454,13 +489,13 @@ class KoboFile(object): if contents[:5]=="