mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fetch book summary alongwith the rest of the metadata
This commit is contained in:
parent
f5e86cc2a8
commit
27a2b7e61d
@ -23,7 +23,7 @@ from libprs500 import setup_cli_handlers, OptionParser
|
|||||||
from libprs500.ebooks.metadata import MetaInformation
|
from libprs500.ebooks.metadata import MetaInformation
|
||||||
from libprs500.ebooks.BeautifulSoup import BeautifulStoneSoup
|
from libprs500.ebooks.BeautifulSoup import BeautifulStoneSoup
|
||||||
|
|
||||||
BASE_URL = 'http://isbndb.com/api/books.xml?access_key=%(key)s&page_number=1&results=subjects,authors&'
|
BASE_URL = 'http://isbndb.com/api/books.xml?access_key=%(key)s&page_number=1&results=subjects,authors,texts&'
|
||||||
|
|
||||||
class ISBNDBError(Exception):
|
class ISBNDBError(Exception):
|
||||||
pass
|
pass
|
||||||
@ -56,6 +56,7 @@ def fetch_metadata(url, max=100, timeout=5.):
|
|||||||
|
|
||||||
|
|
||||||
class ISBNDBMetadata(MetaInformation):
|
class ISBNDBMetadata(MetaInformation):
|
||||||
|
|
||||||
def __init__(self, book):
|
def __init__(self, book):
|
||||||
MetaInformation.__init__(self, None, [])
|
MetaInformation.__init__(self, None, [])
|
||||||
|
|
||||||
@ -77,6 +78,11 @@ class ISBNDBMetadata(MetaInformation):
|
|||||||
pass
|
pass
|
||||||
self.publisher = book.find('publishertext').string
|
self.publisher = book.find('publishertext').string
|
||||||
|
|
||||||
|
summ = book.find('summary')
|
||||||
|
if summ and hasattr(summ, 'string') and summ.string:
|
||||||
|
self.comments = 'SUMMARY:\n'+summ.string
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_isbn(base_url, opts):
|
def build_isbn(base_url, opts):
|
||||||
return base_url + 'index1=isbn&value1='+opts.isbn
|
return base_url + 'index1=isbn&value1='+opts.isbn
|
||||||
|
@ -30,6 +30,7 @@ class Matches(QAbstractTableModel):
|
|||||||
|
|
||||||
def __init__(self, matches):
|
def __init__(self, matches):
|
||||||
self.matches = matches
|
self.matches = matches
|
||||||
|
self.matches.sort(cmp=lambda b, a: cmp(len(a.comments if a.comments else ''), len(b.comments if b.comments else '')))
|
||||||
QAbstractTableModel.__init__(self)
|
QAbstractTableModel.__init__(self)
|
||||||
|
|
||||||
def rowCount(self, *args):
|
def rowCount(self, *args):
|
||||||
@ -53,6 +54,9 @@ class Matches(QAbstractTableModel):
|
|||||||
else:
|
else:
|
||||||
return QVariant(section+1)
|
return QVariant(section+1)
|
||||||
|
|
||||||
|
def summary(self, row):
|
||||||
|
return self.matches[row].comments
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
row, col = index.row(), index.column()
|
row, col = index.row(), index.column()
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
@ -91,6 +95,16 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
self.title = title
|
self.title = title
|
||||||
self.author = author.strip()
|
self.author = author.strip()
|
||||||
self.publisher = publisher
|
self.publisher = publisher
|
||||||
|
self.previous_row = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def show_summary(self, current, previous):
|
||||||
|
row = current.row()
|
||||||
|
if row != self.previous_row:
|
||||||
|
summ = self.model.summary(row)
|
||||||
|
self.summary.setText(summ if summ else '')
|
||||||
|
self.previous_row = row
|
||||||
|
|
||||||
def fetch_metadata(self):
|
def fetch_metadata(self):
|
||||||
key = str(self.key.text())
|
key = str(self.key.text())
|
||||||
@ -132,6 +146,8 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
self.model = Matches(books)
|
self.model = Matches(books)
|
||||||
|
|
||||||
self.matches.setModel(self.model)
|
self.matches.setModel(self.model)
|
||||||
|
QObject.connect(self.matches.selectionModel(), SIGNAL('currentRowChanged(QModelIndex, QModelIndex)'),
|
||||||
|
self.show_summary)
|
||||||
self.model.reset()
|
self.model.reset()
|
||||||
self.matches.selectionModel().select(self.model.index(0, 0),
|
self.matches.selectionModel().select(self.model.index(0, 0),
|
||||||
QItemSelectionModel.Select | QItemSelectionModel.Rows)
|
QItemSelectionModel.Select | QItemSelectionModel.Rows)
|
||||||
@ -139,6 +155,7 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
self.fetch.setEnabled(True)
|
self.fetch.setEnabled(True)
|
||||||
self.unsetCursor()
|
self.unsetCursor()
|
||||||
self.matches.resizeColumnsToContents()
|
self.matches.resizeColumnsToContents()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def selected_book(self):
|
def selected_book(self):
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>830</width>
|
<width>830</width>
|
||||||
<height>622</height>
|
<height>700</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle" >
|
||||||
@ -81,6 +81,12 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="matches" >
|
<widget class="QTableView" name="matches" >
|
||||||
|
<property name="sizePolicy" >
|
||||||
|
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>1</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="alternatingRowColors" >
|
<property name="alternatingRowColors" >
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -92,6 +98,9 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="summary" />
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -287,6 +287,12 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
|||||||
if book.author_sort: self.author_sort.setText(book.author_sort)
|
if book.author_sort: self.author_sort.setText(book.author_sort)
|
||||||
self.publisher.setText(book.publisher)
|
self.publisher.setText(book.publisher)
|
||||||
self.isbn.setText(book.isbn)
|
self.isbn.setText(book.isbn)
|
||||||
|
summ = book.comments
|
||||||
|
if summ:
|
||||||
|
prefix = qstring_to_unicode(self.comments.text())
|
||||||
|
if prefix:
|
||||||
|
prefix += '\n'
|
||||||
|
self.comments.setText(prefix + summ)
|
||||||
else:
|
else:
|
||||||
error_dialog(self, 'Cannot fetch metadata', 'You must specify at least one of ISBN, Title, Authors or Publisher')
|
error_dialog(self, 'Cannot fetch metadata', 'You must specify at least one of ISBN, Title, Authors or Publisher')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user