mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Working eReader input.
This commit is contained in:
parent
6f7d0f7696
commit
e968f529da
@ -12,6 +12,11 @@ FORMATS = {
|
||||
'PNRdPPrs' : eReader,
|
||||
}
|
||||
|
||||
IDENTITY_TO_NAME = {
|
||||
'PNPdPPrs' : 'eReader',
|
||||
'PNRdPPrs' : 'eReader',
|
||||
}
|
||||
|
||||
class PDBError(Exception):
|
||||
pass
|
||||
|
||||
|
@ -40,7 +40,6 @@ PML_HTML_RULES = [
|
||||
(re.compile('\\\\q="(?P<target>#.+?)"(?P<text>)\\\\q', re.DOTALL), lambda match: '<a href="%s">%s</a>' % (match.group('target'), match.group('text'))),
|
||||
(re.compile('\\\\Q="(?P<target>.+?)"'), lambda match: '<div id="%s"></div>' % match.group('target')),
|
||||
(re.compile('\\\\-'), lambda match: ''),
|
||||
# Todo: Footnotes need link.
|
||||
(re.compile('\\\\Fn="(?P<target>.+?)"(?P<text>.+?)\\\\Fn'), lambda match: '<a href="#footnote-%s">%s</a>' % (match.group('target'), match.group('text'))),
|
||||
(re.compile('\\\\Sd="(?P<target>.+?)"(?P<text>.+?)\\\\Sd'), lambda match: '<a href="#sidebar-%s">%s</a>' % (match.group('target'), match.group('text'))),
|
||||
(re.compile('\\\\I'), lambda match: ''),
|
||||
|
@ -44,13 +44,15 @@ class HeaderRecord(object):
|
||||
|
||||
# Can't tell which is sidebar and footnote if they have same offset.
|
||||
# They don't exist if offset is larget than last_record.
|
||||
# Todo: Determine if the subtraction is necessary and find out
|
||||
# what _rec means.
|
||||
self.num_footnote_pages = self.sidebar_offset - self.footnote_offset if self.footnote_offset < self.last_data_offset else 0
|
||||
self.num_sidebar_pages = self.sidebar_offset - self.last_data_offset if self.footnote_offset < self.last_data_offset else 0
|
||||
|
||||
|
||||
class Reader(object):
|
||||
|
||||
def __init__(self, header, stream):
|
||||
def __init__(self, header, stream, log):
|
||||
raw = stream.read()
|
||||
|
||||
self.sections = []
|
||||
@ -169,9 +171,9 @@ class Reader(object):
|
||||
with open(name, 'wb') as imgf:
|
||||
imgf.write(img)
|
||||
|
||||
self.create_opf(output_dir, images)
|
||||
opf_path = self.create_opf(output_dir, images)
|
||||
|
||||
return os.path.join(output_dir, 'metadata.opf')
|
||||
return opf_path
|
||||
|
||||
def create_opf(self, output_dir, images):
|
||||
mi = MetaInformation(None, None)
|
||||
@ -188,6 +190,8 @@ class Reader(object):
|
||||
opf.create_spine(['index.html'])
|
||||
with open('metadata.opf', 'wb') as opffile:
|
||||
opf.render(opffile)
|
||||
|
||||
return os.path.join(output_dir, 'metadata.opf')
|
||||
|
||||
def dump_pml(self):
|
||||
pml = ''
|
||||
@ -197,3 +201,8 @@ class Reader(object):
|
||||
|
||||
return pml
|
||||
|
||||
|
||||
class EreaderMetadata(object):
|
||||
|
||||
def __init__(self, record):
|
||||
pass
|
||||
|
@ -9,7 +9,7 @@ import os
|
||||
|
||||
from calibre.customize.conversion import InputFormatPlugin
|
||||
from calibre.ebooks.pdb.header import PdbHeader
|
||||
from calibre.ebooks.pdb import PDBError, get_reader
|
||||
from calibre.ebooks.pdb import PDBError, IDENTITY_TO_NAME, get_reader
|
||||
|
||||
class PDBInput(InputFormatPlugin):
|
||||
|
||||
@ -24,9 +24,11 @@ class PDBInput(InputFormatPlugin):
|
||||
Reader = get_reader(header.ident)
|
||||
|
||||
if Reader is None:
|
||||
raise PDBError('Unknown format identity is %s' % header.identity)
|
||||
raise PDBError('Unknown format in pdb file. Identity is %s' % header.identity)
|
||||
|
||||
log.debug('Detected ebook format as: %s with identity: %s' % (IDENTITY_TO_NAME[header.ident], header.ident))
|
||||
|
||||
reader = Reader(header, stream)
|
||||
reader = Reader(header, stream, log)
|
||||
opf = reader.extract_content(os.getcwd())
|
||||
|
||||
return opf
|
||||
|
Loading…
x
Reference in New Issue
Block a user