2020-09-27 16:54:49 +06:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2013-10-03 00:59:40 +06:00
|
|
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
|
|
|
|
|
|
|
__license__ = 'GPL v3'
|
|
|
|
|
|
|
|
# Standard Python modules.
|
2021-12-29 14:26:29 +06:00
|
|
|
import os, sys
|
2013-10-03 00:59:40 +06:00
|
|
|
import traceback
|
|
|
|
|
2021-12-29 14:26:29 +06:00
|
|
|
# Calibre stuff - so we can import from our ZIP without absolute module name
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
2021-12-27 15:35:02 +06:00
|
|
|
|
2021-12-29 14:26:29 +06:00
|
|
|
from calibre.utils.config import JSONConfig
|
|
|
|
from __init__ import PLUGIN_NAME
|
2013-10-03 00:59:40 +06:00
|
|
|
|
|
|
|
class DeDRM_Prefs():
|
|
|
|
def __init__(self):
|
2020-09-27 16:54:49 +06:00
|
|
|
JSON_PATH = os.path.join("plugins", PLUGIN_NAME.strip().lower().replace(' ', '_') + '.json')
|
2013-10-03 00:59:40 +06:00
|
|
|
self.dedrmprefs = JSONConfig(JSON_PATH)
|
|
|
|
|
|
|
|
self.dedrmprefs.defaults['configured'] = False
|
2021-11-15 22:59:48 +06:00
|
|
|
self.dedrmprefs.defaults['deobfuscate_fonts'] = True
|
2021-11-17 21:17:30 +06:00
|
|
|
self.dedrmprefs.defaults['remove_watermarks'] = False
|
2013-10-03 00:59:40 +06:00
|
|
|
self.dedrmprefs.defaults['bandnkeys'] = {}
|
|
|
|
self.dedrmprefs.defaults['adeptkeys'] = {}
|
|
|
|
self.dedrmprefs.defaults['ereaderkeys'] = {}
|
|
|
|
self.dedrmprefs.defaults['kindlekeys'] = {}
|
2015-07-29 23:11:19 +06:00
|
|
|
self.dedrmprefs.defaults['androidkeys'] = {}
|
2013-10-03 00:59:40 +06:00
|
|
|
self.dedrmprefs.defaults['pids'] = []
|
|
|
|
self.dedrmprefs.defaults['serials'] = []
|
2021-11-18 02:53:24 +06:00
|
|
|
self.dedrmprefs.defaults['lcp_passphrases'] = []
|
2021-12-27 15:45:12 +06:00
|
|
|
self.dedrmprefs.defaults['adobe_pdf_passphrases'] = []
|
2013-10-03 00:59:40 +06:00
|
|
|
self.dedrmprefs.defaults['adobewineprefix'] = ""
|
|
|
|
self.dedrmprefs.defaults['kindlewineprefix'] = ""
|
|
|
|
|
|
|
|
# initialise
|
|
|
|
# we must actually set the prefs that are dictionaries and lists
|
|
|
|
# to empty dictionaries and lists, otherwise we are unable to add to them
|
|
|
|
# as then it just adds to the (memory only) dedrmprefs.defaults versions!
|
|
|
|
if self.dedrmprefs['bandnkeys'] == {}:
|
|
|
|
self.dedrmprefs['bandnkeys'] = {}
|
|
|
|
if self.dedrmprefs['adeptkeys'] == {}:
|
|
|
|
self.dedrmprefs['adeptkeys'] = {}
|
|
|
|
if self.dedrmprefs['ereaderkeys'] == {}:
|
|
|
|
self.dedrmprefs['ereaderkeys'] = {}
|
|
|
|
if self.dedrmprefs['kindlekeys'] == {}:
|
|
|
|
self.dedrmprefs['kindlekeys'] = {}
|
2015-07-29 23:11:19 +06:00
|
|
|
if self.dedrmprefs['androidkeys'] == {}:
|
|
|
|
self.dedrmprefs['androidkeys'] = {}
|
2013-10-03 00:59:40 +06:00
|
|
|
if self.dedrmprefs['pids'] == []:
|
|
|
|
self.dedrmprefs['pids'] = []
|
|
|
|
if self.dedrmprefs['serials'] == []:
|
|
|
|
self.dedrmprefs['serials'] = []
|
2021-11-18 02:53:24 +06:00
|
|
|
if self.dedrmprefs['lcp_passphrases'] == []:
|
|
|
|
self.dedrmprefs['lcp_passphrases'] = []
|
2021-12-27 15:45:12 +06:00
|
|
|
if self.dedrmprefs['adobe_pdf_passphrases'] == []:
|
|
|
|
self.dedrmprefs['adobe_pdf_passphrases'] = []
|
2013-10-03 00:59:40 +06:00
|
|
|
|
|
|
|
def __getitem__(self,kind = None):
|
|
|
|
if kind is not None:
|
|
|
|
return self.dedrmprefs[kind]
|
|
|
|
return self.dedrmprefs
|
|
|
|
|
|
|
|
def set(self, kind, value):
|
|
|
|
self.dedrmprefs[kind] = value
|
|
|
|
|
|
|
|
def writeprefs(self,value = True):
|
|
|
|
self.dedrmprefs['configured'] = value
|
|
|
|
|
|
|
|
def addnamedvaluetoprefs(self, prefkind, keyname, keyvalue):
|
|
|
|
try:
|
|
|
|
if keyvalue not in self.dedrmprefs[prefkind].values():
|
|
|
|
# ensure that the keyname is unique
|
|
|
|
# by adding a number (starting with 2) to the name if it is not
|
|
|
|
namecount = 1
|
|
|
|
newname = keyname
|
|
|
|
while newname in self.dedrmprefs[prefkind]:
|
|
|
|
namecount += 1
|
|
|
|
newname = "{0:s}_{1:d}".format(keyname,namecount)
|
|
|
|
# add to the preferences
|
|
|
|
self.dedrmprefs[prefkind][newname] = keyvalue
|
|
|
|
return (True, newname)
|
|
|
|
except:
|
|
|
|
traceback.print_exc()
|
|
|
|
pass
|
|
|
|
return (False, keyname)
|
|
|
|
|
|
|
|
def addvaluetoprefs(self, prefkind, prefsvalue):
|
|
|
|
# ensure the keyvalue isn't already in the preferences
|
|
|
|
try:
|
|
|
|
if prefsvalue not in self.dedrmprefs[prefkind]:
|
|
|
|
self.dedrmprefs[prefkind].append(prefsvalue)
|
|
|
|
return True
|
|
|
|
except:
|
|
|
|
traceback.print_exc()
|
|
|
|
return False
|