Content server: OPDS feeds: Change the value of <updated> for entries in the acquisition feed to be the last modified date for the book. Also make the size and last modified timestamp available as attributes in the acquisition links.

This commit is contained in:
Kovid Goyal 2016-09-03 23:38:48 +05:30
parent 62ea49ad02
commit 93c31cdaff
2 changed files with 15 additions and 4 deletions

View File

@ -205,19 +205,24 @@ def ACQUISITION_ENTRY(item, version, db, updated, CFM, CKEYS, prefix):
idm = 'calibre' if version == 0 else 'uuid' idm = 'calibre' if version == 0 else 'uuid'
id_ = 'urn:%s:%s'%(idm, item[FM['uuid']]) id_ = 'urn:%s:%s'%(idm, item[FM['uuid']])
ans = E.entry(TITLE(title), E.author(E.name(authors)), ID(id_), ans = E.entry(TITLE(title), E.author(E.name(authors)), ID(id_),
UPDATED(updated)) UPDATED(item[FM['last_modified']]))
if len(extra): if len(extra):
ans.append(E.content(extra, type='xhtml')) ans.append(E.content(extra, type='xhtml'))
formats = item[FM['formats']] formats = item[FM['formats']]
if formats: if formats:
book_id = item[FM['id']]
for fmt in formats.split(','): for fmt in formats.split(','):
fmt = fmt.lower() fmt = fmt.lower()
mt = guess_type('a.'+fmt)[0] mt = guess_type('a.'+fmt)[0]
href = prefix + '/get/%s/%s'%(fmt, item[FM['id']]) href = prefix + '/get/%s/%s'%(fmt, book_id)
if mt: if mt:
link = E.link(type=mt, href=href) link = E.link(type=mt, href=href)
if version > 0: if version > 0:
link.set('rel', "http://opds-spec.org/acquisition") link.set('rel', "http://opds-spec.org/acquisition")
fm = db.format_metadata(book_id, fmt)
if fm:
link.set('length', str(fm['size']))
link.set('mtime', fm['mtime'].isoformat())
ans.append(link) ans.append(link)
ans.append(E.link(type='image/jpeg', href=prefix+'/get/cover/%s'%item[FM['id']], ans.append(E.link(type='image/jpeg', href=prefix+'/get/cover/%s'%item[FM['id']],
rel="x-stanza-cover-image" if version == 0 else rel="x-stanza-cover-image" if version == 0 else

View File

@ -198,16 +198,22 @@ def ACQUISITION_ENTRY(book_id, updated, request_context):
extra.append(comments) extra.append(comments)
if extra: if extra:
extra = html_to_lxml('\n'.join(extra)) extra = html_to_lxml('\n'.join(extra))
ans = E.entry(TITLE(mi.title), E.author(E.name(authors_to_string(mi.authors))), ID('urn:uuid:' + mi.uuid), UPDATED(updated)) ans = E.entry(TITLE(mi.title), E.author(E.name(authors_to_string(mi.authors))), ID('urn:uuid:' + mi.uuid), UPDATED(mi.last_modified))
if len(extra): if len(extra):
ans.append(E.content(extra, type='xhtml')) ans.append(E.content(extra, type='xhtml'))
get = partial(request_context.ctx.url_for, '/get', book_id=book_id, library_id=request_context.library_id) get = partial(request_context.ctx.url_for, '/get', book_id=book_id, library_id=request_context.library_id)
if mi.formats: if mi.formats:
fm = mi.format_metadata
for fmt in mi.formats: for fmt in mi.formats:
fmt = fmt.lower() fmt = fmt.lower()
mt = guess_type('a.'+fmt)[0] mt = guess_type('a.'+fmt)[0]
if mt: if mt:
ans.append(E.link(type=mt, href=get(what=fmt), rel="http://opds-spec.org/acquisition")) link = E.link(type=mt, href=get(what=fmt), rel="http://opds-spec.org/acquisition")
ffm = fm.get(fmt.upper())
if ffm:
link.set('length', str(ffm['size']))
link.set('mtime', ffm['mtime'].isoformat())
ans.append(link)
ans.append(E.link(type='image/jpeg', href=get(what='cover'), rel="http://opds-spec.org/cover")) ans.append(E.link(type='image/jpeg', href=get(what='cover'), rel="http://opds-spec.org/cover"))
ans.append(E.link(type='image/jpeg', href=get(what='thumb'), rel="http://opds-spec.org/thumbnail")) ans.append(E.link(type='image/jpeg', href=get(what='thumb'), rel="http://opds-spec.org/thumbnail"))