mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Plugin to download series information form LibraryThing. Fixes #5148 (Libraything metadata download plugin)
This commit is contained in:
parent
09b679bb40
commit
d9994a25d9
@ -457,11 +457,12 @@ from calibre.devices.misc import PALMPRE, AVANT
|
||||
from calibre.devices.folder_device.driver import FOLDER_DEVICE_FOR_CONFIG
|
||||
from calibre.devices.kobo.driver import KOBO
|
||||
|
||||
from calibre.ebooks.metadata.fetch import GoogleBooks, ISBNDB, Amazon
|
||||
from calibre.ebooks.metadata.fetch import GoogleBooks, ISBNDB, Amazon, \
|
||||
LibraryThing
|
||||
from calibre.ebooks.metadata.douban import DoubanBooks
|
||||
from calibre.library.catalog import CSV_XML, EPUB_MOBI
|
||||
plugins = [HTML2ZIP, PML2PMLZ, ArchiveExtract, GoogleBooks, ISBNDB, Amazon,
|
||||
DoubanBooks, CSV_XML, EPUB_MOBI]
|
||||
LibraryThing, DoubanBooks, CSV_XML, EPUB_MOBI]
|
||||
plugins += [
|
||||
ComicInput,
|
||||
EPUBInput,
|
||||
|
@ -183,10 +183,7 @@ run_plugins_on_postprocess = functools.partial(_run_filetype_plugins,
|
||||
occasion='postprocess')
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
|
||||
# PLugin customization {{{
|
||||
# Plugin customization {{{
|
||||
def customize_plugin(plugin, custom):
|
||||
d = config['plugin_customization']
|
||||
d[plugin.name] = custom.strip()
|
||||
|
@ -198,6 +198,38 @@ class Amazon(MetadataSource):
|
||||
self.exception = e
|
||||
self.tb = traceback.format_exc()
|
||||
|
||||
class LibraryThing(MetadataSource):
|
||||
|
||||
name = 'LibraryThing'
|
||||
metadata_type = 'social'
|
||||
description = _('Downloads series information from librarything.com')
|
||||
|
||||
def fetch(self):
|
||||
if not self.isbn:
|
||||
return
|
||||
from calibre import browser
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
import json
|
||||
br = browser()
|
||||
try:
|
||||
raw = br.open(
|
||||
'http://status.calibre-ebook.com/library_thing/metadata/'+self.isbn
|
||||
).read()
|
||||
data = json.loads(raw)
|
||||
if not data:
|
||||
return
|
||||
if 'error' in data:
|
||||
raise Exception(data['error'])
|
||||
if 'series' in data and 'series_index' in data:
|
||||
mi = MetaInformation(self.title, [])
|
||||
mi.series = data['series']
|
||||
mi.series_index = data['series_index']
|
||||
self.results = mi
|
||||
except Exception, e:
|
||||
self.exception = e
|
||||
self.tb = traceback.format_exc()
|
||||
|
||||
|
||||
def result_index(source, result):
|
||||
if not result.isbn:
|
||||
return -1
|
||||
@ -266,7 +298,7 @@ def get_social_metadata(mi, verbose=0):
|
||||
with MetadataSources(fetchers) as manager:
|
||||
manager(mi.title, mi.authors, mi.publisher, mi.isbn, verbose)
|
||||
manager.join()
|
||||
ratings, tags, comments = [], set([]), set([])
|
||||
ratings, tags, comments, series, series_index = [], set([]), set([]), None, None
|
||||
for fetcher in fetchers:
|
||||
if fetcher.results:
|
||||
dmi = fetcher.results
|
||||
@ -279,6 +311,10 @@ def get_social_metadata(mi, verbose=0):
|
||||
mi.pubdate = dmi.pubdate
|
||||
if dmi.comments:
|
||||
comments.add(dmi.comments)
|
||||
if dmi.series is not None:
|
||||
series = dmi.series
|
||||
if dmi.series_index is not None:
|
||||
series_index = dmi.series_index
|
||||
if ratings:
|
||||
rating = sum(ratings)/float(len(ratings))
|
||||
if mi.rating is None or mi.rating < 0.1:
|
||||
@ -295,6 +331,9 @@ def get_social_metadata(mi, verbose=0):
|
||||
mi.comments = ''
|
||||
for x in comments:
|
||||
mi.comments += x+'\n\n'
|
||||
if series and series_index is not None:
|
||||
mi.series = series
|
||||
mi.series_index = series_index
|
||||
|
||||
return [(x.name, x.exception, x.tb) for x in fetchers if x.exception is not
|
||||
None]
|
||||
|
@ -49,6 +49,9 @@ class SocialMetadata(QDialog):
|
||||
self.mi.tags = self.worker.mi.tags
|
||||
self.mi.rating = self.worker.mi.rating
|
||||
self.mi.comments = self.worker.mi.comments
|
||||
if self.worker.mi.series:
|
||||
self.mi.series = self.worker.mi.series
|
||||
self.mi.series_index = self.worker.mi.series_index
|
||||
QDialog.accept(self)
|
||||
|
||||
@property
|
||||
|
@ -127,6 +127,10 @@ class DownloadMetadata(Thread):
|
||||
self.db.set_tags(id, mi.tags)
|
||||
if mi.comments:
|
||||
self.db.set_comment(id, mi.comments)
|
||||
if mi.series:
|
||||
self.db.set_series(id, mi.series)
|
||||
if mi.series_index is not None:
|
||||
self.db.set_series_index(id, mi.series_index)
|
||||
|
||||
self.updated = set(self.fetched_metadata)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user