diff --git a/src/calibre/ebooks/metadata/rb.py b/src/calibre/ebooks/metadata/rb.py index a193ae44d9..251faeb00f 100644 --- a/src/calibre/ebooks/metadata/rb.py +++ b/src/calibre/ebooks/metadata/rb.py @@ -5,10 +5,11 @@ import sys, struct +from calibre import prints from calibre.ebooks.metadata import MetaInformation, string_to_authors from polyglot.builtins import unicode_type -MAGIC = '\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00' +MAGIC = b'\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00' def get_metadata(stream): @@ -37,7 +38,7 @@ def get_metadata(stream): return mi stream.seek(offset) - info = stream.read(length).splitlines() + info = stream.read(length).decode('utf-8', 'replace').splitlines() for line in info: if '=' not in line: continue @@ -45,10 +46,9 @@ def get_metadata(stream): if key.strip() == 'TITLE': mi.title = value.strip() elif key.strip() == 'AUTHOR': - mi.author = value mi.authors = string_to_authors(value) except Exception as err: msg = u'Couldn\'t read metadata from rb: %s with error %s'%(mi.title, unicode_type(err)) - print(msg.encode('utf8'), file=sys.stderr) + prints(msg, file=sys.stderr) raise return mi diff --git a/src/calibre/ebooks/rb/__init__.py b/src/calibre/ebooks/rb/__init__.py index acf9c04995..f45b966dad 100644 --- a/src/calibre/ebooks/rb/__init__.py +++ b/src/calibre/ebooks/rb/__init__.py @@ -6,7 +6,7 @@ import os -HEADER = '\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00' +HEADER = b'\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00' class RocketBookError(Exception): diff --git a/src/calibre/ebooks/rb/reader.py b/src/calibre/ebooks/rb/reader.py index da5330c7f1..0d111107fa 100644 --- a/src/calibre/ebooks/rb/reader.py +++ b/src/calibre/ebooks/rb/reader.py @@ -64,7 +64,7 @@ def get_toc(self): 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 @@ def get_text(self, toc_item, output_dir): 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('