Sync to pluginize

This commit is contained in:
John Schember 2009-05-02 15:20:05 -04:00
commit 6b37352d09
7 changed files with 112 additions and 35 deletions

View File

@ -105,7 +105,7 @@ def debug_device_driver():
prefix = logical_disk.DeviceID+os.sep prefix = logical_disk.DeviceID+os.sep
drives.append((str(drive.PNPDeviceID), drive.Index, prefix)) drives.append((str(drive.PNPDeviceID), drive.Index, prefix))
except IndexError: except IndexError:
drives.append(str(drive.PNPDeviceID)) drives.append((str(drive.PNPDeviceID), 'No mount points found'))
for drive in drives: for drive in drives:
print '\t', drive print '\t', drive
from calibre.devices import devices from calibre.devices import devices

View File

@ -4,15 +4,14 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net> ' \
''' '''
Device driver for the SONY PRS-505 Device driver for the SONY PRS-505
''' '''
import sys, os, shutil, time, subprocess, re import os, time
from itertools import cycle from itertools import cycle
from calibre.devices.usbms.cli import CLI from calibre.devices.usbms.cli import CLI
from calibre.devices.usbms.device import Device from calibre.devices.usbms.device import Device
from calibre.devices.errors import DeviceError, FreeSpaceError from calibre.devices.errors import DeviceError, FreeSpaceError
from calibre.devices.prs505.books import BookList, fix_ids from calibre.devices.prs505.books import BookList, fix_ids
from calibre import iswindows, islinux, isosx, __appname__ from calibre import __appname__
from calibre.devices.errors import PathError
class PRS505(CLI, Device): class PRS505(CLI, Device):
@ -51,22 +50,29 @@ class PRS505(CLI, Device):
try: try:
cachep = os.path.join(prefix, self.CACHE_XML) cachep = os.path.join(prefix, self.CACHE_XML)
if not os.path.exists(cachep): if not os.path.exists(cachep):
os.makedirs(os.path.dirname(cachep), mode=0777) try:
f = open(cachep, 'wb') os.makedirs(os.path.dirname(cachep), mode=0777)
f.write(u'''<?xml version="1.0" encoding="UTF-8"?> except:
<cache xmlns="http://www.kinoma.com/FskCache/1"> time.sleep(5)
</cache> os.makedirs(os.path.dirname(cachep), mode=0777)
'''.encode('utf8')) with open(cachep, 'wb') as f:
f.close() f.write(u'''<?xml version="1.0" encoding="UTF-8"?>
<cache xmlns="http://www.kinoma.com/FskCache/1">
</cache>
'''.encode('utf8'))
return True
except: except:
self._card_prefix = None self._card_prefix = None
import traceback import traceback
traceback.print_exc() traceback.print_exc()
return False
if self._card_a_prefix is not None: 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: 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): def get_device_information(self, end_session=True):
return (self.__class__.__name__, '', '', '') return (self.__class__.__name__, '', '', '')

View File

@ -128,7 +128,7 @@ def add_pipeline_options(parser, plumber):
[ [
'dont_split_on_page_breaks', 'chapter', 'chapter_mark', 'dont_split_on_page_breaks', 'chapter', 'chapter_mark',
'prefer_metadata_cover', 'remove_first_image', 'prefer_metadata_cover', 'remove_first_image',
'insert_comments', 'page_breaks_before', 'insert_metadata', 'page_breaks_before',
] ]
), ),

View File

@ -304,11 +304,11 @@ OptionRecommendation(name='remove_first_image',
) )
), ),
OptionRecommendation(name='insert_comments', OptionRecommendation(name='insert_metadata',
recommended_value=False, level=OptionRecommendation.LOW, 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 ' 'the book. This is useful if your ebook reader does not support '
'displaying the comments from the metadata.' 'displaying/searching metadata directly.'
) )
), ),
@ -611,7 +611,7 @@ OptionRecommendation(name='list_recipes',
fkey = map(float, fkey.split(',')) fkey = map(float, fkey.split(','))
from calibre.ebooks.oeb.transforms.jacket import Jacket from calibre.ebooks.oeb.transforms.jacket import Jacket
Jacket()(self.oeb, self.opts) Jacket()(self.oeb, self.opts, self.user_metadata)
pr(0.4) pr(0.4)
if self.opts.extra_css and os.path.exists(self.opts.extra_css): if self.opts.extra_css and os.path.exists(self.opts.extra_css):

View File

@ -25,9 +25,13 @@ class Jacket(object):
<title>%(title)s</title> <title>%(title)s</title>
</head> </head>
<body> <body>
<h1 style="text-align: center">%(title)s</h1> <div style="text-align:center">
<h2 style="text-align: center">%(jacket)s</h2> <h1>%(title)s</h1>
<div> <h2>%(jacket)s</h2>
<div>%(series)s</div>
<div>%(tags)s</div>
</div>
<div style="margin-top:2em">
%(comments)s %(comments)s
</div> </div>
</body> </body>
@ -46,21 +50,47 @@ class Jacket(object):
img.getparent().remove(img) img.getparent().remove(img)
return return
def insert_comments(self, comments): def insert_metadata(self, mi):
self.log('Inserting metadata comments into book...') 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', '<br/><br/>') comments = comments.replace('\r\n', '\n').replace('\n\n', '<br/><br/>')
series = '<b>Series: </b>' + 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 = '<b>Tags: </b>' + 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'], html = self.JACKET_TEMPLATE%dict(xmlns=XPNSMAP['h'],
title=self.opts.title, comments=comments, title=title, comments=comments,
jacket=_('Book Jacket')) jacket=_('Book Jacket'), series=series, tags=tags)
id, href = self.oeb.manifest.generate('jacket', 'jacket.xhtml') id, href = self.oeb.manifest.generate('jacket', 'jacket.xhtml')
root = etree.fromstring(html) root = etree.fromstring(html)
item = self.oeb.manifest.add(id, href, guess_type(href)[0], data=root) item = self.oeb.manifest.add(id, href, guess_type(href)[0], data=root)
self.oeb.spine.insert(0, item, True) 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 self.oeb, self.opts, self.log = oeb, opts, oeb.log
if opts.remove_first_image: if opts.remove_first_image:
self.remove_fisrt_image() self.remove_fisrt_image()
if opts.insert_comments and opts.comments: if opts.insert_metadata:
self.insert_comments(opts.comments) self.insert_metadata(metadata)

View File

@ -40,7 +40,7 @@ recipe_modules = ['recipe_' + r for r in (
'krstarica', 'krstarica_en', 'tanjug', 'laprensa_ni', 'azstarnet', 'krstarica', 'krstarica_en', 'tanjug', 'laprensa_ni', 'azstarnet',
'corriere_della_sera_it', 'corriere_della_sera_en', 'msdnmag_en', 'corriere_della_sera_it', 'corriere_della_sera_en', 'msdnmag_en',
'moneynews', 'der_standard', 'diepresse', 'nzz_ger', 'hna', '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', 'stackoverflow', 'telepolis_artikel', 'zaobao', 'usnews',
)] )]

View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
__license__ = 'GPL v3'
__copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
'''
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