Skip to content

Commit

Permalink
Extract ISBN - better metadata update approach
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwidude68 committed Sep 9, 2024
1 parent 155ff43 commit ace1917
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
4 changes: 4 additions & 0 deletions extract_isbn/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Extract ISBN Change Log

## [1.6.5] - 2024-09-09
### Changed
- Implement an alternative approach to updating the ISBN metadata for books.

## [1.6.4] - 2024-09-05
### Added
- French translation
Expand Down
2 changes: 1 addition & 1 deletion extract_isbn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActionExtractISBN(InterfaceActionBase):
description = 'Extracts the ISBN from the text content of a book format if available'
supported_platforms = ['windows', 'osx', 'linux']
author = 'Grant Drake'
version = (1, 6, 4)
version = (1, 6, 5)
minimum_calibre_version = (2, 0, 0)

#: This field defines the GUI plugin class that contains all the code
Expand Down
28 changes: 18 additions & 10 deletions extract_isbn/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,25 @@ def _check_proceed_with_extracted_isbns(self, payload):
'Click "Show details" to see the list of changed books. '
'Do you want to proceed?'), det_msg='\n'.join(modified)):
return
# At this point we want to re-use code in edit_metadata to go ahead and
# apply the changes. So we will replace the Metadata objects with some
# empty ones with only the isbn field set so only that field gets updated
id_map = {}
# Apply the changes (thanks @chaley!)
ndb = db.new_api
book_to_id_map = {}
applied_ids = []
for i, title, last_modified, isbn in extracted_ids:
mi = Metadata(_('Unknown'))
mi.isbn = isbn
id_map[i] = mi
edit_metadata_action = self.gui.iactions['Edit Metadata']
edit_metadata_action.apply_metadata_changes(id_map,
callback=self._mark_and_display_results)
# Get the existing identifiers for the book
identifiers_for_book = ndb.field_for('identifiers', i)
if 'isbn' in identifiers_for_book:
prev_value = identifiers_for_book['isbn']
if prev_value == isbn:
continue
# Add/replace the ISBN identifer
identifiers_for_book['isbn'] = isbn
# Save the updated list of identifiers
book_to_id_map[i] = identifiers_for_book
applied_ids.append(i)
# Set all the books' identifier values
ndb.set_field('identifiers', book_to_id_map)
self._mark_and_display_results(applied_ids)

def _mark_and_display_results(self, applied_ids):
marked_ids = {}
Expand Down

0 comments on commit ace1917

Please sign in to comment.