From 7bd0237c3f0b1085d03ffdedfabcd9dc1e1742e6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 18 May 2012 16:16:55 +0530 Subject: [PATCH 1/3] ... --- session.vim | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/session.vim b/session.vim index 2bc23acd88..e9cfc39c87 100644 --- a/session.vim +++ b/session.vim @@ -1,40 +1,9 @@ " Project wide builtins let $PYFLAKES_BUILTINS = "_,dynamic_property,__,P,I,lopen,icu_lower,icu_upper,icu_title,ngettext" -python << EOFPY -import os, sys - -import vipy - -source_file = vipy.vipy.eval('expand("")') -project_dir = os.path.dirname(source_file) -src_dir = os.path.abspath(os.path.join(project_dir, 'src')) -base_dir = os.path.join(src_dir, 'calibre') - -sys.path.insert(0, src_dir) -sys.resources_location = os.path.join(project_dir, 'resources') -sys.extensions_location = os.path.join(base_dir, 'plugins') -sys.executables_location = os.environ.get('CALIBRE_EXECUTABLES_PATH', '/usr/bin') - -vipy.session.initialize(project_name='calibre', src_dir=src_dir, - project_dir=project_dir, base_dir=project_dir) - -def recipe_title_callback(raw): - try: - raw = eval(raw) - if isinstance(raw, bytes): - raw = raw.decode('utf-8') - return raw.replace(u' ', u'_') - except: - print ('Failed to decode recipe title: %r'%raw) - raise - -vipy.session.add_content_browser('r', 'Recipe', - vipy.session.glob_based_iterator(os.path.join(project_dir, 'recipes', '*.recipe')), - vipy.session.regexp_based_matcher(r'title\s*=\s*(?P.+)', 'title', recipe_title_callback)) -EOFPY - fun! CalibreLog() + " Setup buffers to edit the calibre changelog and version info prior to + " making a release. enew read ! bzr log -l 500 set nomodifiable noswapfile buftype=nofile From 13f03b4b941c4d1a62f942f984239bd2751ccf0d Mon Sep 17 00:00:00 2001 From: Kovid Goyal <kovid@kovidgoyal.net> Date: Fri, 18 May 2012 18:53:37 +0530 Subject: [PATCH 2/3] ... --- recipes/stars_and_stripes.recipe | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/stars_and_stripes.recipe b/recipes/stars_and_stripes.recipe index d1d203dc70..57acd5ebd8 100644 --- a/recipes/stars_and_stripes.recipe +++ b/recipes/stars_and_stripes.recipe @@ -18,7 +18,7 @@ class AdvancedUserRecipe1308791026(BasicNewsRecipe): encoding = 'utf8' publisher = 'stripes.com' category = 'news, US, world' - language = 'en_US' + language = 'en' publication_type = 'newsportal' preprocess_regexps = [(re.compile(r'<!--.*?-->', re.DOTALL), lambda m: '')] conversion_options = { From 0901845c0f452e87829d5131c30f95bea27248cc Mon Sep 17 00:00:00 2001 From: Kovid Goyal <kovid@kovidgoyal.net> Date: Fri, 18 May 2012 19:00:09 +0530 Subject: [PATCH 3/3] Kindle driver: Upload cover thumbnails when sending books to device by USB to workaround Amazon bug of not displaying covers for sync-enabled books --- src/calibre/devices/kindle/driver.py | 37 ++++++++++++++++++++++- src/calibre/ebooks/mobi/reader/headers.py | 11 +++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/kindle/driver.py b/src/calibre/devices/kindle/driver.py index 8154b7d3a0..9754f95d2d 100644 --- a/src/calibre/devices/kindle/driver.py +++ b/src/calibre/devices/kindle/driver.py @@ -13,6 +13,7 @@ import datetime, os, re, sys, json, hashlib from calibre.devices.kindle.bookmark import Bookmark from calibre.devices.usbms.driver import USBMS from calibre import strftime +from calibre.utils.logging import default_log ''' Notes on collections: @@ -324,6 +325,7 @@ class KINDLE2(KINDLE): OPT_APNX = 0 OPT_APNX_ACCURATE = 1 OPT_APNX_CUST_COL = 2 + THUMBNAIL_HEIGHT = 180 def formats_to_scan_for(self): ans = USBMS.formats_to_scan_for(self) | {'azw3'} @@ -375,8 +377,36 @@ class KINDLE2(KINDLE): def upload_cover(self, path, filename, metadata, filepath): ''' - Hijacking this function to write the apnx file. + Upload sidecar files: cover thumbnails and page count ''' + # Upload the cover thumbnail + try: + self.upload_kindle_thumbnail(metadata, filepath) + except: + import traceback + traceback.print_exc() + # Upload the apnx file + self.upload_apnx(filename, metadata, filepath) + + def upload_kindle_thumbnail(self, metadata, filepath): + coverdata = getattr(metadata, 'thumbnail', None) + if not coverdata or not coverdata[2]: + return + thumb_dir = os.path.join(self._main_prefix, 'system', 'thumbnails') + if not os.path.exists(thumb_dir): return + + from calibre.ebooks.mobi.reader.headers import MetadataHeader + with lopen(filepath, 'rb') as f: + mh = MetadataHeader(f, default_log) + if mh.exth is None or not mh.exth.uuid or not mh.exth.cdetype: + return + thumbfile = os.path.join(thumb_dir, + 'thumbnail_{uuid}_{cdetype}_portrait.jpg'.format( + uuid=mh.exth.uuid, cdetype=mh.exth.cdetype)) + with open(thumbfile, 'wb') as f: + f.write(coverdata[2]) + + def upload_apnx(self, filename, metadata, filepath): from calibre.devices.kindle.apnx import APNXBuilder opts = self.settings() @@ -422,6 +452,9 @@ class KINDLE_DX(KINDLE2): PRODUCT_ID = [0x0003] BCD = [0x0100] + def upload_kindle_thumbnail(self, metadata, filepath): + pass + class KINDLE_FIRE(KINDLE2): name = 'Kindle Fire Device Interface' @@ -440,4 +473,6 @@ class KINDLE_FIRE(KINDLE2): VENDOR_NAME = 'AMAZON' WINDOWS_MAIN_MEM = 'KINDLE' + def upload_kindle_thumbnail(self, metadata, filepath): + pass diff --git a/src/calibre/ebooks/mobi/reader/headers.py b/src/calibre/ebooks/mobi/reader/headers.py index a5ca4a7132..90fdb0e8df 100644 --- a/src/calibre/ebooks/mobi/reader/headers.py +++ b/src/calibre/ebooks/mobi/reader/headers.py @@ -45,6 +45,10 @@ class EXTHHeader(object): # {{{ elif idx == 202: self.thumbnail_offset, = struct.unpack('>L', content) elif idx == 501: + try: + self.cdetype = content.decode('ascii') + except UnicodeDecodeError: + self.cdetype = None # cdetype if content == b'EBSP': if not self.mi.tags: @@ -109,8 +113,11 @@ class EXTHHeader(object): # {{{ self.mi.isbn = raw except: pass - elif idx == 113: - pass # ASIN or UUID + elif idx == 113: # ASIN or other id + try: + self.uuid = content.decode('ascii') + except: + self.uuid = None elif idx == 116: self.start_offset, = struct.unpack(b'>L', content) elif idx == 121: