mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #3444 (More Information on Metadata page)
This commit is contained in:
parent
12eb3bf6a0
commit
145fb221d2
BIN
resources/images/star.png
Normal file
BIN
resources/images/star.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
@ -8,6 +8,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
from xml.sax.saxutils import escape
|
from xml.sax.saxutils import escape
|
||||||
|
from itertools import repeat
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ class Jacket(object):
|
|||||||
<h1 class="calibre_rescale_180">%(title)s</h1>
|
<h1 class="calibre_rescale_180">%(title)s</h1>
|
||||||
<h2 class="calibre_rescale_140">%(jacket)s</h2>
|
<h2 class="calibre_rescale_140">%(jacket)s</h2>
|
||||||
<div class="calibre_rescale_100">%(series)s</div>
|
<div class="calibre_rescale_100">%(series)s</div>
|
||||||
|
<div class="calibre_rescale_100">%(rating)s</div>
|
||||||
<div class="calibre_rescale_100">%(tags)s</div>
|
<div class="calibre_rescale_100">%(tags)s</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-top:2em" class="calibre_rescale_100">
|
<div style="margin-top:2em" class="calibre_rescale_100">
|
||||||
@ -54,6 +56,23 @@ class Jacket(object):
|
|||||||
img.getparent().remove(img)
|
img.getparent().remove(img)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def get_rating(self, rating):
|
||||||
|
ans = ''
|
||||||
|
if rating is None:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
num = float(rating)/2
|
||||||
|
except:
|
||||||
|
return ans
|
||||||
|
num = max(0, num)
|
||||||
|
num = min(num, 5)
|
||||||
|
if num < 1:
|
||||||
|
return ans
|
||||||
|
id, href = self.oeb.manifest.generate('star', 'star.png')
|
||||||
|
self.oeb.manifest.add(id, href, 'image/png', data=I('star.png', data=True))
|
||||||
|
ans = 'Rating: ' + ''.join(repeat('<img style="vertical-align:text-top" alt="star" src="%s" />'%href, num))
|
||||||
|
return ans
|
||||||
|
|
||||||
def insert_metadata(self, mi):
|
def insert_metadata(self, mi):
|
||||||
self.log('Inserting metadata into book...')
|
self.log('Inserting metadata into book...')
|
||||||
comments = mi.comments
|
comments = mi.comments
|
||||||
@ -87,7 +106,7 @@ class Jacket(object):
|
|||||||
html = self.JACKET_TEMPLATE%dict(xmlns=XPNSMAP['h'],
|
html = self.JACKET_TEMPLATE%dict(xmlns=XPNSMAP['h'],
|
||||||
title=escape(title), comments=escape(comments),
|
title=escape(title), comments=escape(comments),
|
||||||
jacket=escape(_('Book Jacket')), series=series,
|
jacket=escape(_('Book Jacket')), series=series,
|
||||||
tags=tags)
|
tags=tags, rating=self.get_rating(mi.rating))
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user