mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Catalog generation: Do not abort on author sort mismatches when generating an EPUB catalog
This commit is contained in:
commit
73a5003a4c
@ -24,6 +24,7 @@ from calibre.utils.logging import Log
|
||||
from calibre.utils.zipfile import ZipFile
|
||||
|
||||
from PIL import Image as PILImage
|
||||
from lxml import etree
|
||||
|
||||
if isosx:
|
||||
try:
|
||||
@ -2515,23 +2516,23 @@ class ITUNES(DriverBase):
|
||||
fnames = zf_opf.namelist()
|
||||
opf = [x for x in fnames if '.opf' in x][0]
|
||||
if opf:
|
||||
opf_raw = cStringIO.StringIO(zf_opf.read(opf))
|
||||
soup = BeautifulSoup(opf_raw.getvalue())
|
||||
opf_raw.close()
|
||||
|
||||
# Touch existing calibre timestamp
|
||||
md = soup.find('metadata')
|
||||
if md:
|
||||
ts = md.find('meta',attrs={'name':'calibre:timestamp'})
|
||||
if ts:
|
||||
timestamp = ts['content']
|
||||
old_ts = parse_date(timestamp)
|
||||
metadata.timestamp = datetime.datetime(old_ts.year, old_ts.month, old_ts.day, old_ts.hour,
|
||||
old_ts.minute, old_ts.second, old_ts.microsecond+1, old_ts.tzinfo)
|
||||
else:
|
||||
metadata.timestamp = now()
|
||||
if DEBUG:
|
||||
self.log.info(" add timestamp: %s" % metadata.timestamp)
|
||||
opf_tree = etree.fromstring(zf_opf.read(opf))
|
||||
ns_map = opf_tree.nsmap.keys()
|
||||
for item in ns_map:
|
||||
ns = opf_tree.nsmap[item]
|
||||
md_el = opf_tree.find(".//{%s}metadata" % ns)
|
||||
if md_el is not None:
|
||||
ts = md_el.find('.//{%s}meta[@name="calibre:timestamp"]')
|
||||
if ts:
|
||||
timestamp = ts.get('content')
|
||||
old_ts = parse_date(timestamp)
|
||||
metadata.timestamp = datetime.datetime(old_ts.year, old_ts.month, old_ts.day, old_ts.hour,
|
||||
old_ts.minute, old_ts.second, old_ts.microsecond+1, old_ts.tzinfo)
|
||||
else:
|
||||
metadata.timestamp = now()
|
||||
if DEBUG:
|
||||
self.log.info(" add timestamp: %s" % metadata.timestamp)
|
||||
break
|
||||
else:
|
||||
metadata.timestamp = now()
|
||||
if DEBUG:
|
||||
@ -2839,7 +2840,7 @@ class ITUNES(DriverBase):
|
||||
def _xform_metadata_via_plugboard(self, book, format):
|
||||
''' Transform book metadata from plugboard templates '''
|
||||
if DEBUG:
|
||||
self.log.info(" ITUNES._update_metadata_from_plugboard()")
|
||||
self.log.info(" ITUNES._xform_metadata_via_plugboard()")
|
||||
|
||||
if self.plugboard_func:
|
||||
pb = self.plugboard_func(self.DEVICE_PLUGBOARD_NAME, format, self.plugboards)
|
||||
|
@ -1481,23 +1481,36 @@ class EPUB_MOBI(CatalogPlugin):
|
||||
current_author = authors[0]
|
||||
for (i,author) in enumerate(authors):
|
||||
if author != current_author and i:
|
||||
# Exit if author matches previous, but author_sort doesn't match
|
||||
if author[0] == current_author[0]:
|
||||
error_msg = _('''
|
||||
Inconsistent Author Sort values for Author '{0}':
|
||||
'{1}' <> '{2}',
|
||||
unable to build catalog.\n
|
||||
Select all books by '{0}', apply correct Author Sort value in Edit Metadata dialog,
|
||||
then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
self.opts.log.warn('\n*** Metadata error ***')
|
||||
self.opts.log.warn(error_msg)
|
||||
if self.opts.fmt == 'mobi':
|
||||
# Exit if building MOBI
|
||||
error_msg = _(
|
||||
'''Inconsistent Author Sort values for
|
||||
Author '{0}':
|
||||
'{1}' <> '{2}'
|
||||
Unable to build MOBI catalog.\n
|
||||
Select all books by '{0}', apply correct Author Sort value in Edit Metadata dialog, then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
self.opts.log.warn('\n*** Metadata error ***')
|
||||
self.opts.log.warn(error_msg)
|
||||
|
||||
self.error.append('Author Sort mismatch')
|
||||
self.error.append(error_msg)
|
||||
return False
|
||||
else:
|
||||
# Warning if building non-MOBI
|
||||
if not self.error:
|
||||
self.error.append('Author Sort mismatch')
|
||||
|
||||
error_msg = _(
|
||||
'''Warning: inconsistent Author Sort values for
|
||||
Author '{0}':
|
||||
'{1}' <> '{2}'\n''').format(author[0],author[1],current_author[1])
|
||||
self.opts.log.warn('\n*** Metadata warning ***')
|
||||
self.opts.log.warn(error_msg)
|
||||
self.error.append(error_msg)
|
||||
|
||||
self.error.append('Metadata error')
|
||||
self.error.append(error_msg)
|
||||
return False
|
||||
current_author = author
|
||||
|
||||
|
||||
self.booksByAuthor = sorted(self.booksByAuthor, key=self.booksByAuthorSorter_author_sort)
|
||||
|
||||
# Build the unique_authors set from existing data
|
||||
@ -2135,7 +2148,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
if author_count == 1:
|
||||
divOpeningTag.insert(dotc, pBookTag)
|
||||
dotc += 1
|
||||
else:
|
||||
elif divRunningTag:
|
||||
divRunningTag.insert(drtc,pBookTag)
|
||||
drtc += 1
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user