mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Fix author name casing algorithm
This commit is contained in:
parent
62b1ae9176
commit
6059a77d86
@ -15,6 +15,7 @@ from calibre.customize import Plugin
|
||||
from calibre.utils.logging import ThreadSafeLog, FileStream
|
||||
from calibre.utils.config import JSONConfig
|
||||
from calibre.utils.titlecase import titlecase
|
||||
from calibre.utils.icu import capitalize, lower
|
||||
from calibre.ebooks.metadata import check_isbn
|
||||
|
||||
msprefs = JSONConfig('metadata_sources/global.json')
|
||||
@ -107,6 +108,25 @@ def get_cached_cover_urls(mi):
|
||||
if url:
|
||||
yield (p, url)
|
||||
|
||||
def cap_author_token(token):
|
||||
if lower(token) in ('von', 'de', 'el', 'van'):
|
||||
return lower(token)
|
||||
return capitalize(token)
|
||||
|
||||
def fixauthors(authors):
|
||||
if not authors:
|
||||
return authors
|
||||
ans = []
|
||||
for x in authors:
|
||||
ans.append(' '.join(map(cap_author_token, x.split())))
|
||||
return ans
|
||||
|
||||
def fixcase(x):
|
||||
if x:
|
||||
x = titlecase(x)
|
||||
return x
|
||||
|
||||
|
||||
|
||||
class Source(Plugin):
|
||||
|
||||
@ -259,13 +279,9 @@ class Source(Plugin):
|
||||
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.authors = fixauthors(mi.authors)
|
||||
mi.tags = list(map(fixcase, mi.tags))
|
||||
mi.isbn = check_isbn(mi.isbn)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user