mirror of
https://github.com/noDRM/DeDRM_tools.git
synced 2025-01-12 03:14:43 +06:00
New obok fix that should work for stand-alone script and non-Windows machines. (Makes a tweaked copy of the database.)
This commit is contained in:
parent
5d75018719
commit
d65dd1ab87
Binary file not shown.
@ -1,6 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Version 3.2.2 October 2016
|
||||||
|
# Change to the way the new database version is handled.
|
||||||
|
#
|
||||||
# Version 3.2.1 September 2016
|
# Version 3.2.1 September 2016
|
||||||
# Update for v4.0 of Windows Desktop app.
|
# Update for v4.0 of Windows Desktop app.
|
||||||
#
|
#
|
||||||
@ -139,13 +142,13 @@
|
|||||||
#
|
#
|
||||||
"""Manage all Kobo books, either encrypted or DRM-free."""
|
"""Manage all Kobo books, either encrypted or DRM-free."""
|
||||||
|
|
||||||
__version__ = '3.2.1'
|
__version__ = '3.2.2'
|
||||||
__about__ = u"Obok v{0}\nCopyright © 2012-2016 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 apsw
|
import sqlite3
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
import re
|
import re
|
||||||
@ -155,6 +158,7 @@ import xml.etree.ElementTree as ET
|
|||||||
import string
|
import string
|
||||||
import shutil
|
import shutil
|
||||||
import argparse
|
import argparse
|
||||||
|
import tempfile
|
||||||
|
|
||||||
can_parse_xml = True
|
can_parse_xml = True
|
||||||
try:
|
try:
|
||||||
@ -358,7 +362,18 @@ 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 = apsw.Connection(kobodb)
|
# make a copy of the database in a temporary file
|
||||||
|
# so we can ensure it's not using WAL logging which sqlite3 can't do.
|
||||||
|
self.newdb = tempfile.NamedTemporaryFile(mode='wb', delete=False)
|
||||||
|
print self.newdb.name
|
||||||
|
olddb = open(kobodb, 'rb')
|
||||||
|
self.newdb.write(olddb.read(18))
|
||||||
|
self.newdb.write('\x01\x01')
|
||||||
|
olddb.read(2)
|
||||||
|
self.newdb.write(olddb.read())
|
||||||
|
olddb.close()
|
||||||
|
self.newdb.close()
|
||||||
|
self.__sqlite = sqlite3.connect(self.newdb.name)
|
||||||
self.__cursor = self.__sqlite.cursor()
|
self.__cursor = self.__sqlite.cursor()
|
||||||
self._userkeys = []
|
self._userkeys = []
|
||||||
self._books = []
|
self._books = []
|
||||||
@ -369,6 +384,8 @@ class KoboLibrary(object):
|
|||||||
"""Closes the database used by the library."""
|
"""Closes the database used by the library."""
|
||||||
self.__cursor.close()
|
self.__cursor.close()
|
||||||
self.__sqlite.close()
|
self.__sqlite.close()
|
||||||
|
# delete the temporary copy of the database
|
||||||
|
os.remove(self.newdb.name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def userkeys (self):
|
def userkeys (self):
|
||||||
@ -393,13 +410,11 @@ 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):
|
||||||
try:
|
row = self.__cursor.execute("SELECT Title, Attribution, Series FROM content WHERE ContentID = '" + f + "'").fetchone()
|
||||||
row = self.__cursor.execute("SELECT Title, Attribution, Series FROM content WHERE ContentID = '" + f + "'").next()
|
if row is not None:
|
||||||
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
|
||||||
@ -441,9 +456,14 @@ 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')
|
||||||
for row in cursor.next():
|
row = cursor.fetchone()
|
||||||
userid = row
|
while row is not None:
|
||||||
|
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):
|
||||||
|
Loading…
Reference in New Issue
Block a user