Fix for Obok Plugin and Obok Desktop v4.0

This commit is contained in:
Apprentice Harper 2016-09-28 07:14:16 +01:00
parent 34231cc252
commit 6b4d621159
3 changed files with 26 additions and 19 deletions

Binary file not shown.

View File

@ -19,7 +19,7 @@ except NameError:
PLUGIN_NAME = 'Obok DeDRM' PLUGIN_NAME = 'Obok DeDRM'
PLUGIN_SAFE_NAME = PLUGIN_NAME.strip().lower().replace(' ', '_') PLUGIN_SAFE_NAME = PLUGIN_NAME.strip().lower().replace(' ', '_')
PLUGIN_DESCRIPTION = _('Removes DRM from Kobo kepubs and adds them to the library.') PLUGIN_DESCRIPTION = _('Removes DRM from Kobo kepubs and adds them to the library.')
PLUGIN_VERSION_TUPLE = (6, 3, 6) PLUGIN_VERSION_TUPLE = (6, 5, 2)
PLUGIN_VERSION = '.'.join([str(x) for x in PLUGIN_VERSION_TUPLE]) PLUGIN_VERSION = '.'.join([str(x) for x in PLUGIN_VERSION_TUPLE])
HELPFILE_NAME = PLUGIN_SAFE_NAME + '_Help.htm' HELPFILE_NAME = PLUGIN_SAFE_NAME + '_Help.htm'
PLUGIN_AUTHORS = 'Anon' PLUGIN_AUTHORS = 'Anon'

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Version 3.2.1 September 2016
# Update for v4.0 of Windows Desktop app.
#
# Version 3.2.0 January 2016 # Version 3.2.0 January 2016
# Update for latest version of Windows Desktop app. # Update for latest version of Windows Desktop app.
# Support Kobo devices in the command line version. # Support Kobo devices in the command line version.
@ -136,13 +139,13 @@
# #
"""Manage all Kobo books, either encrypted or DRM-free.""" """Manage all Kobo books, either encrypted or DRM-free."""
__version__ = '3.1.9' __version__ = '3.2.1'
__about__ = u"Obok v{0}\nCopyright © 2012-2015 Physisticated et al.".format(__version__) __about__ = u"Obok v{0}\nCopyright © 2012-2016 Physisticated et al.".format(__version__)
import sys import sys
import os import os
import subprocess import subprocess
import sqlite3 import apsw
import base64 import base64
import binascii import binascii
import re import re
@ -162,7 +165,7 @@ except ImportError:
# print u"Cannot find xml.etree, disabling extraction of serial numbers" # print u"Cannot find xml.etree, disabling extraction of serial numbers"
# List of all known hash keys # List of all known hash keys
KOBO_HASH_KEYS = ['88b3a2e13', 'XzUhGYdFp', 'NoCanLook'] KOBO_HASH_KEYS = ['88b3a2e13', 'XzUhGYdFp', 'NoCanLook','QJhwzAtXL']
class ENCRYPTIONError(Exception): class ENCRYPTIONError(Exception):
pass pass
@ -355,7 +358,7 @@ class KoboLibrary(object):
if (self.kobodir != u""): if (self.kobodir != u""):
self.bookdir = os.path.join(self.kobodir, u"kepub") self.bookdir = os.path.join(self.kobodir, u"kepub")
self.__sqlite = sqlite3.connect(kobodb) self.__sqlite = apsw.Connection(kobodb)
self.__cursor = self.__sqlite.cursor() self.__cursor = self.__sqlite.cursor()
self._userkeys = [] self._userkeys = []
self._books = [] self._books = []
@ -390,11 +393,13 @@ class KoboLibrary(object):
"""Drm-free""" """Drm-free"""
for f in os.listdir(self.bookdir): for f in os.listdir(self.bookdir):
if(f not in self._volumeID): if(f not in self._volumeID):
row = self.__cursor.execute("SELECT Title, Attribution, Series FROM content WHERE ContentID = '" + f + "'").fetchone() try:
if row is not None: row = self.__cursor.execute("SELECT Title, Attribution, Series FROM content WHERE ContentID = '" + f + "'").next()
fTitle = row[0] fTitle = row[0]
self._books.append(KoboBook(f, fTitle, self.__bookfile(f), 'drm-free', self.__cursor, author=row[1], series=row[2])) self._books.append(KoboBook(f, fTitle, self.__bookfile(f), 'drm-free', self.__cursor, author=row[1], series=row[2]))
self._volumeID.append(f) self._volumeID.append(f)
except StopIteration:
pass
"""Sort""" """Sort"""
self._books.sort(key=lambda x: x.title) self._books.sort(key=lambda x: x.title)
return self._books return self._books
@ -436,14 +441,9 @@ class KoboLibrary(object):
def __getuserids (self): def __getuserids (self):
userids = [] userids = []
cursor = self.__cursor.execute('SELECT UserID FROM user') cursor = self.__cursor.execute('SELECT UserID FROM user')
row = cursor.fetchone() for row in cursor.next():
while row is not None: userid = row
try:
userid = row[0]
userids.append(userid) userids.append(userid)
except:
pass
row = cursor.fetchone()
return userids return userids
def __getuserkeys (self, macaddr): def __getuserkeys (self, macaddr):
@ -558,12 +558,19 @@ class KoboFile(object):
Returns True if the content was checked, False if it was not Returns True if the content was checked, False if it was not
checked.""" checked."""
if self.mimetype == 'application/xhtml+xml': if self.mimetype == 'application/xhtml+xml':
if contents[:5]=="<?xml": if contents[:5]=="<?xml" or contents[:8]=="\xef\xbb\xbf<?xml":
# utf-8
return True
elif contents[:14]=="\xfe\xff\x00<\x00?\x00x\x00m\x00l":
# utf-16BE
return True
elif contents[:14]=="\xff\xfe<\x00?\x00x\x00m\x00l\x00":
# utf-16LE
return True return True
else: else:
print u"Bad XML: {0}".format(contents[:5]) print u"Bad XML: {0}".format(contents[:8])
raise ValueError raise ValueError
if self.mimetype == 'image/jpeg': elif self.mimetype == 'image/jpeg':
if contents[:3] == '\xff\xd8\xff': if contents[:3] == '\xff\xd8\xff':
return True return True
else: else: