mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 14:53:06 +02:00
Fix eReader metadata reading.
This commit is contained in:
parent
e4ee664bb3
commit
3f92a07918
3 changed files with 19 additions and 15 deletions
|
|
@ -24,19 +24,22 @@ def get_metadata(stream, extract_cover=True):
|
|||
stream.seek(0)
|
||||
|
||||
pheader = PdbHeaderReader(stream)
|
||||
hr = HeaderRecord(pheader.section_data(0))
|
||||
|
||||
if hr.version in (2, 10) and hr.has_metadata == 1:
|
||||
try:
|
||||
mdata = pheader.section_data(hr.metadata_offset)
|
||||
# Only Dropbook produced 132 byte record0 files are supported
|
||||
if len(pheader.section_data(0)) == 132:
|
||||
hr = HeaderRecord(pheader.section_data(0))
|
||||
|
||||
mdata = mdata.split('\x00')
|
||||
mi.title = mdata[0]
|
||||
mi.authors = [mdata[1]]
|
||||
mi.publisher = mdata[3]
|
||||
mi.isbn = mdata[4]
|
||||
except:
|
||||
pass
|
||||
if hr.version in (2, 10) and hr.has_metadata == 1:
|
||||
try:
|
||||
mdata = pheader.section_data(hr.metadata_offset)
|
||||
|
||||
mdata = mdata.split('\x00')
|
||||
mi.title = mdata[0]
|
||||
mi.authors = [mdata[1]]
|
||||
mi.publisher = mdata[3]
|
||||
mi.isbn = mdata[4]
|
||||
except:
|
||||
pass
|
||||
|
||||
if not mi.title:
|
||||
mi.title = pheader.title if pheader.title else _('Unknown')
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ def get_metadata(stream, extract_cover=True):
|
|||
if MetadataReader is None:
|
||||
return MetaInformation(pheader.title, [_('Unknown')])
|
||||
|
||||
|
||||
return MetadataReader(stream, extract_cover)
|
||||
|
||||
def set_metadata(stream, mi):
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
import struct
|
||||
|
||||
from calibre import CurrentDir
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||
from calibre.ebooks.pml.pmlconverter import pml_to_html
|
||||
from calibre.ebooks.compression.palmdoc import decompress_doc
|
||||
|
|
@ -48,6 +47,9 @@ def __init__(self, header, stream, log, encoding=None):
|
|||
if self.header_record.version != 4:
|
||||
raise EreaderError('Unknown book version %i.' % self.header_record.version)
|
||||
|
||||
from calibre.ebooks.metadata.pdb import get_metadata
|
||||
self.mi = get_metadata(stream, False)
|
||||
|
||||
def section_data(self, number):
|
||||
return self.sections[number]
|
||||
|
||||
|
|
@ -62,7 +64,7 @@ def get_image(self, number):
|
|||
if data.startswith('PNG'):
|
||||
name = data[4:4 + 32].strip('\x00')
|
||||
img = data[62:]
|
||||
|
||||
|
||||
return name, img
|
||||
|
||||
def get_text_page(self, number):
|
||||
|
|
@ -114,7 +116,7 @@ def extract_content(self, output_dir):
|
|||
|
||||
def create_opf(self, output_dir, images):
|
||||
with CurrentDir(output_dir):
|
||||
opf = OPFCreator(output_dir, MetaInformation(_('Unknown'), _('Unknown')))
|
||||
opf = OPFCreator(output_dir, self.mi)
|
||||
|
||||
manifest = [('index.html', None)]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue