From ea876907e91e8c896b48b28ec4978e042f723b4e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 28 Jul 2011 14:08:24 -0600 Subject: [PATCH] ... --- recipes/economist.recipe | 3 ++- recipes/economist_free.recipe | 3 ++- src/calibre/ebooks/mobi/kindlegen.py | 32 ++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/recipes/economist.recipe b/recipes/economist.recipe index 79a247d855..702e3c6601 100644 --- a/recipes/economist.recipe +++ b/recipes/economist.recipe @@ -22,7 +22,8 @@ class Economist(BasicNewsRecipe): ' perspective. Best downloaded on Friday mornings (GMT)') extra_css = '.headline {font-size: x-large;} \n h2 { font-size: small; } \n h1 { font-size: medium; }' oldest_article = 7.0 - cover_url = 'http://www.economist.com/images/covers/currentcoverus_large.jpg' + cover_url = 'http://media.economist.com/sites/default/files/imagecache/print-cover-thumbnail/print-covers/currentcoverus_large.jpg' + #cover_url = 'http://www.economist.com/images/covers/currentcoverus_large.jpg' remove_tags = [ dict(name=['script', 'noscript', 'title', 'iframe', 'cf_floatingcontent']), dict(attrs={'class':['dblClkTrk', 'ec-article-info', 'share_inline_header']}), diff --git a/recipes/economist_free.recipe b/recipes/economist_free.recipe index 1c1dcca183..1d4dd8ba7d 100644 --- a/recipes/economist_free.recipe +++ b/recipes/economist_free.recipe @@ -16,7 +16,8 @@ class Economist(BasicNewsRecipe): ' Much slower than the print edition based version.') extra_css = '.headline {font-size: x-large;} \n h2 { font-size: small; } \n h1 { font-size: medium; }' oldest_article = 7.0 - cover_url = 'http://www.economist.com/images/covers/currentcoverus_large.jpg' + cover_url = 'http://media.economist.com/sites/default/files/imagecache/print-cover-thumbnail/print-covers/currentcoverus_large.jpg' + #cover_url = 'http://www.economist.com/images/covers/currentcoverus_large.jpg' remove_tags = [ dict(name=['script', 'noscript', 'title', 'iframe', 'cf_floatingcontent']), dict(attrs={'class':['dblClkTrk', 'ec-article-info', diff --git a/src/calibre/ebooks/mobi/kindlegen.py b/src/calibre/ebooks/mobi/kindlegen.py index 5eb148e161..b1a64f86af 100644 --- a/src/calibre/ebooks/mobi/kindlegen.py +++ b/src/calibre/ebooks/mobi/kindlegen.py @@ -7,7 +7,9 @@ __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, subprocess, tempfile +import os, subprocess, tempfile, shutil + +from lxml import etree from calibre.constants import iswindows from calibre.customize.ui import plugin_for_output_format @@ -18,11 +20,24 @@ from calibre import CurrentDir exe = 'kindlegen.exe' if iswindows else 'kindlegen' def refactor_opf(opf, is_periodical): - pass + with open(opf, 'rb') as f: + root = etree.fromstring(f.read()) + if is_periodical: + metadata = root.xpath('//*[local-name() = "metadata"]')[0] + xm = etree.SubElement(metadata, 'x-metadata') + xm.tail = '\n' + xm.text = '\n\t' + mobip = etree.SubElement(xm, attrib={'encoding':"utf-8", + 'content-type':"application/x-mobipocket-subscription-magazine"}) + mobip.tail = '\n' + with open(opf, 'wb') as f: + f.write(etree.tostring(root, method='xml', encodin='utf-8', + xml_declaration=True)) + def refactor_guide(oeb): for key in list(oeb.guide): - if key not in ('toc', 'start'): + if key not in ('toc', 'start', 'masthead'): oeb.guide.remove(key) def run_kindlegen(opf, log): @@ -50,5 +65,14 @@ def kindlegen(oeb, opts, input_plugin, output_path): opf = [x for x in os.listdir(tdir) if x.endswith('.opf')][0] refactor_opf(opf, is_periodical) with CurrentDir(tdir): - run_kindlegen(opf, oeb.log) + oname = run_kindlegen(opf, oeb.log) + shutil.copyfile(oname, output_path) + + try: + if os.path.exists('/tmp/kindlegen'): + shutil.rmtree('/tmp/kindlegen') + shutil.copytree(tdir, '/tmp/kindlegen') + oeb.log('kindlegen intermediate output stored in: /tmp/kindlegen') + except: + pass