This commit is contained in:
Kovid Goyal 2011-03-24 09:54:36 -06:00
parent d06dc22ac1
commit aa3ce26ff8
3 changed files with 23 additions and 1 deletions

View File

@ -172,6 +172,8 @@ class Worker(Thread): # {{{
self.plugin.cache_identifier_to_cover_url(self.amazon_id, self.plugin.cache_identifier_to_cover_url(self.amazon_id,
self.cover_url) self.cover_url)
self.plugin.clean_downloaded_metadata(mi)
self.result_queue.put(mi) self.result_queue.put(mi)
def parse_asin(self, root): def parse_asin(self, root):

View File

@ -13,6 +13,7 @@ from calibre import browser, random_user_agent
from calibre.customize import Plugin from calibre.customize import Plugin
from calibre.utils.logging import ThreadSafeLog, FileStream from calibre.utils.logging import ThreadSafeLog, FileStream
from calibre.utils.config import JSONConfig from calibre.utils.config import JSONConfig
from calibre.utils.titlecase import titlecase
msprefs = JSONConfig('metadata_sources.json') msprefs = JSONConfig('metadata_sources.json')
@ -128,7 +129,7 @@ class Source(Plugin):
# }}} # }}}
# Utility functions {{{ # Caching {{{
def get_related_isbns(self, id_): def get_related_isbns(self, id_):
with self.cache_lock: with self.cache_lock:
@ -152,6 +153,10 @@ class Source(Plugin):
with self.cache_lock: with self.cache_lock:
return self._identifier_to_cover_url_cache.get(id_, None) return self._identifier_to_cover_url_cache.get(id_, None)
# }}}
# Utility functions {{{
def get_author_tokens(self, authors, only_first_author=True): def get_author_tokens(self, authors, only_first_author=True):
''' '''
Take a list of authors and return a list of tokens useful for an Take a list of authors and return a list of tokens useful for an
@ -216,6 +221,20 @@ class Source(Plugin):
elif mi.is_null(key): elif mi.is_null(key):
return key return key
def clean_downloaded_metadata(self, mi):
'''
Call this method in your plugin's identify method to normalize metadata
before putting the Metadata object into result_queue. You can of
course, use a custom algorithm suited to your metadata source.
'''
def fixcase(x):
if x:
x = titlecase(x)
return x
if mi.title:
mi.title = fixcase(mi.title)
mi.authors = list(map(fixcase, mi.authors))
mi.tags = list(map(fixcase, mi.tags))
# }}} # }}}

View File

@ -256,6 +256,7 @@ class GoogleBooks(Source):
if ans.has_google_cover: if ans.has_google_cover:
self.cache_identifier_to_cover_url(goog, self.cache_identifier_to_cover_url(goog,
self.GOOGLE_COVER%goog) self.GOOGLE_COVER%goog)
self.clean_downloaded_metadata(ans)
result_queue.put(ans) result_queue.put(ans)
except: except:
log.exception( log.exception(