mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #7400 (Mass importing by ISBN)
This commit is contained in:
parent
c996a001a7
commit
8fc411ade6
@ -89,14 +89,18 @@ class AddAction(InterfaceAction):
|
||||
self.gui.library_view.model().db.import_book(MetaInformation(None), [])
|
||||
self.gui.library_view.model().books_added(num)
|
||||
|
||||
def add_isbns(self, isbns):
|
||||
def add_isbns(self, books):
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
ids = set([])
|
||||
for x in isbns:
|
||||
for x in books:
|
||||
mi = MetaInformation(None)
|
||||
mi.isbn = x
|
||||
mi.isbn = x['isbn']
|
||||
if x['path'] is not None:
|
||||
ids.add(self.gui.library_view.model().db.import_book(mi, [x['path']]))
|
||||
os.remove(x['path'])
|
||||
else:
|
||||
ids.add(self.gui.library_view.model().db.import_book(mi, []))
|
||||
self.gui.library_view.model().books_added(len(isbns))
|
||||
self.gui.library_view.model().books_added(len(books))
|
||||
self.gui.iactions['Edit Metadata'].do_download_metadata(ids)
|
||||
|
||||
|
||||
@ -150,7 +154,7 @@ class AddAction(InterfaceAction):
|
||||
from calibre.gui2.dialogs.add_from_isbn import AddFromISBN
|
||||
d = AddFromISBN(self.gui)
|
||||
if d.exec_() == d.Accepted:
|
||||
self.add_isbns(d.isbns)
|
||||
self.add_isbns(d.books)
|
||||
|
||||
def add_books(self, *args):
|
||||
'''
|
||||
|
@ -5,10 +5,14 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os
|
||||
|
||||
from PyQt4.Qt import QDialog, QApplication
|
||||
|
||||
from calibre.gui2.dialogs.add_from_isbn_ui import Ui_Dialog
|
||||
from calibre.ebooks.metadata import check_isbn
|
||||
from calibre.constants import iswindows
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
|
||||
class AddFromISBN(QDialog, Ui_Dialog):
|
||||
|
||||
@ -16,7 +20,12 @@ class AddFromISBN(QDialog, Ui_Dialog):
|
||||
QDialog.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
|
||||
path = r'C:\Users\kovid\e-books\some_book.epub' if iswindows else \
|
||||
'/Users/kovid/e-books/some_book.epub'
|
||||
self.label.setText(unicode(self.label.text())%path)
|
||||
|
||||
self.isbns = []
|
||||
self.books = []
|
||||
self.paste_button.clicked.connect(self.paste)
|
||||
|
||||
def paste(self, *args):
|
||||
@ -30,11 +39,27 @@ class AddFromISBN(QDialog, Ui_Dialog):
|
||||
|
||||
def accept(self, *args):
|
||||
for line in unicode(self.isbn_box.toPlainText()).strip().splitlines():
|
||||
if line:
|
||||
isbn = check_isbn(line)
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
parts = line.split('>>')
|
||||
if len(parts) > 2:
|
||||
parts = [parts[0] + '>>'.join(parts[1:])]
|
||||
parts = [x.strip() for x in parts]
|
||||
if not parts[0]:
|
||||
continue
|
||||
isbn = check_isbn(parts[0])
|
||||
if isbn is not None:
|
||||
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]):
|
||||
pt = PersistentTemporaryFile(os.path.splitext(parts[1])[1])
|
||||
pt.write(open(parts[1], 'rb').read())
|
||||
pt.close()
|
||||
book['path'] = pt.name
|
||||
self.books.append(book)
|
||||
QDialog.accept(self, *args)
|
||||
|
||||
|
@ -24,7 +24,10 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><p>Enter a list of ISBNs in the box to the left, one per line. calibre will automatically create entries for books based on the ISBN and download metadata and covers for them.<p>Any invalid ISBNs in the list will be ignored.</string>
|
||||
<string><p>Enter a list of ISBNs in the box to the left, one per line. calibre will automatically create entries for books based on the ISBN and download metadata and covers for them.</p>
|
||||
<p>Any invalid ISBNs in the list will be ignored.</p>
|
||||
<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>
|
||||
<p><code>9788842915232 >> %s</code></p></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
|
Loading…
x
Reference in New Issue
Block a user