mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
c70556d3bc
@ -15,7 +15,8 @@ from binascii import hexlify, unhexlify
|
|||||||
import cherrypy
|
import cherrypy
|
||||||
|
|
||||||
from calibre.utils.date import isoformat
|
from calibre.utils.date import isoformat
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs, tweaks
|
||||||
|
from calibre.ebooks.metadata import title_sort
|
||||||
from calibre.ebooks.metadata.book.json_codec import JsonCodec
|
from calibre.ebooks.metadata.book.json_codec import JsonCodec
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.library.server import custom_fields_to_display
|
from calibre.library.server import custom_fields_to_display
|
||||||
@ -118,12 +119,16 @@ class AjaxServer(object):
|
|||||||
|
|
||||||
|
|
||||||
# Get book metadata {{{
|
# Get book metadata {{{
|
||||||
def ajax_book_to_json(self, book_id, get_category_urls=True):
|
def ajax_book_to_json(self, book_id, get_category_urls=True,
|
||||||
|
device_compatible=False):
|
||||||
mi = self.db.get_metadata(book_id, index_is_id=True)
|
mi = self.db.get_metadata(book_id, index_is_id=True)
|
||||||
|
|
||||||
|
if not device_compatible:
|
||||||
try:
|
try:
|
||||||
mi.rating = mi.rating/2.
|
mi.rating = mi.rating/2.
|
||||||
except:
|
except:
|
||||||
mi.rating = 0.0
|
mi.rating = 0.0
|
||||||
|
|
||||||
data = self.ajax_json_codec.encode_book_metadata(mi)
|
data = self.ajax_json_codec.encode_book_metadata(mi)
|
||||||
for x in ('publication_type', 'size', 'db_id', 'lpath', 'mime',
|
for x in ('publication_type', 'size', 'db_id', 'lpath', 'mime',
|
||||||
'rights', 'book_producer'):
|
'rights', 'book_producer'):
|
||||||
@ -131,6 +136,8 @@ class AjaxServer(object):
|
|||||||
|
|
||||||
data['cover'] = absurl(self.opts.url_prefix, u'/get/cover/%d'%book_id)
|
data['cover'] = absurl(self.opts.url_prefix, u'/get/cover/%d'%book_id)
|
||||||
data['thumbnail'] = absurl(self.opts.url_prefix, u'/get/thumb/%d'%book_id)
|
data['thumbnail'] = absurl(self.opts.url_prefix, u'/get/thumb/%d'%book_id)
|
||||||
|
|
||||||
|
if not device_compatible:
|
||||||
mi.format_metadata = {k.lower():dict(v) for k, v in
|
mi.format_metadata = {k.lower():dict(v) for k, v in
|
||||||
mi.format_metadata.iteritems()}
|
mi.format_metadata.iteritems()}
|
||||||
for v in mi.format_metadata.itervalues():
|
for v in mi.format_metadata.itervalues():
|
||||||
@ -177,11 +184,20 @@ class AjaxServer(object):
|
|||||||
unicode(tag.id))
|
unicode(tag.id))
|
||||||
break
|
break
|
||||||
category_urls[key] = dbtags
|
category_urls[key] = dbtags
|
||||||
|
else:
|
||||||
|
series = data.get('series', None)
|
||||||
|
if series:
|
||||||
|
tsorder = tweaks['save_template_title_series_sorting']
|
||||||
|
series = title_sort(series, order=tsorder)
|
||||||
|
else:
|
||||||
|
series = ''
|
||||||
|
data['_series_sort_'] = series
|
||||||
|
|
||||||
return data, mi.last_modified
|
return data, mi.last_modified
|
||||||
|
|
||||||
@Endpoint(set_last_modified=False)
|
@Endpoint(set_last_modified=False)
|
||||||
def ajax_book(self, book_id, category_urls='true', id_is_uuid='false'):
|
def ajax_book(self, book_id, category_urls='true', id_is_uuid='false',
|
||||||
|
device_compatible='false'):
|
||||||
'''
|
'''
|
||||||
Return the metadata of the book as a JSON dictionary.
|
Return the metadata of the book as a JSON dictionary.
|
||||||
|
|
||||||
@ -197,7 +213,8 @@ class AjaxServer(object):
|
|||||||
else:
|
else:
|
||||||
book_id = int(book_id)
|
book_id = int(book_id)
|
||||||
data, last_modified = self.ajax_book_to_json(book_id,
|
data, last_modified = self.ajax_book_to_json(book_id,
|
||||||
get_category_urls=category_urls.lower()=='true')
|
get_category_urls=category_urls.lower()=='true',
|
||||||
|
device_compatible=device_compatible.lower()=='true');
|
||||||
except:
|
except:
|
||||||
raise cherrypy.HTTPError(404, 'No book with id: %r'%book_id)
|
raise cherrypy.HTTPError(404, 'No book with id: %r'%book_id)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user