Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@

# Cache
/DeDRM_plugin/__pycache__
/DeDRM_plugin/standalone/__pycache__
/DeDRM_plugin/standalone/__pycache__
__pycache__/
*.pyc
.pytest_cache/
Binary file added Obok_DeDRM_plugin.zip
Binary file not shown.
27 changes: 26 additions & 1 deletion Obok_plugin/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

from calibre_plugins.obok_dedrm.obok.obok import KoboLibrary
from calibre_plugins.obok_dedrm.obok.legacy_obok import legacy_obok
from calibre_plugins.obok_dedrm.title_match import LibraryMatcher

PLUGIN_ICONS = ['images/obok.png']

Expand Down Expand Up @@ -131,8 +132,32 @@ def launchObok(self):
showErrorDlg(msg, None)
return

# Build a matcher over the titles already in the calibre library so the
# dialog can flag (and filter) Kobo books that are already imported.
# Kobo and calibre store titles independently, so LibraryMatcher
# normalizes both sides and falls back to a bounded fuzzy match.
try:
book_ids = self.db.all_book_ids()
entries = []
for book_id in book_ids:
title = self.db.field_for('title', book_id)
authors = self.db.field_for('authors', book_id)
if isinstance(authors, (tuple, list)):
author = ' & '.join(a for a in authors if a)
else:
author = authors or ''
entries.append((title, author))
matcher = LibraryMatcher(entries)
debug_print("OBOK DIAG: built library matcher from %d calibre books (%d unique normalized titles)"
% (len(book_ids), len(matcher)))
except Exception:
debug_print("OBOK DIAG: FAILED to read calibre library titles -- traceback follows")
traceback.print_exc()
matcher = LibraryMatcher([])

# Launch the Dialog so the user can select titles.
dlg = SelectionDialog(self.gui, self, books)
from calibre_plugins.obok_dedrm.config import plugin_prefs
dlg = SelectionDialog(self.gui, self, books, plugin_prefs, matcher)
if dlg.exec_():
books_to_import = dlg.getBooks()
self.count = len(books_to_import)
Expand Down
1 change: 1 addition & 0 deletions Obok_plugin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
plugin_prefs.defaults['finding_homes_for_formats'] = 'Ask'
plugin_prefs.defaults['kobo_serials'] = []
plugin_prefs.defaults['kobo_directory'] = u''
plugin_prefs.defaults['hidden_books'] = []

from calibre_plugins.obok_dedrm.__init__ import PLUGIN_NAME, PLUGIN_VERSION
from calibre_plugins.obok_dedrm.utilities import (debug_print)
Expand Down
276 changes: 215 additions & 61 deletions Obok_plugin/dialogs.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Obok_plugin/obok/obok.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def __getmacaddrs (self):
"""The list of all MAC addresses on this machine."""
macaddrs = []
if sys.platform.startswith('win'):
c = re.compile('\s?(' + '[0-9a-f]{2}[:\-]' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
c = re.compile(r'\s?(' + r'[0-9a-f]{2}[:\-]' * 5 + r'[0-9a-f]{2})(\s|$)', re.IGNORECASE)
try:
output = subprocess.Popen('ipconfig /all', shell=True, stdout=subprocess.PIPE, text=True).stdout
for line in output:
Expand All @@ -443,7 +443,7 @@ def __getmacaddrs (self):
if m:
macaddrs.append(re.sub("-", ":", m.group(1)).upper())
elif sys.platform.startswith('darwin'):
c = re.compile('\s(' + '[0-9a-f]{2}:' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
c = re.compile(r'\s(' + '[0-9a-f]{2}:' * 5 + r'[0-9a-f]{2})(\s|$)', re.IGNORECASE)
output = subprocess.check_output('/sbin/ifconfig -a', shell=True, encoding='utf-8')
matches = c.findall(output)
for m in matches:
Expand All @@ -459,14 +459,14 @@ def __getmacaddrs (self):
else:
# final fallback
# let's try ip
c = re.compile('\s(' + '[0-9a-f]{2}:' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
c = re.compile(r'\s(' + '[0-9a-f]{2}:' * 5 + r'[0-9a-f]{2})(\s|$)', re.IGNORECASE)
for line in os.popen('ip -br link'):
m = c.search(line)
if m:
macaddrs.append(m.group(1).upper())

# let's try ipconfig under wine
c = re.compile('\s(' + '[0-9a-f]{2}-' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
c = re.compile(r'\s(' + '[0-9a-f]{2}-' * 5 + r'[0-9a-f]{2})(\s|$)', re.IGNORECASE)
for line in os.popen('ipconfig /all'):
m = c.search(line)
if m:
Expand Down Expand Up @@ -665,7 +665,7 @@ def decrypt_book(book, lib):
print("Converting {0}".format(book.title))
zin = zipfile.ZipFile(book.filename, "r")
# make filename out of Unicode alphanumeric and whitespace equivalents from title
outname = "{0}.epub".format(re.sub('[^\s\w]', '_', book.title, 0, re.UNICODE))
outname = "{0}.epub".format(re.sub(r'[^\s\w]', '_', book.title, 0, re.UNICODE))
if (book.type == 'drm-free'):
print("DRM-free book, conversion is not needed")
shutil.copyfile(book.filename, outname)
Expand Down
Loading