mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add by ISBN: Allow adding using identifiers other than ISBN as well. Fixes #2003227 [enhancement request regarding add from isbn](https://bugs.launchpad.net/calibre/+bug/2003227)
This commit is contained in:
parent
bd0b511b81
commit
b67c5a2104
@ -371,14 +371,26 @@ class AddAction(InterfaceAction):
|
|||||||
existing_isbns.pop('', None)
|
existing_isbns.pop('', None)
|
||||||
ok = []
|
ok = []
|
||||||
duplicates = []
|
duplicates = []
|
||||||
|
checker_maps = {}
|
||||||
for book in books:
|
for book in books:
|
||||||
q = normalize_isbn(book['isbn'])
|
if 'isbn' in book:
|
||||||
if q and q in existing_isbns:
|
q = normalize_isbn(book['isbn'])
|
||||||
duplicates.append((book, existing_isbns[q]))
|
if q and q in existing_isbns:
|
||||||
|
duplicates.append((book, existing_isbns[q]))
|
||||||
|
else:
|
||||||
|
ok.append(book)
|
||||||
else:
|
else:
|
||||||
ok.append(book)
|
key = book['']
|
||||||
|
if key not in checker_maps:
|
||||||
|
checker_maps[key] = {ids.get(key, ''): book_id for book_id, ids in book_id_identifiers.items()}
|
||||||
|
checker_maps[key].pop('', None)
|
||||||
|
q = book[key]
|
||||||
|
if q in checker_maps[key]:
|
||||||
|
duplicates.append((book, checker_maps[key][q]))
|
||||||
|
else:
|
||||||
|
ok.append(book)
|
||||||
if duplicates:
|
if duplicates:
|
||||||
det_msg = '\n'.join(f'{book["isbn"]}: {db.field_for("title", book_id)}' for book, book_id in duplicates)
|
det_msg = '\n'.join(f'{book[book[""]]}: {db.field_for("title", book_id)}' for book, book_id in duplicates)
|
||||||
if question_dialog(self.gui, _('Duplicates found'), _(
|
if question_dialog(self.gui, _('Duplicates found'), _(
|
||||||
'Books with some of the specified ISBNs already exist in the calibre library.'
|
'Books with some of the specified ISBNs already exist in the calibre library.'
|
||||||
' Click "Show details" for the full list. Do you want to add them anyway?'), det_msg=det_msg
|
' Click "Show details" for the full list. Do you want to add them anyway?'), det_msg=det_msg
|
||||||
@ -416,7 +428,10 @@ class AddAction(InterfaceAction):
|
|||||||
return
|
return
|
||||||
|
|
||||||
mi = MetaInformation(None)
|
mi = MetaInformation(None)
|
||||||
mi.isbn = x['isbn']
|
if x[''] == 'isbn':
|
||||||
|
mi.isbn = x['isbn']
|
||||||
|
else:
|
||||||
|
mi.set_identifiers({x['']:x[x['']]})
|
||||||
if self.isbn_add_tags:
|
if self.isbn_add_tags:
|
||||||
mi.tags = list(self.isbn_add_tags)
|
mi.tags = list(self.isbn_add_tags)
|
||||||
fmts = [] if x['path'] is None else [x['path']]
|
fmts = [] if x['path'] is None else [x['path']]
|
||||||
|
@ -55,7 +55,11 @@ class AddFromISBN(QDialog):
|
|||||||
"<p>Any invalid ISBNs in the list will be ignored.</p>\n"
|
"<p>Any invalid ISBNs in the list will be ignored.</p>\n"
|
||||||
"<p>You can also specify a file that will be added with each ISBN. To do this enter the full"
|
"<p>You can also specify a file that will be added with each ISBN. To do this enter the full"
|
||||||
" path to the file after a <code>>></code>. For example:</p>\n"
|
" path to the file after a <code>>></code>. For example:</p>\n"
|
||||||
"<p><code>9788842915232 >> %s</code></p>"), self)
|
"<p><code>9788842915232 >> %s</code></p>"
|
||||||
|
"<p>To use identifiers other than ISBN use key:value syntax, For example:</p>\n"
|
||||||
|
"<p><code>amazon:B001JK9C72</code></p>"
|
||||||
|
), self)
|
||||||
|
|
||||||
l.addWidget(la), la.setWordWrap(True)
|
l.addWidget(la), la.setWordWrap(True)
|
||||||
l.addSpacing(20)
|
l.addSpacing(20)
|
||||||
self.la2 = la = QLabel(_("&Tags to set on created book entries:"), self)
|
self.la2 = la = QLabel(_("&Tags to set on created book entries:"), self)
|
||||||
@ -100,18 +104,26 @@ class AddFromISBN(QDialog):
|
|||||||
parts = [x.strip() for x in parts]
|
parts = [x.strip() for x in parts]
|
||||||
if not parts[0]:
|
if not parts[0]:
|
||||||
continue
|
continue
|
||||||
isbn = check_isbn(parts[0])
|
if ':' in parts[0]:
|
||||||
if isbn is not None:
|
prefix, val = parts[0].partition(':')[::2]
|
||||||
isbn = isbn.upper()
|
|
||||||
if isbn not in self.isbns:
|
|
||||||
self.isbns.append(isbn)
|
|
||||||
book = {'isbn': isbn, 'path': None}
|
|
||||||
if len(parts) > 1 and parts[1] and \
|
|
||||||
os.access(parts[1], os.R_OK) and os.path.isfile(parts[1]):
|
|
||||||
book['path'] = parts[1]
|
|
||||||
self.books.append(book)
|
|
||||||
else:
|
else:
|
||||||
bad.add(parts[0])
|
prefix, val = 'isbn', parts[0]
|
||||||
|
path = None
|
||||||
|
if len(parts) > 1 and parts[1] and os.access(parts[1], os.R_OK) and os.path.isfile(parts[1]):
|
||||||
|
path = parts[1]
|
||||||
|
|
||||||
|
if prefix == 'isbn':
|
||||||
|
isbn = check_isbn(parts[0])
|
||||||
|
if isbn is not None:
|
||||||
|
isbn = isbn.upper()
|
||||||
|
if isbn not in self.isbns:
|
||||||
|
self.isbns.append(isbn)
|
||||||
|
self.books.append({'isbn': isbn, 'path': path, '': 'isbn'})
|
||||||
|
else:
|
||||||
|
bad.add(parts[0])
|
||||||
|
else:
|
||||||
|
if prefix != 'path':
|
||||||
|
self.books.append({prefix: val, 'path': path, '':prefix})
|
||||||
if bad:
|
if bad:
|
||||||
if self.books:
|
if self.books:
|
||||||
if not question_dialog(self, _('Some invalid ISBNs'),
|
if not question_dialog(self, _('Some invalid ISBNs'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user