mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Content server: Add more descriptive titles to the OPDS feeds, where possible
This commit is contained in:
parent
97b222caca
commit
144d673004
@ -231,17 +231,19 @@ def ACQUISITION_ENTRY(item, version, db, updated, CFM, CKEYS, prefix):
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
default_feed_title = __appname__ + ' ' + _('Library')
|
||||||
|
|
||||||
class Feed(object): # {{{
|
class Feed(object): # {{{
|
||||||
|
|
||||||
def __init__(self, id_, updated, version, subtitle=None,
|
def __init__(self, id_, updated, version, subtitle=None,
|
||||||
title=__appname__ + ' ' + _('Library'),
|
title=None,
|
||||||
up_link=None, first_link=None, last_link=None,
|
up_link=None, first_link=None, last_link=None,
|
||||||
next_link=None, previous_link=None):
|
next_link=None, previous_link=None):
|
||||||
self.base_href = url_for('opds', version)
|
self.base_href = url_for('opds', version)
|
||||||
|
|
||||||
self.root = \
|
self.root = \
|
||||||
FEED(
|
FEED(
|
||||||
TITLE(title),
|
TITLE(title or default_feed_title),
|
||||||
AUTHOR(__appname__, uri='http://calibre-ebook.com'),
|
AUTHOR(__appname__, uri='http://calibre-ebook.com'),
|
||||||
ID(id_),
|
ID(id_),
|
||||||
ICON('/favicon.png'),
|
ICON('/favicon.png'),
|
||||||
@ -289,7 +291,7 @@ class TopLevel(Feed): # {{{
|
|||||||
|
|
||||||
class NavFeed(Feed):
|
class NavFeed(Feed):
|
||||||
|
|
||||||
def __init__(self, id_, updated, version, offsets, page_url, up_url):
|
def __init__(self, id_, updated, version, offsets, page_url, up_url, title=None):
|
||||||
kwargs = {'up_link': up_url}
|
kwargs = {'up_link': up_url}
|
||||||
kwargs['first_link'] = page_url
|
kwargs['first_link'] = page_url
|
||||||
kwargs['last_link'] = page_url+'?offset=%d'%offsets.last_offset
|
kwargs['last_link'] = page_url+'?offset=%d'%offsets.last_offset
|
||||||
@ -299,13 +301,15 @@ class NavFeed(Feed):
|
|||||||
if offsets.next_offset > -1:
|
if offsets.next_offset > -1:
|
||||||
kwargs['next_link'] = \
|
kwargs['next_link'] = \
|
||||||
page_url+'?offset=%d'%offsets.next_offset
|
page_url+'?offset=%d'%offsets.next_offset
|
||||||
|
if title:
|
||||||
|
kwargs['title'] = title
|
||||||
Feed.__init__(self, id_, updated, version, **kwargs)
|
Feed.__init__(self, id_, updated, version, **kwargs)
|
||||||
|
|
||||||
class AcquisitionFeed(NavFeed):
|
class AcquisitionFeed(NavFeed):
|
||||||
|
|
||||||
def __init__(self, updated, id_, items, offsets, page_url, up_url, version,
|
def __init__(self, updated, id_, items, offsets, page_url, up_url, version,
|
||||||
db, prefix):
|
db, prefix, title=None):
|
||||||
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url)
|
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url, title=title)
|
||||||
CFM = db.field_metadata
|
CFM = db.field_metadata
|
||||||
CKEYS = [key for key in sorted(custom_fields_to_display(db),
|
CKEYS = [key for key in sorted(custom_fields_to_display(db),
|
||||||
key=lambda x: sort_key(CFM[x]['name']))]
|
key=lambda x: sort_key(CFM[x]['name']))]
|
||||||
@ -315,8 +319,8 @@ class AcquisitionFeed(NavFeed):
|
|||||||
|
|
||||||
class CategoryFeed(NavFeed):
|
class CategoryFeed(NavFeed):
|
||||||
|
|
||||||
def __init__(self, items, which, id_, updated, version, offsets, page_url, up_url, db):
|
def __init__(self, items, which, id_, updated, version, offsets, page_url, up_url, db, title=None):
|
||||||
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url)
|
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url, title=title)
|
||||||
base_href = self.base_href + '/category/' + hexlify(which)
|
base_href = self.base_href + '/category/' + hexlify(which)
|
||||||
ignore_count = False
|
ignore_count = False
|
||||||
if which == 'search':
|
if which == 'search':
|
||||||
@ -328,8 +332,8 @@ class CategoryFeed(NavFeed):
|
|||||||
|
|
||||||
class CategoryGroupFeed(NavFeed):
|
class CategoryGroupFeed(NavFeed):
|
||||||
|
|
||||||
def __init__(self, items, which, id_, updated, version, offsets, page_url, up_url):
|
def __init__(self, items, which, id_, updated, version, offsets, page_url, up_url, title=None):
|
||||||
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url)
|
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url, title=title)
|
||||||
base_href = self.base_href + '/categorygroup/' + hexlify(which)
|
base_href = self.base_href + '/categorygroup/' + hexlify(which)
|
||||||
for item in items:
|
for item in items:
|
||||||
self.root.append(CATALOG_GROUP_ENTRY(item, which, base_href, version, updated))
|
self.root.append(CATALOG_GROUP_ENTRY(item, which, base_href, version, updated))
|
||||||
@ -359,7 +363,7 @@ class OPDSServer(object):
|
|||||||
return ids
|
return ids
|
||||||
|
|
||||||
def get_opds_acquisition_feed(self, ids, offset, page_url, up_url, id_,
|
def get_opds_acquisition_feed(self, ids, offset, page_url, up_url, id_,
|
||||||
sort_by='title', ascending=True, version=0):
|
sort_by='title', ascending=True, version=0, feed_title=None):
|
||||||
idx = self.db.FIELD_MAP['id']
|
idx = self.db.FIELD_MAP['id']
|
||||||
ids &= self.get_opds_allowed_ids_for_version(version)
|
ids &= self.get_opds_allowed_ids_for_version(version)
|
||||||
if not ids:
|
if not ids:
|
||||||
@ -374,7 +378,7 @@ class OPDSServer(object):
|
|||||||
cherrypy.response.headers['Content-Type'] = 'application/atom+xml;profile=opds-catalog'
|
cherrypy.response.headers['Content-Type'] = 'application/atom+xml;profile=opds-catalog'
|
||||||
return str(AcquisitionFeed(updated, id_, items, offsets,
|
return str(AcquisitionFeed(updated, id_, items, offsets,
|
||||||
page_url, up_url, version, self.db,
|
page_url, up_url, version, self.db,
|
||||||
self.opts.url_prefix))
|
self.opts.url_prefix, title=feed_title))
|
||||||
|
|
||||||
def opds_search(self, query=None, version=0, offset=0):
|
def opds_search(self, query=None, version=0, offset=0):
|
||||||
try:
|
try:
|
||||||
@ -403,10 +407,12 @@ class OPDSServer(object):
|
|||||||
raise cherrypy.HTTPError(404, 'Not found')
|
raise cherrypy.HTTPError(404, 'Not found')
|
||||||
sort = 'timestamp' if which == 'newest' else 'title'
|
sort = 'timestamp' if which == 'newest' else 'title'
|
||||||
ascending = which == 'title'
|
ascending = which == 'title'
|
||||||
|
feed_title = {'newest':_('Newest'), 'title': _('Title')}.get(which, which)
|
||||||
|
feed_title = default_feed_title + ' :: ' + _('By %s') % feed_title
|
||||||
ids = self.get_opds_allowed_ids_for_version(version)
|
ids = self.get_opds_allowed_ids_for_version(version)
|
||||||
return self.get_opds_acquisition_feed(ids, offset, page_url, up_url,
|
return self.get_opds_acquisition_feed(ids, offset, page_url, up_url,
|
||||||
id_='calibre-all:'+sort, sort_by=sort, ascending=ascending,
|
id_='calibre-all:'+sort, sort_by=sort, ascending=ascending,
|
||||||
version=version)
|
version=version, feed_title=feed_title)
|
||||||
|
|
||||||
# Categories {{{
|
# Categories {{{
|
||||||
|
|
||||||
@ -427,7 +433,11 @@ class OPDSServer(object):
|
|||||||
category = unhexlify(category)
|
category = unhexlify(category)
|
||||||
if category not in categories:
|
if category not in categories:
|
||||||
raise cherrypy.HTTPError(404, 'Category %r not found'%which)
|
raise cherrypy.HTTPError(404, 'Category %r not found'%which)
|
||||||
|
category_meta = self.db.field_metadata
|
||||||
|
meta = category_meta.get(category, {})
|
||||||
|
category_name = meta.get('name', which)
|
||||||
which = unhexlify(which)
|
which = unhexlify(which)
|
||||||
|
feed_title = default_feed_title + ' :: ' + _('By %s :: %s') % (category_name, which)
|
||||||
owhich = hexlify('N'+which)
|
owhich = hexlify('N'+which)
|
||||||
up_url = url_for('opdsnavcatalog', version, which=owhich)
|
up_url = url_for('opdsnavcatalog', version, which=owhich)
|
||||||
items = categories[category]
|
items = categories[category]
|
||||||
@ -449,7 +459,7 @@ class OPDSServer(object):
|
|||||||
cherrypy.response.headers['Content-Type'] = 'application/atom+xml'
|
cherrypy.response.headers['Content-Type'] = 'application/atom+xml'
|
||||||
|
|
||||||
return str(CategoryFeed(items, category, id_, updated, version, offsets,
|
return str(CategoryFeed(items, category, id_, updated, version, offsets,
|
||||||
page_url, up_url, self.db))
|
page_url, up_url, self.db, title=feed_title))
|
||||||
|
|
||||||
def opds_navcatalog(self, which=None, version=0, offset=0):
|
def opds_navcatalog(self, which=None, version=0, offset=0):
|
||||||
try:
|
try:
|
||||||
@ -481,6 +491,10 @@ class OPDSServer(object):
|
|||||||
|
|
||||||
items = categories[which]
|
items = categories[which]
|
||||||
updated = self.db.last_modified()
|
updated = self.db.last_modified()
|
||||||
|
category_meta = self.db.field_metadata
|
||||||
|
meta = category_meta.get(which, {})
|
||||||
|
category_name = meta.get('name', which)
|
||||||
|
feed_title = default_feed_title + ' :: ' + _('By %s') % category_name
|
||||||
|
|
||||||
id_ = 'calibre-category-feed:'+which
|
id_ = 'calibre-category-feed:'+which
|
||||||
|
|
||||||
@ -491,7 +505,7 @@ class OPDSServer(object):
|
|||||||
offsets = Offsets(offset, max_items, len(items))
|
offsets = Offsets(offset, max_items, len(items))
|
||||||
items = list(items)[offsets.offset:offsets.offset+max_items]
|
items = list(items)[offsets.offset:offsets.offset+max_items]
|
||||||
ans = CategoryFeed(items, which, id_, updated, version, offsets,
|
ans = CategoryFeed(items, which, id_, updated, version, offsets,
|
||||||
page_url, up_url, self.db)
|
page_url, up_url, self.db, title=feed_title)
|
||||||
else:
|
else:
|
||||||
class Group:
|
class Group:
|
||||||
def __init__(self, text, count):
|
def __init__(self, text, count):
|
||||||
@ -512,7 +526,7 @@ class OPDSServer(object):
|
|||||||
offsets = Offsets(offset, max_items, len(items))
|
offsets = Offsets(offset, max_items, len(items))
|
||||||
items = items[offsets.offset:offsets.offset+max_items]
|
items = items[offsets.offset:offsets.offset+max_items]
|
||||||
ans = CategoryGroupFeed(items, which, id_, updated, version, offsets,
|
ans = CategoryGroupFeed(items, which, id_, updated, version, offsets,
|
||||||
page_url, up_url)
|
page_url, up_url, title=feed_title)
|
||||||
|
|
||||||
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
||||||
cherrypy.response.headers['Content-Type'] = 'application/atom+xml'
|
cherrypy.response.headers['Content-Type'] = 'application/atom+xml'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user