From 596ba46590fe546d304ce3730ddc9b4de4f45f37 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 19 May 2010 07:36:42 -0600 Subject: [PATCH 1/3] ... --- src/calibre/devices/prs505/sony_cache.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/calibre/devices/prs505/sony_cache.py b/src/calibre/devices/prs505/sony_cache.py index f365bba3ab..b81867dc7f 100644 --- a/src/calibre/devices/prs505/sony_cache.py +++ b/src/calibre/devices/prs505/sony_cache.py @@ -184,8 +184,7 @@ class XMLCache(object): 'descendant::*[local-name()="png"]'): if img.text: raw = b64decode(img.text.strip()) - ext = img.tag.split('}')[-1] - book.cover_data = [ext, raw] + book.thumbnail = raw break break # }}} From 48f8a9c338dcaf133f832b22cad3d92f0c06da56 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 19 May 2010 08:53:07 -0600 Subject: [PATCH 2/3] Guarantee that metadata read from filenames is unicode --- src/calibre/ebooks/metadata/meta.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/metadata/meta.py b/src/calibre/ebooks/metadata/meta.py index 4f808e3fb0..f5a327a0d6 100644 --- a/src/calibre/ebooks/metadata/meta.py +++ b/src/calibre/ebooks/metadata/meta.py @@ -5,9 +5,9 @@ __copyright__ = '2008, Kovid Goyal ' import os, re, collections from calibre.utils.config import prefs - +from calibre.constants import filesystem_encoding from calibre.ebooks.metadata.opf2 import OPF - +from calibre import isbytestring from calibre.customize.ui import get_file_type_metadata, set_file_type_metadata from calibre.ebooks.metadata import MetaInformation, string_to_authors @@ -131,6 +131,8 @@ def set_metadata(stream, mi, stream_type='lrf'): def metadata_from_filename(name, pat=None): + if isbytestring(name): + name = name.decode(filesystem_encoding, 'replace') name = name.rpartition('.')[0] mi = MetaInformation(None, None) if pat is None: From b172b841196d155db92ba88b188d32ad745ab452 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 19 May 2010 08:57:59 -0600 Subject: [PATCH 3/3] Ensure encoding to JSON in BookList never blows up because of non UTF-8 bytestrings --- src/calibre/devices/usbms/books.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index e7462bdb73..5ae2c20df7 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -11,7 +11,8 @@ import time from calibre.ebooks.metadata import MetaInformation from calibre.devices.mime import mime_type_ext from calibre.devices.interface import BookList as _BookList -from calibre.constants import filesystem_encoding +from calibre.constants import filesystem_encoding, preferred_encoding +from calibre import isbytestring class Book(MetaInformation): @@ -105,7 +106,11 @@ class Book(MetaInformation): def to_json(self): json = {} for attr in self.JSON_ATTRS: - json[attr] = getattr(self, attr) + val = getattr(self, attr) + if isbytestring(val): + enc = filesystem_encoding if attr == 'lpath' else preferred_encoding + val = val.decode(enc, 'replace') + json[attr] = val return json class BookList(_BookList):