Skip to content

Commit

Permalink
add option to adjust azw3 offset
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed Nov 12, 2020
1 parent 734f7cf commit eb1cdfc
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Please read [CONTRIBUTING](./docs/CONTRIBUTING.md)

Install calibre 5.

Add the plugin to "The context menu for the books in the calibre library" in "Preferences" -> "Toolbars & menus". Right click a MOBI format book then click the plugin menu, it will start generating Word Wise file in a few minutes depends on the book size and your computer speed.
Add the plugin to "The context menu for the books in the calibre library" in "Preferences" -> "Toolbars & menus". Right click a MOBI or AZW3 format book then click the plugin menu, it will start generating Word Wise file in a few minutes that depends on the book size and your computer speed.

If your Kindle device is connected, it will send the file to your device.

You can try it on azw3 books but may not work. If you know how to deal with azw3 or kfx books please help.
For AZW3 books you may have to adjust the offset manually. For example, if you find the word is 16 characters(include white space) behind where it should be, set -16 in the plugin settings.

## License

Expand Down
12 changes: 11 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ class WordDumbDumb(InterfaceActionBase):
description = 'Create Kindle Word Wise file.'
supported_platforms = ['linux', 'osx', 'windows']
author = 'xxyzz'
version = (1, 1, 0)
version = (1, 2, 0)
minimum_calibre_version = (5, 0, 0) # Python3
actual_plugin = 'calibre_plugins.worddumb.ui:WordDumb'

def is_customizable(self):
return True

def config_widget(self):
from calibre_plugins.worddumb.config import ConfigWidget
return ConfigWidget()

def save_settings(self, config_widget):
config_widget.save_settings()
43 changes: 43 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

from calibre.utils.config import JSONConfig
from PyQt5.Qt import QWidget, QHBoxLayout, QLabel, QLineEdit, QPushButton, QVBoxLayout
import webbrowser

prefs = JSONConfig('plugins/worddumb')

prefs.defaults['offset'] = '0'

class ConfigWidget(QWidget):
def __init__(self):
QWidget.__init__(self)

self.vl = QVBoxLayout()
self.setLayout(self.vl)
self.hl = QHBoxLayout()
self.vl.addLayout(self.hl)

self.label = QLabel('Offset:')
self.hl.addWidget(self.label)

self.offset = QLineEdit(self)
self.offset.setText(prefs['offset'])
self.hl.addWidget(self.offset)
self.label.setBuddy(self.offset)

self.donate_button = QPushButton('Donate', self)
self.donate_button.clicked.connect(self.donate)
self.vl.addWidget(self.donate_button)

self.github_button = QPushButton('Source code', self)
self.github_button.clicked.connect(self.github)
self.vl.addWidget(self.github_button)

def save_settings(self):
prefs['offset'] = self.offset.text()

def donate(self):
webbrowser.open('https://liberapay.com/xxyzz/donate')

def github(self):
webbrowser.open('https://github.com/xxyzz/WordDumb')
4 changes: 2 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ $ create_ww_sql.py ./path-of-klld ./path-of-kll

- Add GitHub action to test the code

- Supports azw3 and kfx

- Improve performance, especially matching lemmas part

- Lemmatize words

- Supports kfx
4 changes: 3 additions & 1 deletion parse_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from calibre.utils.logging import default_log
from calibre_plugins.worddumb.database import connect_ww_database, \
create_lang_layer, match_word
from calibre_plugins.worddumb.config import prefs
from pathlib import Path
import re

Expand Down Expand Up @@ -41,5 +42,6 @@ def parse_book(pathtoebook, book_fmt):
lemma = text[match_word.start():match_word.end()]
start = match_text.start() + match_word.start()
if book_fmt.lower() == 'azw3':
start -= 14 # I have no idea, may not work
start -= 14 # this value works for some books of mine
start += int(prefs['offset'])
yield (start, lemma.decode('utf-8'))

0 comments on commit eb1cdfc

Please sign in to comment.