mirror of
https://github.com/noDRM/DeDRM_tools.git
synced 2026-03-20 04:58:56 +00:00
Compare commits
3 Commits
8228e38d5a
...
f9fecbde6d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9fecbde6d | ||
|
|
ef67dbd204 | ||
|
|
ad33aea18d |
@@ -14,7 +14,8 @@ if "calibre" in sys.modules and sys.version_info[0] == 2:
|
||||
if os.path.join(config_dir, "plugins", "DeDRM.zip") not in sys.path:
|
||||
sys.path.insert(0, os.path.join(config_dir, "plugins", "DeDRM.zip"))
|
||||
|
||||
# Explicitly set the package identifier so we are allowed to import stuff ...
|
||||
__package__ = "calibre_plugins.dedrm"
|
||||
if "calibre" in sys.modules:
|
||||
# Explicitly set the package identifier so we are allowed to import stuff ...
|
||||
__package__ = "calibre_plugins.dedrm"
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE_END@@
|
||||
|
||||
@@ -5,10 +5,21 @@
|
||||
# (CLI interface without Calibre)
|
||||
# Copyright © 2021 NoDRM
|
||||
|
||||
"""
|
||||
|
||||
NOTE: This code is not functional (yet). I started working on it a while ago
|
||||
to make a standalone version of the plugins that could work without Calibre,
|
||||
too, but for now there's only a rough code structure and no working code yet.
|
||||
|
||||
Currently, to use these plugins, you will need to use Calibre. Hopwfully that'll
|
||||
change in the future.
|
||||
|
||||
"""
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
# For revision history see __init__.py
|
||||
# For revision history see CHANGELOG.md
|
||||
|
||||
"""
|
||||
Run DeDRM plugin without Calibre.
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
# For use with Topaz Scripts Version 2.6
|
||||
# Python 3, September 2020
|
||||
|
||||
from utilities import SafeUnbuffered
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
from .utilities import SafeUnbuffered
|
||||
|
||||
import sys
|
||||
import csv
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
|
||||
__version__ = '2.0'
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
import sys, struct, os, traceback
|
||||
import zlib
|
||||
import zipfile
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
# Python 3 for calibre 5.0
|
||||
from __future__ import print_function
|
||||
|
||||
from utilities import SafeUnbuffered
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
from .utilities import SafeUnbuffered
|
||||
|
||||
import sys
|
||||
import csv
|
||||
|
||||
@@ -45,6 +45,8 @@ import os
|
||||
import hashlib
|
||||
import base64
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
try:
|
||||
from Cryptodome.Cipher import AES
|
||||
except ImportError:
|
||||
|
||||
@@ -27,6 +27,8 @@ import hashlib
|
||||
import getopt
|
||||
import re
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
from .utilities import SafeUnbuffered
|
||||
|
||||
try:
|
||||
|
||||
@@ -70,6 +70,8 @@ def unpad(data, padding=16):
|
||||
|
||||
return data[:-pad_len]
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
from .utilities import SafeUnbuffered
|
||||
from .argv_utils import unicode_argv
|
||||
|
||||
|
||||
@@ -92,13 +92,14 @@ def unpad(data, padding=16):
|
||||
|
||||
return data[:-pad_len]
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
from .utilities import SafeUnbuffered
|
||||
from .argv_utils import unicode_argv
|
||||
|
||||
iswindows = sys.platform.startswith('win')
|
||||
isosx = sys.platform.startswith('darwin')
|
||||
|
||||
from .argv_utils import unicode_argv
|
||||
|
||||
class ADEPTError(Exception):
|
||||
pass
|
||||
|
||||
@@ -30,6 +30,9 @@ import struct
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
|
||||
try:
|
||||
from Cryptodome.Cipher import AES
|
||||
from Cryptodome.Util.py3compat import bchr
|
||||
@@ -57,7 +60,7 @@ except ImportError:
|
||||
# Windows-friendly choice: pylzma wheels
|
||||
import pylzma as lzma
|
||||
|
||||
from kfxtables import *
|
||||
from .kfxtables import *
|
||||
|
||||
TID_NULL = 0
|
||||
TID_BOOLEAN = 1
|
||||
|
||||
@@ -62,6 +62,8 @@ except NameError:
|
||||
|
||||
# Routines common to Mac and PC
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
from .utilities import SafeUnbuffered
|
||||
from .argv_utils import unicode_argv
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
import sys
|
||||
import binascii
|
||||
|
||||
from .utilities import SafeUnbuffered
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
from .utilities import SafeUnbuffered
|
||||
from .argv_utils import unicode_argv
|
||||
|
||||
letters = b'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'
|
||||
|
||||
@@ -327,36 +327,50 @@ class KoboLibrary(object):
|
||||
elif sys.platform.startswith('darwin'):
|
||||
self.kobodir = os.path.join(os.environ['HOME'], "Library", "Application Support", "Kobo", "Kobo Desktop Edition")
|
||||
elif sys.platform.startswith('linux'):
|
||||
# Since on Linux, you have to run Kobo Desktop within Wine,
|
||||
# there is no guarantee where Kobo.sqlite (and the rest of
|
||||
# the kobo directory) might be.
|
||||
#
|
||||
# It should also be noted that Kobo Desktop will store all
|
||||
# of it files in the current directory where you run it,
|
||||
# meaning that a user might accidentally create several
|
||||
# Kobo.sqlite files which are all separate and then be
|
||||
# confused why Obok can't find any of the new books. Sadly
|
||||
# there isn't a trivial way to deal with this.
|
||||
|
||||
#sets ~/.config/calibre as the location to store the kobodir location info file and creates this directory if necessary
|
||||
kobodir_cache_dir = os.path.join(os.environ['HOME'], ".config", "calibre")
|
||||
# We cache the kobodir we find in ~/.config/calibre.
|
||||
kobodir_cache_dir = os.path.join(os.environ['HOME'], ".config", "calibre", "plugins", "obok")
|
||||
if not os.path.isdir(kobodir_cache_dir):
|
||||
os.mkdir(kobodir_cache_dir)
|
||||
kobodir_cache_file = os.path.join(kobodir_cache_dir, "kobo-location")
|
||||
|
||||
#appends the name of the file we're storing the kobodir location info to the above path
|
||||
kobodir_cache_file = str(kobodir_cache_dir) + "/" + "kobo location"
|
||||
try:
|
||||
# If the cached version exists and the path does really
|
||||
# contain Kobo.sqlite, use that.
|
||||
with open(kobodir_cache_file, "r") as f:
|
||||
cached_kobodir = f.read().strip()
|
||||
assert os.path.isfile(os.path.join(cached_kobodir, "Kobo.sqlite"))
|
||||
self.kobodir = cached_kobodir
|
||||
except (AssertionError, FileNotFoundError):
|
||||
# If there was no cached version, search the entire
|
||||
# filesystem tree for a directory containing
|
||||
# "Kobo.sqlite".
|
||||
#
|
||||
# We first search $HOME to avoid picking another user's
|
||||
# Kobo.sqlite file, but then fallback to / if there was
|
||||
# nothing in $HOME.
|
||||
for candidate_root in (os.environ["HOME"], "/"):
|
||||
for root, _, files in os.walk(candidate_root):
|
||||
if "Kobo.sqlite" in files:
|
||||
with open(kobodir_cache_file, "w") as f:
|
||||
f.write("%s/\n" % (root,))
|
||||
self.kobodir = root
|
||||
break
|
||||
|
||||
"""if the above file does not exist, recursively searches from the root
|
||||
of the filesystem until kobodir is found and stores the location of kobodir
|
||||
in that file so this loop can be skipped in the future"""
|
||||
original_stdout = sys.stdout
|
||||
if not os.path.isfile(kobodir_cache_file):
|
||||
for root, dirs, files in os.walk('/'):
|
||||
for file in files:
|
||||
if file == 'Kobo.sqlite':
|
||||
kobo_linux_path = str(root)
|
||||
with open(kobodir_cache_file, 'w') as f:
|
||||
sys.stdout = f
|
||||
print(kobo_linux_path, end='')
|
||||
sys.stdout = original_stdout
|
||||
|
||||
f = open(kobodir_cache_file, 'r' )
|
||||
self.kobodir = f.read()
|
||||
|
||||
# desktop versions use Kobo.sqlite
|
||||
# Desktop versions use Kobo.sqlite.
|
||||
kobodb = os.path.join(self.kobodir, "Kobo.sqlite")
|
||||
# check for existence of file
|
||||
if (not(os.path.isfile(kobodb))):
|
||||
if not os.path.isfile(kobodb):
|
||||
# give up here, we haven't found anything useful
|
||||
self.kobodir = u""
|
||||
kobodb = u""
|
||||
|
||||
Reference in New Issue
Block a user