mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-04-24 03:14:41 +02:00
Topaz metadata: Read metadata correctly from Topaz files that have MOBI file extensions
This commit is contained in:
parent
61fb4f30e0
commit
fd20c4ac7f
1 changed files with 13 additions and 1 deletions
|
|
@ -29,6 +29,9 @@
|
|||
from calibre.ebooks.metadata.opf2 import OPFCreator, OPF
|
||||
from calibre.ebooks.metadata.toc import TOC
|
||||
|
||||
class TopazError(ValueError):
|
||||
pass
|
||||
|
||||
class EXTHHeader(object):
|
||||
|
||||
def __init__(self, raw, codec, title):
|
||||
|
|
@ -259,7 +262,7 @@ def __init__(self, filename_or_stream, log, user_encoding=None, debug=None,
|
|||
|
||||
raw = stream.read()
|
||||
if raw.startswith('TPZ'):
|
||||
raise ValueError(_('This is an Amazon Topaz book. It cannot be processed.'))
|
||||
raise TopazError(_('This is an Amazon Topaz book. It cannot be processed.'))
|
||||
|
||||
self.header = raw[0:72]
|
||||
self.name = self.header[:32].replace('\x00', '')
|
||||
|
|
@ -832,6 +835,15 @@ def extract_images(self, processed_records, output_dir):
|
|||
im.save(open(path, 'wb'), format='JPEG')
|
||||
|
||||
def get_metadata(stream):
|
||||
stream.seek(0)
|
||||
try:
|
||||
raw = stream.read(3)
|
||||
except:
|
||||
raw = ''
|
||||
stream.seek(0)
|
||||
if raw == 'TPZ':
|
||||
from calibre.ebooks.metadata.topaz import get_metadata
|
||||
return get_metadata(stream)
|
||||
from calibre.utils.logging import Log
|
||||
log = Log()
|
||||
mi = MetaInformation(os.path.basename(stream.name), [_('Unknown')])
|
||||
|
|
|
|||
Loading…
Reference in a new issue