mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add support for author and description when parsing NCX files
This commit is contained in:
parent
f5fb4d9a6c
commit
fb86204423
@ -41,11 +41,14 @@ SVG_NS = 'http://www.w3.org/2000/svg'
|
||||
XLINK_NS = 'http://www.w3.org/1999/xlink'
|
||||
CALIBRE_NS = 'http://calibre.kovidgoyal.net/2009/metadata'
|
||||
RE_NS = 'http://exslt.org/regular-expressions'
|
||||
MBP_NS = 'http://www.mobipocket.com'
|
||||
|
||||
XPNSMAP = {'h' : XHTML_NS, 'o1' : OPF1_NS, 'o2' : OPF2_NS,
|
||||
'd09': DC09_NS, 'd10': DC10_NS, 'd11': DC11_NS,
|
||||
'xsi': XSI_NS, 'dt' : DCTERMS_NS, 'ncx': NCX_NS,
|
||||
'svg': SVG_NS, 'xl' : XLINK_NS, 're': RE_NS}
|
||||
'svg': SVG_NS, 'xl' : XLINK_NS, 're': RE_NS,
|
||||
'mbp': MBP_NS }
|
||||
|
||||
OPF1_NSMAP = {'dc': DC11_NS, 'oebpackage': OPF1_NS}
|
||||
OPF2_NSMAP = {'opf': OPF2_NS, 'dc': DC11_NS, 'dcterms': DCTERMS_NS,
|
||||
'xsi': XSI_NS, 'calibre': CALIBRE_NS}
|
||||
@ -1373,9 +1376,11 @@ class TOC(object):
|
||||
:attr:`href`: Book-internal URL referenced by this node.
|
||||
:attr:`klass`: Optional semantic class referenced by this node.
|
||||
:attr:`id`: Option unique identifier for this node.
|
||||
:attr:`author`: Optional author attribution for periodicals <mbp:>
|
||||
:attr:`description`: Optional description attribute for periodicals <mbp:>
|
||||
"""
|
||||
def __init__(self, title=None, href=None, klass=None, id=None,
|
||||
play_order=None):
|
||||
play_order=None, author=None, description=None):
|
||||
self.title = title
|
||||
self.href = urlnormalize(href) if href else href
|
||||
self.klass = klass
|
||||
@ -1385,10 +1390,12 @@ class TOC(object):
|
||||
if play_order is None:
|
||||
play_order = self.next_play_order()
|
||||
self.play_order = play_order
|
||||
self.author = author
|
||||
self.description = description
|
||||
|
||||
def add(self, title, href, klass=None, id=None, play_order=0):
|
||||
def add(self, title, href, klass=None, id=None, play_order=0, author=None, description=None):
|
||||
"""Create and return a new sub-node of this node."""
|
||||
node = TOC(title, href, klass, id, play_order)
|
||||
node = TOC(title, href, klass, id, play_order, author, description)
|
||||
self.nodes.append(node)
|
||||
return node
|
||||
|
||||
|
@ -351,9 +351,27 @@ class OEBReader(object):
|
||||
self.logger.warn('TOC reference %r not found' % href)
|
||||
continue
|
||||
id = child.get('id')
|
||||
klass = child.get('class')
|
||||
klass = child.get('class', 'chapter')
|
||||
|
||||
po = int(child.get('playOrder', self.oeb.toc.next_play_order()))
|
||||
node = toc.add(title, href, id=id, klass=klass, play_order=po)
|
||||
|
||||
authorElement = xpath(child,
|
||||
'descendant::mbp:meta[@name = "author"]')
|
||||
if authorElement :
|
||||
author = authorElement[0].text
|
||||
else :
|
||||
author = None
|
||||
|
||||
descriptionElement = xpath(child,
|
||||
'descendant::mbp:meta[@name = "description"]')
|
||||
if descriptionElement :
|
||||
description = descriptionElement[0].text
|
||||
else :
|
||||
description = None
|
||||
|
||||
node = toc.add(title, href, id=id, klass=klass,
|
||||
play_order=po, description=description, author=author)
|
||||
|
||||
self._toc_from_navpoint(item, node, child)
|
||||
|
||||
def _toc_from_ncx(self, item):
|
||||
|
Loading…
x
Reference in New Issue
Block a user