When adding MOBI files if the author name is in LN, FN format, auto change it to FN LN format. This behavior can be disabled by setting Preferences->Tweaks->Author sort name algorithm to copy. Fixes #1306748 [Author attribute is imported incorrectly when importing Kindle e-book files](https://bugs.launchpad.net/calibre/+bug/1306748)

This commit is contained in:
Kovid Goyal 2014-04-22 10:30:41 +05:30
parent ced2265ce2
commit 3d6204db86

View File

@ -15,6 +15,7 @@ from calibre.ebooks.metadata import MetaInformation, check_isbn
from calibre.ebooks.mobi.langcodes import main_language, sub_language, mobi2iana
from calibre.utils.cleantext import clean_ascii_chars, clean_xml_chars
from calibre.utils.localization import canonicalize_lang
from calibre.utils.config_base import tweaks
NULL_INDEX = 0xffffffff
@ -90,9 +91,18 @@ class EXTHHeader(object): # {{{
if self.mi.is_null('authors'):
self.mi.authors = []
au = clean_xml_chars(self.decode(content).strip())
# Author names in Amazon MOBI files are usually in LN, FN format,
# try to detect and auto-correct that.
m = re.match(r'([^,]+?)\s*,\s+([^,]+)$', au.strip())
if m is not None:
if tweaks['author_sort_copy_method'] != 'copy':
self.mi.authors.append(m.group(2) + ' ' + m.group(1))
else:
self.mi.authors.append(m.group())
if self.mi.is_null('author_sort'):
self.mi.author_sort = m.group()
else:
self.mi.authors.append(au)
if self.mi.is_null('author_sort') and re.match(r'\S+?\s*,\s+\S+', au.strip()):
self.mi.author_sort = au.strip()
elif idx == 101:
self.mi.publisher = clean_xml_chars(self.decode(content).strip())
if self.mi.publisher in {'Unknown', _('Unknown')}: