From 8ca336696b5058c9c0eeb7a165e9259a71dc008c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 1 May 2009 20:29:42 -0700 Subject: [PATCH 1/3] New recipe for Twitch films by Darko Miletic --- src/calibre/debug.py | 2 +- src/calibre/web/feeds/recipes/__init__.py | 2 +- .../web/feeds/recipes/recipe_twitchfilms.py | 41 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/calibre/web/feeds/recipes/recipe_twitchfilms.py diff --git a/src/calibre/debug.py b/src/calibre/debug.py index 35fc615b58..ac164c14ab 100644 --- a/src/calibre/debug.py +++ b/src/calibre/debug.py @@ -105,7 +105,7 @@ def debug_device_driver(): prefix = logical_disk.DeviceID+os.sep drives.append((str(drive.PNPDeviceID), drive.Index, prefix)) except IndexError: - drives.append(str(drive.PNPDeviceID)) + drives.append((str(drive.PNPDeviceID), 'No mount points found')) for drive in drives: print '\t', drive from calibre.devices import devices diff --git a/src/calibre/web/feeds/recipes/__init__.py b/src/calibre/web/feeds/recipes/__init__.py index dc848fe4b9..73b0e67122 100644 --- a/src/calibre/web/feeds/recipes/__init__.py +++ b/src/calibre/web/feeds/recipes/__init__.py @@ -40,7 +40,7 @@ recipe_modules = ['recipe_' + r for r in ( 'krstarica', 'krstarica_en', 'tanjug', 'laprensa_ni', 'azstarnet', 'corriere_della_sera_it', 'corriere_della_sera_en', 'msdnmag_en', 'moneynews', 'der_standard', 'diepresse', 'nzz_ger', 'hna', - 'seattle_times', 'scott_hanselman', 'coding_horror', + 'seattle_times', 'scott_hanselman', 'coding_horror', 'twitchfilms', 'stackoverflow', 'telepolis_artikel', 'zaobao', 'usnews', )] diff --git a/src/calibre/web/feeds/recipes/recipe_twitchfilms.py b/src/calibre/web/feeds/recipes/recipe_twitchfilms.py new file mode 100644 index 0000000000..dc0bcac88b --- /dev/null +++ b/src/calibre/web/feeds/recipes/recipe_twitchfilms.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +__license__ = 'GPL v3' +__copyright__ = '2009, Darko Miletic ' +''' +twitchfilm.net/site/ +''' +from calibre.web.feeds.news import BasicNewsRecipe +from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag + +class Twitchfilm(BasicNewsRecipe): + title = 'Twitch Films' + __author__ = 'Darko Miletic' + description = 'Twitch specializes in spreading the news on strange little films from around the world.' + oldest_article = 30 + max_articles_per_feed = 100 + no_stylesheets = True + use_embedded_content = True + encoding = 'utf-8' + publisher = 'Twitch' + category = 'twitch, twitchfilm, movie news, movie reviews, cult cinema, independent cinema, anime, foreign cinema, geek talk' + language = _('English') + + html2lrf_options = [ + '--comment', description + , '--category', category + , '--publisher', publisher + ] + + html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"' + + remove_tags = [dict(name='div', attrs={'class':'feedflare'})] + + feeds = [(u'News', u'http://feedproxy.google.com/TwitchEverything')] + + def preprocess_html(self, soup): + mtag = Tag(soup,'meta',[('http-equiv','Content-Type'),('context','text/html; charset=utf-8')]) + soup.head.insert(0,mtag) + soup.html['lang'] = 'en-US' + return soup + From 133d1d761baeb0bd8f24d0cb9409a0043337d85c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 2 May 2009 10:49:03 -0700 Subject: [PATCH 2/3] IGN:Fix timeout on windows when trying to open strage card --- src/calibre/devices/prs505/driver.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/prs505/driver.py b/src/calibre/devices/prs505/driver.py index b32c7e702e..00cb78b06b 100644 --- a/src/calibre/devices/prs505/driver.py +++ b/src/calibre/devices/prs505/driver.py @@ -251,7 +251,11 @@ class PRS505(Device): try: cachep = os.path.join(self._card_prefix, self.CACHE_XML) if not os.path.exists(cachep): - os.makedirs(os.path.dirname(cachep), mode=0777) + try: + os.makedirs(os.path.dirname(cachep), mode=0777) + except: + time.sleep(5) + os.makedirs(os.path.dirname(cachep), mode=0777) f = open(cachep, 'wb') f.write(u''' From 789061a7ae6885ae82b3dcef628a1864f01e5014 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 2 May 2009 11:10:29 -0700 Subject: [PATCH 3/3] Miscellaneous minor fixes. Add tags and series metadata to the book jacket, not just comments --- src/calibre/devices/prs505/driver.py | 42 +++++++++-------- src/calibre/ebooks/conversion/cli.py | 2 +- src/calibre/ebooks/conversion/plumber.py | 8 ++-- src/calibre/ebooks/oeb/transforms/jacket.py | 50 ++++++++++++++++----- src/calibre/linux.py | 1 - 5 files changed, 69 insertions(+), 34 deletions(-) diff --git a/src/calibre/devices/prs505/driver.py b/src/calibre/devices/prs505/driver.py index f569667ba1..702dd37592 100644 --- a/src/calibre/devices/prs505/driver.py +++ b/src/calibre/devices/prs505/driver.py @@ -4,15 +4,14 @@ __copyright__ = '2008, Kovid Goyal ' \ ''' Device driver for the SONY PRS-505 ''' -import sys, os, shutil, time, subprocess, re +import os, time from itertools import cycle from calibre.devices.usbms.cli import CLI from calibre.devices.usbms.device import Device from calibre.devices.errors import DeviceError, FreeSpaceError from calibre.devices.prs505.books import BookList, fix_ids -from calibre import iswindows, islinux, isosx, __appname__ -from calibre.devices.errors import PathError +from calibre import __appname__ class PRS505(CLI, Device): @@ -22,7 +21,7 @@ class PRS505(CLI, Device): supported_platforms = ['windows', 'osx', 'linux'] FORMATS = ['epub', 'lrf', 'lrx', 'rtf', 'pdf', 'txt'] - + VENDOR_ID = [0x054c] #: SONY Vendor Id PRODUCT_ID = [0x031e] #: Product Id for the PRS-505 BCD = [0x229] #: Needed to disambiguate 505 and 700 on linux @@ -46,27 +45,34 @@ class PRS505(CLI, Device): def open(self): Device.open(self) - + def write_cache(prefix): try: cachep = os.path.join(prefix, self.CACHE_XML) if not os.path.exists(cachep): - os.makedirs(os.path.dirname(cachep), mode=0777) - f = open(cachep, 'wb') - f.write(u''' - - -'''.encode('utf8')) - f.close() + try: + os.makedirs(os.path.dirname(cachep), mode=0777) + except: + time.sleep(5) + os.makedirs(os.path.dirname(cachep), mode=0777) + with open(cachep, 'wb') as f: + f.write(u''' + + + '''.encode('utf8')) + return True except: self._card_prefix = None import traceback traceback.print_exc() + return False if self._card_a_prefix is not None: - write_cache(self._card_a_prefix) + if not write_cache(self._card_a_prefix): + self._card_a_prefix = None if self._card_b_prefix is not None: - write_cache(self._card_b_prefix) + if not write_cache(self._card_b_prefix): + self._card_b_prefix = None def get_device_information(self, end_session=True): return (self.__class__.__name__, '', '', '') @@ -132,7 +138,7 @@ class PRS505(CLI, Device): if not hasattr(infile, 'read'): infile, close = open(infile, 'rb'), True infile.seek(0) - + newpath = path mdata = metadata.next() @@ -159,11 +165,11 @@ class PRS505(CLI, Device): paths.append(filepath) self.put_file(infile, paths[-1], replace_file=True) - + if close: infile.close() ctimes.append(os.path.getctime(paths[-1])) - + return zip(paths, sizes, ctimes, cycle([on_card])) @classmethod @@ -199,7 +205,7 @@ class PRS505(CLI, Device): f = open(self._main_prefix + self.__class__.MEDIA_XML, 'wb') booklists[0].write(f) f.close() - + def write_card_prefix(prefix, listid): if prefix is not None and hasattr(booklists[listid], 'write'): if not os.path.exists(prefix): diff --git a/src/calibre/ebooks/conversion/cli.py b/src/calibre/ebooks/conversion/cli.py index b165fbf8f4..53b1a2065d 100644 --- a/src/calibre/ebooks/conversion/cli.py +++ b/src/calibre/ebooks/conversion/cli.py @@ -128,7 +128,7 @@ def add_pipeline_options(parser, plumber): [ 'dont_split_on_page_breaks', 'chapter', 'chapter_mark', 'prefer_metadata_cover', 'remove_first_image', - 'insert_comments', 'page_breaks_before', + 'insert_metadata', 'page_breaks_before', ] ), diff --git a/src/calibre/ebooks/conversion/plumber.py b/src/calibre/ebooks/conversion/plumber.py index 9987ec0243..37611dcea7 100644 --- a/src/calibre/ebooks/conversion/plumber.py +++ b/src/calibre/ebooks/conversion/plumber.py @@ -300,11 +300,11 @@ OptionRecommendation(name='remove_first_image', ) ), -OptionRecommendation(name='insert_comments', +OptionRecommendation(name='insert_metadata', recommended_value=False, level=OptionRecommendation.LOW, - help=_('Insert the comments/summary from the book metadata at the start of ' + help=_('Insert the book metadata at the start of ' 'the book. This is useful if your ebook reader does not support ' - 'displaying the comments from the metadata.' + 'displaying/searching metadata directly.' ) ), @@ -607,7 +607,7 @@ OptionRecommendation(name='list_recipes', fkey = map(float, fkey.split(',')) from calibre.ebooks.oeb.transforms.jacket import Jacket - Jacket()(self.oeb, self.opts) + Jacket()(self.oeb, self.opts, self.user_metadata) pr(0.4) if self.opts.extra_css and os.path.exists(self.opts.extra_css): diff --git a/src/calibre/ebooks/oeb/transforms/jacket.py b/src/calibre/ebooks/oeb/transforms/jacket.py index c182faedfa..78f4ab871e 100644 --- a/src/calibre/ebooks/oeb/transforms/jacket.py +++ b/src/calibre/ebooks/oeb/transforms/jacket.py @@ -25,9 +25,13 @@ class Jacket(object): %(title)s -

%(title)s

-

%(jacket)s

-
+
+

%(title)s

+

%(jacket)s

+
%(series)s
+
%(tags)s
+
+
%(comments)s
@@ -46,21 +50,47 @@ class Jacket(object): img.getparent().remove(img) return - def insert_comments(self, comments): - self.log('Inserting metadata comments into book...') + def insert_metadata(self, mi): + self.log('Inserting metadata into book...') + comments = mi.comments + if not comments: + try: + comments = unicode(self.oeb.metadata.description[0]) + except: + comments = '' + if not comments.strip(): + comments = '' comments = comments.replace('\r\n', '\n').replace('\n\n', '

') + series = 'Series: ' + mi.series if mi.series else '' + if series and mi.series_index is not None: + series += ' [%s]'%mi.series_index + tags = mi.tags + if not tags: + try: + tags = map(unicode, self.oeb.metadata.subject) + except: + tags = [] + tags = u'/'.join(tags) + if tags: + tags = 'Tags: ' + u'/%s/'%tags + else: + tags = '' + try: + title = mi.title if mi.title else unicode(self.oeb.metadata.title[0]) + except: + title = _('Unknown') html = self.JACKET_TEMPLATE%dict(xmlns=XPNSMAP['h'], - title=self.opts.title, comments=comments, - jacket=_('Book Jacket')) + title=title, comments=comments, + jacket=_('Book Jacket'), series=series, tags=tags) id, href = self.oeb.manifest.generate('jacket', 'jacket.xhtml') root = etree.fromstring(html) item = self.oeb.manifest.add(id, href, guess_type(href)[0], data=root) self.oeb.spine.insert(0, item, True) - def __call__(self, oeb, opts): + def __call__(self, oeb, opts, metadata): self.oeb, self.opts, self.log = oeb, opts, oeb.log if opts.remove_first_image: self.remove_fisrt_image() - if opts.insert_comments and opts.comments: - self.insert_comments(opts.comments) + if opts.insert_metadata: + self.insert_metadata(metadata) diff --git a/src/calibre/linux.py b/src/calibre/linux.py index 1d641de51c..e6c0504316 100644 --- a/src/calibre/linux.py +++ b/src/calibre/linux.py @@ -5,7 +5,6 @@ import sys, os, shutil from subprocess import check_call, call from calibre import __version__, __appname__ -from calibre.devices import devices DEVICES = devices()