mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #2036 (Add PDB support to the Stanza content server)
This commit is contained in:
parent
5dd27c22e6
commit
e1b3302dcb
@ -31,6 +31,8 @@ mimetypes.add_type('application/adobe-page-template+xml', '.xpgt')
|
||||
mimetypes.add_type('application/x-font-opentype', '.otf')
|
||||
mimetypes.add_type('application/x-font-truetype', '.ttf')
|
||||
mimetypes.add_type('application/oebps-package+xml', '.opf')
|
||||
mimetypes.add_type('application/ereader', '.pdb')
|
||||
guess_type = mimetypes.guess_type
|
||||
import cssutils
|
||||
cssutils.log.setLevel(logging.WARN)
|
||||
|
||||
|
@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
|
||||
HTTP server for remote access to the calibre database.
|
||||
'''
|
||||
|
||||
import sys, textwrap, mimetypes, operator, os, re, logging
|
||||
import sys, textwrap, operator, os, re, logging
|
||||
from itertools import repeat
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from datetime import datetime
|
||||
@ -18,7 +18,7 @@ from PyQt4.Qt import QImage, QApplication, QByteArray, Qt, QBuffer
|
||||
|
||||
from calibre.constants import __version__, __appname__
|
||||
from calibre.utils.genshi.template import MarkupTemplate
|
||||
from calibre import fit_image
|
||||
from calibre import fit_image, guess_type
|
||||
from calibre.resources import jquery, server_resources, build_time
|
||||
from calibre.library import server_config as config
|
||||
from calibre.library.database2 import LibraryDatabase2, FIELD_MAP
|
||||
@ -77,7 +77,7 @@ class LibraryServer(object):
|
||||
<id>urn:calibre:${record[FM['id']]}</id>
|
||||
<author><name>${authors}</name></author>
|
||||
<updated>${record[FM['timestamp']].strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
||||
<link type="application/epub+zip" href="/get/epub/${record[FM['id']]}" />
|
||||
<link type="${mimetype}" href="/get/${fmt}/${record[FM['id']]}" />
|
||||
<link rel="x-stanza-cover-image" type="image/jpeg" href="/get/cover/${record[FM['id']]}" />
|
||||
<link rel="x-stanza-cover-image-thumbnail" type="image/jpeg" href="/get/thumb/${record[FM['id']]}" />
|
||||
<content type="xhtml">
|
||||
@ -218,7 +218,7 @@ class LibraryServer(object):
|
||||
fmt = self.db.format(id, format, index_is_id=True, as_file=True, mode='rb')
|
||||
if fmt is None:
|
||||
raise cherrypy.HTTPError(404, 'book: %d does not have format: %s'%(id, format))
|
||||
mt = mimetypes.guess_type('dummy.'+format.lower())[0]
|
||||
mt = guess_type('dummy.'+format.lower())[0]
|
||||
if mt is None:
|
||||
mt = 'application/octet-stream'
|
||||
cherrypy.response.headers['Content-Type'] = mt
|
||||
@ -258,8 +258,9 @@ class LibraryServer(object):
|
||||
for record in iter(self.db):
|
||||
r = record[FIELD_MAP['formats']]
|
||||
r = r.upper() if r else ''
|
||||
if 'EPUB' in r:
|
||||
authors = ' & '.join([i.replace('|', ',') for i in record[FIELD_MAP['authors']].split(',')])
|
||||
if 'EPUB' in r or 'PDB' in r:
|
||||
authors = ' & '.join([i.replace('|', ',') for i in
|
||||
record[FIELD_MAP['authors']].split(',')])
|
||||
extra = []
|
||||
rating = record[FIELD_MAP['rating']]
|
||||
if rating > 0:
|
||||
@ -270,12 +271,18 @@ class LibraryServer(object):
|
||||
extra.append('TAGS: %s<br />'%', '.join(tags.split(',')))
|
||||
series = record[FIELD_MAP['series']]
|
||||
if series:
|
||||
extra.append('SERIES: %s [%d]<br />'%(series, record[FIELD_MAP['series_index']]))
|
||||
books.append(self.STANZA_ENTRY.generate(authors=authors,
|
||||
record=record, FM=FIELD_MAP,
|
||||
port=self.opts.port,
|
||||
extra = ''.join(extra),
|
||||
).render('xml').decode('utf8'))
|
||||
extra.append('SERIES: %s [%d]<br />'%(series,
|
||||
record[FIELD_MAP['series_index']]))
|
||||
fmt = 'epub' if 'EPUB' in r else 'pdb'
|
||||
mimetype = guess_type('dummy.'+fmt)[0]
|
||||
books.append(self.STANZA_ENTRY.generate(
|
||||
authors=authors,
|
||||
record=record, FM=FIELD_MAP,
|
||||
port=self.opts.port,
|
||||
extra = ''.join(extra),
|
||||
mimetype=mimetype,
|
||||
fmt=fmt,
|
||||
).render('xml').decode('utf8'))
|
||||
|
||||
updated = self.db.last_modified()
|
||||
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
||||
|
Loading…
x
Reference in New Issue
Block a user