mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Also add the date added and published dates to the OPDS acquisition feeds
This commit is contained in:
parent
93c31cdaff
commit
72d735b41d
@ -22,7 +22,7 @@ from calibre.library.server import custom_fields_to_display
|
|||||||
from calibre.library.server.utils import format_tag_string, Offsets
|
from calibre.library.server.utils import format_tag_string, Offsets
|
||||||
from calibre import guess_type, prepare_string_for_xml as xml
|
from calibre import guess_type, prepare_string_for_xml as xml
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.date import as_utc
|
from calibre.utils.date import as_utc, is_date_undefined
|
||||||
|
|
||||||
BASE_HREFS = {
|
BASE_HREFS = {
|
||||||
0 : '/stanza',
|
0 : '/stanza',
|
||||||
@ -45,10 +45,11 @@ def unhexlify(x):
|
|||||||
return binascii.unhexlify(x).decode('utf-8')
|
return binascii.unhexlify(x).decode('utf-8')
|
||||||
|
|
||||||
# Vocabulary for building OPDS feeds {{{
|
# Vocabulary for building OPDS feeds {{{
|
||||||
|
DC_NS = 'http://purl.org/dc/terms/'
|
||||||
E = ElementMaker(namespace='http://www.w3.org/2005/Atom',
|
E = ElementMaker(namespace='http://www.w3.org/2005/Atom',
|
||||||
nsmap={
|
nsmap={
|
||||||
None : 'http://www.w3.org/2005/Atom',
|
None : 'http://www.w3.org/2005/Atom',
|
||||||
'dc' : 'http://purl.org/dc/terms/',
|
'dc' : DC_NS,
|
||||||
'opds' : 'http://opds-spec.org/2010/catalog',
|
'opds' : 'http://opds-spec.org/2010/catalog',
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -205,7 +206,10 @@ 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(item[FM['last_modified']]))
|
UPDATED(item[FM['last_modified']]), E.published(item[FM['timestamp']].isoformat()))
|
||||||
|
if mi.pubdate and not is_date_undefined(mi.pubdate):
|
||||||
|
ans.append(ans.makeelement('{%s}date' % DC_NS))
|
||||||
|
ans[-1].text = mi.pubdate.isoformat()
|
||||||
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']]
|
||||||
|
@ -20,7 +20,7 @@ from calibre.ebooks.metadata import fmt_sidx, authors_to_string
|
|||||||
from calibre.library.comments import comments_to_html
|
from calibre.library.comments import comments_to_html
|
||||||
from calibre import guess_type, prepare_string_for_xml as xml
|
from calibre import guess_type, prepare_string_for_xml as xml
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.date import as_utc, timestampfromdt
|
from calibre.utils.date import as_utc, timestampfromdt, is_date_undefined
|
||||||
|
|
||||||
from calibre.srv.errors import HTTPNotFound
|
from calibre.srv.errors import HTTPNotFound
|
||||||
from calibre.srv.routes import endpoint
|
from calibre.srv.routes import endpoint
|
||||||
@ -54,10 +54,11 @@ def format_tag_string(tags, sep, joinval=', '):
|
|||||||
return joinval.join(tlist) if tlist else ''
|
return joinval.join(tlist) if tlist else ''
|
||||||
|
|
||||||
# Vocabulary for building OPDS feeds {{{
|
# Vocabulary for building OPDS feeds {{{
|
||||||
|
DC_NS = 'http://purl.org/dc/terms/'
|
||||||
E = ElementMaker(namespace='http://www.w3.org/2005/Atom',
|
E = ElementMaker(namespace='http://www.w3.org/2005/Atom',
|
||||||
nsmap={
|
nsmap={
|
||||||
None : 'http://www.w3.org/2005/Atom',
|
None : 'http://www.w3.org/2005/Atom',
|
||||||
'dc' : 'http://purl.org/dc/terms/',
|
'dc' : DC_NS,
|
||||||
'opds' : 'http://opds-spec.org/2010/catalog',
|
'opds' : 'http://opds-spec.org/2010/catalog',
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -198,7 +199,11 @@ 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(mi.last_modified))
|
ans = E.entry(TITLE(mi.title), E.author(E.name(authors_to_string(mi.authors))), ID('urn:uuid:' + mi.uuid), UPDATED(mi.last_modified),
|
||||||
|
E.published(mi.timestamp.isoformat()))
|
||||||
|
if mi.pubdate and not is_date_undefined(mi.pubdate):
|
||||||
|
ans.append(ans.makeelement('{%s}date' % DC_NS))
|
||||||
|
ans[-1].text = mi.pubdate.isoformat()
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user