Skip to content

Commit 392f2c6

Browse files
committed
Updated to work with new versions of calibre
1 parent dd2c9b4 commit 392f2c6

10 files changed

+1003
-3
lines changed

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ This is a fork of kiwidude's "Find Duplicates" plugin that allows for merging du
44

55
Merging duplicates can be dangerous, you can lose metadata or versions of a book if you aren't careful. You must use this plugin with care. Take note of the GPL-3 license included: there is no warranty, nothing is guaranteed.
66

7-
kiwidude did the bulk of the work that makes this possible. You should thank them for their hard work, and take a look at their repository of other really useful calibre plugins. Developers, kiwidude also has a lot of really interesting information about learning to develop your own calibre plugins! https://github.com/kiwidude68/calibre_plugins
7+
kiwidude did the bulk of the work that makes this possible. You should thank them for their hard work, and take a look at their repository of other really useful Calibre plugins. Developers, kiwidude also has a lot of really interesting information about learning to develop your own Calibre plugins! https://github.com/kiwidude68/calibre_plugins
88

99
More information on how this was developed can be found at my blog post. If you're interested in learning how to contribute to an open source project but think you can't because you don't know enough, I recommend reading it! It's more possible than you think: https://blog.calebjay.com/posts/calibre-automerge/
10+
11+
# Usage
12+
13+
To install this plugin, follow the Calibre instructions: https://manual.calibre-ebook.com/creating_plugins.html . In short:
14+
15+
1. Back up your library. Merging duplicates is *a file destructive action.* You risk *losing your actual ebook files*.
16+
2. Download this repo
17+
3. Open a terminal at the root of this folder (the same directory as this README)
18+
4. Run `calibre-customize -b .`
19+
5. Open Calibre
20+
6. Under Preferences > Plugins > User interface action, click "Find Duplicates Merge Fork"
21+
7. Click "customize plugin." A window should pop up with options such as "Keyboard shortcuts..." If not, something broke, and you should try to debug this or email me (this project is low priority for me, your best chance of fixing it is by yourself).
22+
8. If step 6 worked, then, close the Preferences window, then open Preferences > Toolbars & menu.
23+
9. Click "the main toolbar" in the dropdown
24+
10. Using the tool, add "Find Duplicates" to the "Current Actions" box on the right. Click "apply" afterwards.
25+
11. A "Find Duplicates" button should now be on your toolbar. Click it, or click the dropdown indicator next to it to customize your duplicate find search.
26+
12. A list of "groups" of duplicates should be displayed, if your search was configured correctly. If not, try looking for instructions on kiwidude's repo, linked above. Remember, the bulk of why this works at all is thanks to their work. A "group" is a list of entries in Calibre's database that, hopefully, all refer to the "same book." Each of these entries may refer to multiple actual files, of various formats. This is important, because if for example two entries have a `pdf` format, *only the pdf of the first entry will exist after merging!* This is the built in way that the Calibre merge tool works.
27+
13. Also note that when merging, books will be merged into the *first* entry in a given group. I'm not sure how to change this functionality, or what ways there are of changing which entry is considered the "first" entry - for example, simply sorting on different columns may not actually change which entry is considered the "first" entry. This is why it's very important you back up your library! Your results may be unexpected and disastrous.
28+
14. A final note, the merge function uses the `merge_only_formats` flag of Calibre's merge tool. That means that no metadata will be copied from one entry in a group to another, the only thing that will be merged are *formats*. So if there are two entries, one having a pdf format, and another having an epub format, these will be merged into one entry with a pdf and epub format. The remaining metadata will be whatever the metadata was for the first entry. If you want to change this behavior, you'll need to modify the flags on line `452` in `duplicates.py` in this repo.
29+
15. When you're ready, click the "Find Duplicates" icon dropdown, and select "Merge All Groups."
30+
16. From here, follow the Calibre merge tool's prompts, which are not a part of this repo or kiwidude's work, these are built-in Calibre tools.

__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
__license__ = 'GPL v3'
44
__copyright__ = '2011, Grant Drake'
5+
__copyright__ = '2021, Caleb Rogers'
56

67
# The class that all Interface Action plugin wrappers must inherit from
78
from calibre.customize import InterfaceActionBase
@@ -16,10 +17,10 @@ class ActionFindDuplicates(InterfaceActionBase):
1617
The reason for having two classes is that it allows the command line
1718
calibre utilities to run without needing to load the GUI libraries.
1819
'''
19-
name = 'Find Duplicates'
20+
name = 'Find Duplicates Merge Fork'
2021
description = 'Find possible duplicate books based on their metadata'
2122
supported_platforms = ['windows', 'osx', 'linux']
22-
author = 'Grant Drake'
23+
author = 'Grant Drake, Caleb Rogers'
2324
version = (1, 10, 7)
2425
minimum_calibre_version = (2, 0, 0)
2526

action.py

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
__license__ = 'GPL v3'
44
__copyright__ = '2011, Grant Drake'
5+
__copyright__ = '2021, Caleb Rogers'
56

67
from functools import partial
78

@@ -135,12 +136,17 @@ def rebuild_menus(self):
135136
_('&Export duplicate groups'),
136137
tooltip=_('Export duplicates groups to a json file'),
137138
triggered=self.export_duplicates)
139+
self.merge_all_groups_action = create_menu_action_unique(self, m,
140+
_('&Merge all groups'),
141+
tooltip=_('Merge all the groups, showing confirmation box for each group. Back up your library first.'),
142+
triggered=partial(self.merge_all_groups))
138143
m.addSeparator()
139144

140145
create_menu_action_unique(self, m, _('&Customize plugin')+'...', 'config.png',
141146
shortcut=False, triggered=self.show_configuration)
142147
create_menu_action_unique(self, m, _('&Help'), 'help.png',
143148
shortcut=False, triggered=self.show_help)
149+
144150
self.gui.keyboard.finalize()
145151

146152
def about_to_show_menu(self):
@@ -167,6 +173,7 @@ def update_actions_enabled(self):
167173
self.previous_group_action.setEnabled(has_results)
168174
self.mark_group_exempt_action.setEnabled(has_results)
169175
self.mark_all_groups_exempt_action.setEnabled(has_results)
176+
self.merge_all_groups_action.setEnabled(has_results)
170177
is_showing_exemptions = self.duplicate_finder.is_showing_duplicate_exemptions()
171178
self.clear_duplicate_mode_action.setEnabled(has_results or is_showing_exemptions or self.has_advanced_results)
172179
self.export_duplicates_action.setEnabled(has_results)
@@ -265,6 +272,10 @@ def show_all_exemptions(self, for_books=True):
265272
self.duplicate_finder.show_all_exemptions(for_books)
266273
self.update_actions_enabled()
267274

275+
def merge_all_groups(self):
276+
self.duplicate_finder.merge_all_groups()
277+
self.update_actions_enabled()
278+
268279
def manage_exemptions_for_book(self):
269280
row = self.gui.library_view.currentIndex()
270281
if not row.isValid():

common_compatibility.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
3+
from __future__ import (unicode_literals, division, absolute_import,
4+
print_function)
5+
6+
__license__ = 'GPL v3'
7+
__copyright__ = '2022, Grant Drake'
8+
9+
# Maintain backwards compatibility with older versions of Qt and calibre.
10+
try:
11+
from qt.core import QSizePolicy, QTextEdit, Qt
12+
except ImportError:
13+
from PyQt5.Qt import QSizePolicy, QTextEdit, Qt
14+
15+
try:
16+
qSizePolicy_Minimum = QSizePolicy.Policy.Minimum
17+
qSizePolicy_Maximum = QSizePolicy.Policy.Maximum
18+
qSizePolicy_Expanding = QSizePolicy.Policy.Expanding
19+
qSizePolicy_Preferred = QSizePolicy.Policy.Preferred
20+
qSizePolicy_Ignored = QSizePolicy.Policy.Ignored
21+
except:
22+
qSizePolicy_Minimum = QSizePolicy.Minimum
23+
qSizePolicy_Maximum = QSizePolicy.Maximum
24+
qSizePolicy_Expanding = QSizePolicy.Expanding
25+
qSizePolicy_Preferred = QSizePolicy.Preferred
26+
qSizePolicy_Ignored = QSizePolicy.Ignored
27+
28+
try:
29+
qTextEdit_NoWrap = QTextEdit.LineWrapMode.NoWrap
30+
except:
31+
qTextEdit_NoWrap = QTextEdit.NoWrap
32+
33+
try:
34+
qtDropActionCopyAction = Qt.DropAction.CopyAction
35+
qtDropActionMoveAction = Qt.DropAction.MoveAction
36+
except:
37+
qtDropActionCopyAction = Qt.CopyAction
38+
qtDropActionMoveAction = Qt.MoveAction

0 commit comments

Comments
 (0)