mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: make rb input work
This commit is contained in:
parent
f2009fd991
commit
42cb67abb3
@ -64,7 +64,7 @@ class Reader(object):
|
||||
|
||||
toc = RBToc()
|
||||
for i in range(pages):
|
||||
name = unquote(self.stream.read(32).strip('\x00'))
|
||||
name = unquote(self.stream.read(32).strip(b'\x00'))
|
||||
size, offset, flags = self.read_i32(), self.read_i32(), self.read_i32()
|
||||
toc.append(RBToc.Item(name=name, size=size, offset=offset, flags=flags))
|
||||
|
||||
@ -90,7 +90,7 @@ class Reader(object):
|
||||
else:
|
||||
output += self.stream.read(toc_item.size).decode('cp1252' if self.encoding is None else self.encoding, 'replace')
|
||||
|
||||
with open(os.path.join(output_dir, toc_item.name), 'wb') as html:
|
||||
with open(os.path.join(output_dir, toc_item.name.decode('utf-8')), 'wb') as html:
|
||||
html.write(output.replace('<TITLE>', '<TITLE> ').encode('utf-8'))
|
||||
|
||||
def get_image(self, toc_item, output_dir):
|
||||
@ -100,7 +100,7 @@ class Reader(object):
|
||||
self.stream.seek(toc_item.offset)
|
||||
data = self.stream.read(toc_item.size)
|
||||
|
||||
with open(os.path.join(output_dir, toc_item.name), 'wb') as img:
|
||||
with open(os.path.join(output_dir, toc_item.name.decode('utf-8')), 'wb') as img:
|
||||
img.write(data)
|
||||
|
||||
def extract_content(self, output_dir):
|
||||
@ -109,13 +109,14 @@ class Reader(object):
|
||||
images = []
|
||||
|
||||
for item in self.toc:
|
||||
if item.name.lower().endswith('html'):
|
||||
self.log.debug('HTML item %s found...' % item.name)
|
||||
html.append(item.name)
|
||||
iname = item.name.decode('utf-8')
|
||||
if iname.lower().endswith('html'):
|
||||
self.log.debug('HTML item %s found...' % iname)
|
||||
html.append(iname)
|
||||
self.get_text(item, output_dir)
|
||||
if item.name.lower().endswith('png'):
|
||||
self.log.debug('PNG item %s found...' % item.name)
|
||||
images.append(item.name)
|
||||
if iname.lower().endswith('png'):
|
||||
self.log.debug('PNG item %s found...' % iname)
|
||||
images.append(iname)
|
||||
self.get_image(item, output_dir)
|
||||
|
||||
opf_path = self.create_opf(output_dir, html, images)
|
||||
|
Loading…
x
Reference in New Issue
Block a user