mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Add option to download only social metadata. Fixes #4015 (Option to Update Only Parts of Metadata)
This commit is contained in:
parent
2c65a90878
commit
6cbede48fb
@ -191,7 +191,7 @@ def get_social_metadata(mi, verbose=0):
|
|||||||
comments.add(dmi.comments)
|
comments.add(dmi.comments)
|
||||||
if ratings:
|
if ratings:
|
||||||
rating = sum(ratings)/float(len(ratings))
|
rating = sum(ratings)/float(len(ratings))
|
||||||
if mi.rating is None or mi.rating == 0:
|
if mi.rating is None or mi.rating < 0.1:
|
||||||
mi.rating = rating
|
mi.rating = rating
|
||||||
else:
|
else:
|
||||||
mi.rating = (mi.rating + rating)/2.0
|
mi.rating = (mi.rating + rating)/2.0
|
||||||
|
@ -246,6 +246,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
md.addAction(_('Download metadata and covers'))
|
md.addAction(_('Download metadata and covers'))
|
||||||
md.addAction(_('Download only metadata'))
|
md.addAction(_('Download only metadata'))
|
||||||
md.addAction(_('Download only covers'))
|
md.addAction(_('Download only covers'))
|
||||||
|
md.addAction(_('Download only social metadata'))
|
||||||
self.metadata_menu = md
|
self.metadata_menu = md
|
||||||
self.add_menu = QMenu()
|
self.add_menu = QMenu()
|
||||||
self.add_menu.addAction(_('Add books from a single directory'))
|
self.add_menu.addAction(_('Add books from a single directory'))
|
||||||
@ -288,7 +289,10 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
set_metadata=False)
|
set_metadata=False)
|
||||||
QObject.connect(md.actions()[6], SIGNAL('triggered(bool)'),
|
QObject.connect(md.actions()[6], SIGNAL('triggered(bool)'),
|
||||||
self.__em5__)
|
self.__em5__)
|
||||||
|
self.__em6__ = partial(self.download_metadata, covers=False,
|
||||||
|
set_metadata=False, set_social_metadata=True)
|
||||||
|
QObject.connect(md.actions()[7], SIGNAL('triggered(bool)'),
|
||||||
|
self.__em6__)
|
||||||
|
|
||||||
|
|
||||||
self.save_menu = QMenu()
|
self.save_menu = QMenu()
|
||||||
@ -1027,7 +1031,8 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
|
|
||||||
############################### Edit metadata ##############################
|
############################### Edit metadata ##############################
|
||||||
|
|
||||||
def download_metadata(self, checked, covers=True, set_metadata=True):
|
def download_metadata(self, checked, covers=True, set_metadata=True,
|
||||||
|
set_social_metadata=None):
|
||||||
rows = self.library_view.selectionModel().selectedRows()
|
rows = self.library_view.selectionModel().selectedRows()
|
||||||
previous = self.library_view.currentIndex()
|
previous = self.library_view.currentIndex()
|
||||||
if not rows or len(rows) == 0:
|
if not rows or len(rows) == 0:
|
||||||
@ -1037,12 +1042,19 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
return
|
return
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
ids = [db.id(row.row()) for row in rows]
|
ids = [db.id(row.row()) for row in rows]
|
||||||
|
if set_social_metadata is None:
|
||||||
|
get_social_metadata = config['get_social_metadata']
|
||||||
|
else:
|
||||||
|
get_social_metadata = set_social_metadata
|
||||||
from calibre.gui2.metadata import DownloadMetadata
|
from calibre.gui2.metadata import DownloadMetadata
|
||||||
self._download_book_metadata = DownloadMetadata(db, ids,
|
self._download_book_metadata = DownloadMetadata(db, ids,
|
||||||
get_covers=covers, set_metadata=set_metadata,
|
get_covers=covers, set_metadata=set_metadata,
|
||||||
get_social_metadata=config['get_social_metadata'])
|
get_social_metadata=get_social_metadata)
|
||||||
self._download_book_metadata.start()
|
self._download_book_metadata.start()
|
||||||
x = _('covers') if covers and not set_metadata else _('metadata')
|
if set_social_metadata is not None and set_social_metadata:
|
||||||
|
x = _('social metadata')
|
||||||
|
else:
|
||||||
|
x = _('covers') if covers and not set_metadata else _('metadata')
|
||||||
self.progress_indicator.start(
|
self.progress_indicator.start(
|
||||||
_('Downloading %s for %d book(s)')%(x, len(ids)))
|
_('Downloading %s for %d book(s)')%(x, len(ids)))
|
||||||
self._book_metadata_download_check = QTimer(self)
|
self._book_metadata_download_check = QTimer(self)
|
||||||
|
@ -60,6 +60,7 @@ class DownloadMetadata(Thread):
|
|||||||
self.worker = Worker()
|
self.worker = Worker()
|
||||||
for id in ids:
|
for id in ids:
|
||||||
self.metadata[id] = db.get_metadata(id, index_is_id=True)
|
self.metadata[id] = db.get_metadata(id, index_is_id=True)
|
||||||
|
self.metadata[id].rating = None
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.exception = self.tb = None
|
self.exception = self.tb = None
|
||||||
@ -100,6 +101,8 @@ class DownloadMetadata(Thread):
|
|||||||
mi.smart_update(fmi)
|
mi.smart_update(fmi)
|
||||||
if mi.isbn and self.get_social_metadata:
|
if mi.isbn and self.get_social_metadata:
|
||||||
self.social_metadata_exceptions = get_social_metadata(mi)
|
self.social_metadata_exceptions = get_social_metadata(mi)
|
||||||
|
if mi.rating:
|
||||||
|
mi.rating *= 2
|
||||||
if not self.get_social_metadata:
|
if not self.get_social_metadata:
|
||||||
mi.tags = []
|
mi.tags = []
|
||||||
else:
|
else:
|
||||||
@ -111,6 +114,15 @@ class DownloadMetadata(Thread):
|
|||||||
if self.set_metadata:
|
if self.set_metadata:
|
||||||
for id in self.fetched_metadata:
|
for id in self.fetched_metadata:
|
||||||
self.db.set_metadata(id, self.metadata[id])
|
self.db.set_metadata(id, self.metadata[id])
|
||||||
|
if not self.set_metadata and self.get_social_metadata:
|
||||||
|
mi = self.metadata[id]
|
||||||
|
if mi.rating:
|
||||||
|
self.db.set_rating(id, mi.rating)
|
||||||
|
if mi.tags:
|
||||||
|
self.db.set_tags(id, mi.tags)
|
||||||
|
if mi.comments:
|
||||||
|
self.db.set_comment(id, mi.comments)
|
||||||
|
|
||||||
self.updated = set(self.fetched_metadata)
|
self.updated = set(self.fetched_metadata)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user