mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Miscellaneous minor fixes. Add tags and series metadata to the book jacket, not just comments
This commit is contained in:
parent
50c163d25d
commit
789061a7ae
@ -4,15 +4,14 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net> ' \
|
||||
'''
|
||||
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):
|
||||
|
||||
@ -51,22 +50,29 @@ class PRS505(CLI, Device):
|
||||
try:
|
||||
cachep = os.path.join(prefix, self.CACHE_XML)
|
||||
if not os.path.exists(cachep):
|
||||
try:
|
||||
os.makedirs(os.path.dirname(cachep), mode=0777)
|
||||
f = open(cachep, 'wb')
|
||||
except:
|
||||
time.sleep(5)
|
||||
os.makedirs(os.path.dirname(cachep), mode=0777)
|
||||
with open(cachep, 'wb') as f:
|
||||
f.write(u'''<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cache xmlns="http://www.kinoma.com/FskCache/1">
|
||||
</cache>
|
||||
'''.encode('utf8'))
|
||||
f.close()
|
||||
<cache xmlns="http://www.kinoma.com/FskCache/1">
|
||||
</cache>
|
||||
'''.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__, '', '', '')
|
||||
|
@ -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',
|
||||
]
|
||||
),
|
||||
|
||||
|
@ -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):
|
||||
|
@ -25,9 +25,13 @@ class Jacket(object):
|
||||
<title>%(title)s</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align: center">%(title)s</h1>
|
||||
<h2 style="text-align: center">%(jacket)s</h2>
|
||||
<div>
|
||||
<div style="text-align:center">
|
||||
<h1>%(title)s</h1>
|
||||
<h2>%(jacket)s</h2>
|
||||
<div>%(series)s</div>
|
||||
<div>%(tags)s</div>
|
||||
</div>
|
||||
<div style="margin-top:2em">
|
||||
%(comments)s
|
||||
</div>
|
||||
</body>
|
||||
@ -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', '<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'],
|
||||
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)
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user