From c3a87762296b6e489b8dc1f654fc5ccfb0269858 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 28 Jul 2011 13:18:53 -0600 Subject: [PATCH] National Geographic (PL) by Marcin Urban, Caros Amigos by Pablo Aldama, Aksiyon Dergisi by thomass --- recipes/aksiyon_derigisi.recipe | 53 ++++++++++++++++++++++ recipes/caros_amigos.recipe | 17 +++++++ recipes/icons/national_geographic_pl.png | Bin 0 -> 894 bytes recipes/national_geographic_pl.recipe | 52 ++++++++++++++++++++++ src/calibre/ebooks/mobi/kindlegen.py | 54 +++++++++++++++++++++++ src/calibre/ebooks/mobi/output.py | 16 +++++-- 6 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 recipes/aksiyon_derigisi.recipe create mode 100644 recipes/caros_amigos.recipe create mode 100644 recipes/icons/national_geographic_pl.png create mode 100644 recipes/national_geographic_pl.recipe create mode 100644 src/calibre/ebooks/mobi/kindlegen.py diff --git a/recipes/aksiyon_derigisi.recipe b/recipes/aksiyon_derigisi.recipe new file mode 100644 index 0000000000..f18ebd84d3 --- /dev/null +++ b/recipes/aksiyon_derigisi.recipe @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- + +from calibre.web.feeds.news import BasicNewsRecipe + +class Aksiyon (BasicNewsRecipe): + + title = u'Aksiyon Dergisi' + __author__ = u'thomass' + description = 'Haftalık haber dergisi ' + oldest_article =13 + max_articles_per_feed =100 + no_stylesheets = True + #delay = 1 + #use_embedded_content = False + encoding = 'utf-8' + publisher = 'Aksiyon' + category = 'news, haberler,TR,gazete' + language = 'tr' + publication_type = 'magazine' + #extra_css = ' body{ font-family: Verdana,Helvetica,Arial,sans-serif } .introduction{font-weight: bold} .story-feature{display: block; padding: 0; border: 1px solid; width: 40%; font-size: small} .story-feature h2{text-align: center; text-transform: uppercase} ' + #keep_only_tags = [dict(name='font', attrs={'class':['newsDetail','agenda2NewsSpot']}),dict(name='span', attrs={'class':['agenda2Title']}),dict(name='div', attrs={'id':['gallery']})] + remove_tags = [dict(name='img', attrs={'src':[ 'http://medya.aksiyon.com.tr/aksiyon/images/logo/logo.bmp','/aksiyon/images/template/green/baslik0.gif','mobile/home.jpg']}) ] + + cover_img_url = 'http://www.aksiyon.com.tr/aksiyon/images/aksiyon/top-page/aksiyon_top_r2_c1.jpg' + masthead_url = 'http://aksiyon.com.tr/aksiyon/images/aksiyon/top-page/aksiyon_top_r2_c1.jpg' + remove_empty_feeds= True + remove_attributes = ['width','height'] + + feeds = [ + ( u'ANASAYFA', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=0'), + ( u'KARAKUTU', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=11'), + ( u'EKONOMİ', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=35'), + ( u'EKOANALİZ', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=284'), + ( u'YAZARLAR', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=17'), + ( u'KİTAPLIK', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=13'), + ( u'SİNEMA', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=14'), + ( u'ARKA PENCERE', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=27'), + ( u'DÜNYA', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=32'), + ( u'DOSYALAR', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=34'), + ( u'KÜLTÜR & SANAT', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=12'), + ( u'KAPAK', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=26'), + ( u'SPOR', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=38'), + ( u'BİLİŞİM - TEKNOLOJİ', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=39'), + ( u'3. BOYUT', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=172'), + ( u'HAYAT BİLGİSİ', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=283'), + ( u'İŞ DÜNYASI', u'http://www.aksiyon.com.tr/aksiyon/rss?sectionId=283'), + + + ] + + def print_version(self, url): + return url.replace('http://www.aksiyon.com.tr/aksiyon/newsDetail_getNewsById.action?load=detay&', 'http://www.aksiyon.com.tr/aksiyon/mobile_detailn.action?') + diff --git a/recipes/caros_amigos.recipe b/recipes/caros_amigos.recipe new file mode 100644 index 0000000000..48edceacba --- /dev/null +++ b/recipes/caros_amigos.recipe @@ -0,0 +1,17 @@ +__copyright__ = '2011, Pablo Aldama ' + +from calibre.web.feeds.news import BasicNewsRecipe + +class AdvancedUserRecipe1311839910(BasicNewsRecipe): + title = u'Caros Amigos' + oldest_article = 20 + max_articles_per_feed = 100 + language = 'pt_BR' + __author__ = 'Pablo Aldama' + + feeds = [(u'Caros Amigos', u'http://carosamigos.terra.com.br/index/index.php?format=feed&type=rss')] + keep_only_tags = [dict(name='div', attrs={'class':['blog']}) + ,dict(name='div', attrs={'class':['blogcontent']}) + ] + remove_tags = [dict(name='div', attrs={'class':'addtoany'})] + diff --git a/recipes/icons/national_geographic_pl.png b/recipes/icons/national_geographic_pl.png new file mode 100644 index 0000000000000000000000000000000000000000..1ccae70dd61361855d1a0e3cc59a675ad166403c GIT binary patch literal 894 zcmZQzU<5(|0R|u`!H~hsz#zuJz@P!dKp_SNAO?wpfCEqtH#qa30Y5_1ieE8M77aku tqX|N|Sf#KEj;eFN+o&e$JpGm_oeE', re.DOTALL), lambda m: '')] + conversion_options = { + 'comments' : description + ,'tags' : category + ,'language' : language + ,'publisher' : publisher + ,'linearize_tables': True + } + + remove_tags = [ + dict(name='div', attrs={'class':'add_inf'}), + dict(name='div', attrs={'class':'add_f'}), + ] + + remove_attributes = ['width','height'] + + feeds = [ + ('National Geographic PL', 'http://www.national-geographic.pl/rss/'), + ] + + def print_version(self, url): + return url.replace('artykuly0Cpokaz', 'drukuj-artykul') + diff --git a/src/calibre/ebooks/mobi/kindlegen.py b/src/calibre/ebooks/mobi/kindlegen.py new file mode 100644 index 0000000000..5eb148e161 --- /dev/null +++ b/src/calibre/ebooks/mobi/kindlegen.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2011, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +import os, subprocess, tempfile + +from calibre.constants import iswindows +from calibre.customize.ui import plugin_for_output_format +from calibre.ptempfile import TemporaryDirectory +from calibre.ebooks.mobi.utils import detect_periodical +from calibre import CurrentDir + +exe = 'kindlegen.exe' if iswindows else 'kindlegen' + +def refactor_opf(opf, is_periodical): + pass + +def refactor_guide(oeb): + for key in list(oeb.guide): + if key not in ('toc', 'start'): + oeb.guide.remove(key) + +def run_kindlegen(opf, log): + log.info('Running kindlegen on MOBIML created by calibre') + oname = os.path.splitext(opf)[0] + '.mobi' + with tempfile.NamedTemporaryFile('_kindlegen_output.txt') as tfile: + p = subprocess.Popen([exe, opf, '-c1', '-verbose', '-o', oname], + stderr=subprocess.STDOUT, stdout=tfile) + returncode = p.wait() + tfile.seek(0) + log.debug('kindlegen verbose output:') + log.debug(tfile.read()) + log.info('kindlegen returned returncode: %d'%returncode) + if not os.path.exists(oname) or os.stat(oname).st_size < 100: + raise RuntimeError('kindlegen did not produce any output. ' + 'kindlegen return code: %d'%returncode) + return oname + +def kindlegen(oeb, opts, input_plugin, output_path): + is_periodical = detect_periodical(oeb.toc, oeb.log) + refactor_guide(oeb) + with TemporaryDirectory('_epub_output') as tdir: + oeb_output = plugin_for_output_format('oeb') + oeb_output.convert(oeb, tdir, input_plugin, opts, oeb.log) + 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) + diff --git a/src/calibre/ebooks/mobi/output.py b/src/calibre/ebooks/mobi/output.py index 669d41fa8f..cc526e0976 100644 --- a/src/calibre/ebooks/mobi/output.py +++ b/src/calibre/ebooks/mobi/output.py @@ -50,6 +50,12 @@ class MOBIOutput(OutputFormatPlugin): help=_('When adding the Table of Contents to the book, add it at the start of the ' 'book instead of the end. Not recommended.') ), + OptionRecommendation(name='kindlegen', + recommended_value=False, + help=_('Use kindlegen (must be in your PATH) to generate the' + ' binary wrapper for the MOBI format. Useful to debug ' + ' the calibre MOBI output.') + ), ]) @@ -164,7 +170,11 @@ class MOBIOutput(OutputFormatPlugin): MobiWriter else: from calibre.ebooks.mobi.writer import MobiWriter - writer = MobiWriter(opts, - write_page_breaks_after_item=write_page_breaks_after_item) - writer(oeb, output_path) + if opts.kindlegen: + from calibre.ebooks.mobi.kindlegen import kindlegen + kindlegen(oeb, opts, input_plugin, output_path) + else: + writer = MobiWriter(opts, + write_page_breaks_after_item=write_page_breaks_after_item) + writer(oeb, output_path)