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
@ -88,15 +88,19 @@ class AddAction(InterfaceAction):
|
|||||||
for x in xrange(num):
|
for x in xrange(num):
|
||||||
self.gui.library_view.model().db.import_book(MetaInformation(None), [])
|
self.gui.library_view.model().db.import_book(MetaInformation(None), [])
|
||||||
self.gui.library_view.model().books_added(num)
|
self.gui.library_view.model().books_added(num)
|
||||||
|
|
||||||
def add_isbns(self, isbns):
|
def add_isbns(self, books):
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
ids = set([])
|
ids = set([])
|
||||||
for x in isbns:
|
for x in books:
|
||||||
mi = MetaInformation(None)
|
mi = MetaInformation(None)
|
||||||
mi.isbn = x
|
mi.isbn = x['isbn']
|
||||||
ids.add(self.gui.library_view.model().db.import_book(mi, []))
|
if x['path'] is not None:
|
||||||
self.gui.library_view.model().books_added(len(isbns))
|
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(books))
|
||||||
self.gui.iactions['Edit Metadata'].do_download_metadata(ids)
|
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
|
from calibre.gui2.dialogs.add_from_isbn import AddFromISBN
|
||||||
d = AddFromISBN(self.gui)
|
d = AddFromISBN(self.gui)
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
self.add_isbns(d.isbns)
|
self.add_isbns(d.books)
|
||||||
|
|
||||||
def add_books(self, *args):
|
def add_books(self, *args):
|
||||||
'''
|
'''
|
||||||
|
@ -5,10 +5,14 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from PyQt4.Qt import QDialog, QApplication
|
from PyQt4.Qt import QDialog, QApplication
|
||||||
|
|
||||||
from calibre.gui2.dialogs.add_from_isbn_ui import Ui_Dialog
|
from calibre.gui2.dialogs.add_from_isbn_ui import Ui_Dialog
|
||||||
from calibre.ebooks.metadata import check_isbn
|
from calibre.ebooks.metadata import check_isbn
|
||||||
|
from calibre.constants import iswindows
|
||||||
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
|
|
||||||
class AddFromISBN(QDialog, Ui_Dialog):
|
class AddFromISBN(QDialog, Ui_Dialog):
|
||||||
|
|
||||||
@ -16,7 +20,12 @@ class AddFromISBN(QDialog, Ui_Dialog):
|
|||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
self.setupUi(self)
|
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.isbns = []
|
||||||
|
self.books = []
|
||||||
self.paste_button.clicked.connect(self.paste)
|
self.paste_button.clicked.connect(self.paste)
|
||||||
|
|
||||||
def paste(self, *args):
|
def paste(self, *args):
|
||||||
@ -30,11 +39,27 @@ class AddFromISBN(QDialog, Ui_Dialog):
|
|||||||
|
|
||||||
def accept(self, *args):
|
def accept(self, *args):
|
||||||
for line in unicode(self.isbn_box.toPlainText()).strip().splitlines():
|
for line in unicode(self.isbn_box.toPlainText()).strip().splitlines():
|
||||||
if line:
|
line = line.strip()
|
||||||
isbn = check_isbn(line)
|
if not line:
|
||||||
if isbn is not None:
|
continue
|
||||||
isbn = isbn.upper()
|
parts = line.split('>>')
|
||||||
if isbn not in self.isbns:
|
if len(parts) > 2:
|
||||||
self.isbns.append(isbn)
|
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)
|
QDialog.accept(self, *args)
|
||||||
|
|
||||||
|
@ -24,7 +24,10 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<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>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user