Improvements for OPDS on iOS with Bookari- and Chunky-Reader

pull/88/merge
OzzieIsaacs 8 years ago
parent 8494cb698c
commit a16321179d

@ -3,17 +3,19 @@
<id>urn:uuid:2853dacf-ed79-42f5-8e8a-a7bb3d1ae6a2</id> <id>urn:uuid:2853dacf-ed79-42f5-8e8a-a7bb3d1ae6a2</id>
<link rel="self" <link rel="self"
href="{{url_for('feed_index')}}" href="{{url_for('feed_index')}}"
type="application/atom+xml;profile=opds-catalog;kind=navigation"/> type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/>
<link rel="start" <link rel="start"
href="{{url_for('feed_index')}}" href="{{url_for('feed_index')}}"
type="application/atom+xml;profile=opds-catalog;kind=navigation"/> type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/>
<link rel="up" <link rel="up"
href="{{url_for('feed_index')}}" href="{{url_for('feed_index')}}"
type="application/atom+xml;profile=opds-catalog;kind=navigation"/> type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/>
{% if pagination.has_next %}
<link rel="next" <link rel="next"
title="{{_('Next')}}" title="{{_('Next')}}"
href="{{ next_url }}" href="{{ next_url }}"
type="application/atom+xml;profile=opds-catalog;kind=navigation"/> type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/>
{% endif %}
<link rel="search" <link rel="search"
href="{{url_for('feed_osd')}}" href="{{url_for('feed_osd')}}"
type="application/opensearchdescription+xml"/> type="application/opensearchdescription+xml"/>
@ -30,7 +32,6 @@
<updated>{{entry.timestamp}}</updated> <updated>{{entry.timestamp}}</updated>
<author> <author>
<name>{{entry.authors[0].name}}</name> <name>{{entry.authors[0].name}}</name>
<uri>{{entry.authors[0].name}}</uri>
</author> </author>
<language>{{entry.language}}</language> <language>{{entry.language}}</language>
{% for tag in entry.tags %} {% for tag in entry.tags %}
@ -38,17 +39,18 @@
term="{{tag.name}}" term="{{tag.name}}"
label="{{tag.name}}"/> label="{{tag.name}}"/>
{% endfor %} {% endfor %}
<summary>{% if entry.comments[0] %}{{entry.comments[0].text|striptags}}{% endif %}</summary> {% if entry.comments[0] %}<summary>{{entry.comments[0].text|striptags}}</summary>{% endif %}
{% if entry.has_cover %} {% if entry.has_cover %}
<link rel="http://opds-spec.org/image" href="{{ url_for('feed_get_cover', cover_path=entry.path) }}" type="image/jpg"/> <link type="image/jpeg" href="{{url_for('feed_get_cover', book_id=entry.id)}}" rel="http://opds-spec.org/image"/>
<link rel="http://opds-spec.org/cover" href="{{ url_for('feed_get_cover', cover_path=entry.path) }}" type="image/jpg"/> <link type="image/jpeg" href="{{url_for('feed_get_cover', book_id=entry.id)}}" rel="http://opds-spec.org/image/thumbnail"/>
<link rel="http://opds-spec.org/image/thumbnail" href="{{ url_for('feed_get_cover', cover_path=entry.path) }}" type="image/jpg"/>
{% endif %} {% endif %}
{% for format in entry.data %} {% for format in entry.data %}
<link rel="http://opds-spec.org/acquisition" href="{{ url_for('get_opds_download_link', book_id=entry.id, format=format.format|lower)}}" <link rel="http://opds-spec.org/acquisition" href="{{ url_for('get_opds_download_link', book_id=entry.id, format=format.format|lower)}}"
length="{{format.uncompressed_size}}" mtime="{{entry.timestamp}}" length="{{format.uncompressed_size}}" mtime="{{entry.timestamp}}"
{% if format.format|lower == "epub" %} {% if format.format|lower == "epub" %}
type="application/epub+zip"/> type="application/epub+zip"/>
{% elif format.format|lower == "cbr" %}
type="application/x-cbr"/>
{% else %} {% else %}
type="application/x-mobipocket-ebook"/> type="application/x-mobipocket-ebook"/>
{% endif %} {% endif %}
@ -59,7 +61,7 @@
<entry> <entry>
<title>{{author.name}}</title> <title>{{author.name}}</title>
<id>{{ url_for('feed_author', name=author.name) }}</id> <id>{{ url_for('feed_author', name=author.name) }}</id>
<link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_author', name=author.name)}}" /> <link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_author', name=author.name)}}"/>
<link type="application/atom+xml" href="{{url_for('feed_author', name=author.name)}}" rel="subsection"/> <link type="application/atom+xml" href="{{url_for('feed_author', name=author.name)}}" rel="subsection"/>
</entry> </entry>
{% endfor %} {% endfor %}
@ -67,7 +69,7 @@
<entry> <entry>
<title>{{entry.name}}</title> <title>{{entry.name}}</title>
<id>{{ url_for('feed_category', name=entry.name) }}</id> <id>{{ url_for('feed_category', name=entry.name) }}</id>
<link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_category', name=entry.name)}}" /> <link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_category', name=entry.name)}}"/>
<link type="application/atom+xml" href="{{url_for('feed_category', name=entry.name)}}" rel="subsection"/> <link type="application/atom+xml" href="{{url_for('feed_category', name=entry.name)}}" rel="subsection"/>
</entry> </entry>
{% endfor %} {% endfor %}

@ -27,28 +27,28 @@
</entry> </entry>
<entry> <entry>
<title>{{_('Random Books')}}</title> <title>{{_('Random Books')}}</title>
<link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_discover')}}" /> <link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_discover')}}"/>
<link rel="http://opds-spec.org/featured" href="{{url_for('feed_discover')}}" type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"/> <link rel="http://opds-spec.org/featured" href="{{url_for('feed_discover')}}" type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"/>
<id>{{url_for('feed_discover')}}</id> <id>{{url_for('feed_discover')}}</id>
<content type="text">{{_('Show Random Books')}}</content> <content type="text">{{_('Show Random Books')}}</content>
</entry> </entry>
<entry> <entry>
<title>{{_('Authors')}}</title> <title>{{_('Authors')}}</title>
<link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_authorindex')}}" /> <link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_authorindex')}}"/>
<link rel="subsection" href="{{url_for('feed_authorindex')}}" type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/> <link rel="subsection" href="{{url_for('feed_authorindex')}}" type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/>
<id>{{url_for('feed_authorindex')}}</id> <id>{{url_for('feed_authorindex')}}</id>
<content type="text">{{_('Books ordered by Author')}}</content> <content type="text">{{_('Books ordered by Author')}}</content>
</entry> </entry>
<entry> <entry>
<title>{{_('Category list')}}</title> <title>{{_('Category list')}}</title>
<link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_categoryindex')}}" /> <link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_categoryindex')}}"/>
<link rel="subsection" href="{{url_for('feed_categoryindex')}}" type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/> <link rel="subsection" href="{{url_for('feed_categoryindex')}}" type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/>
<id>{{url_for('feed_categoryindex')}}</id> <id>{{url_for('feed_categoryindex')}}</id>
<content type="text">{{_('Books ordered by category')}}</content> <content type="text">{{_('Books ordered by category')}}</content>
</entry> </entry>
<entry> <entry>
<title>{{_('Series list')}}</title> <title>{{_('Series list')}}</title>
<link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_seriesindex')}}" /> <link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_seriesindex')}}"/>
<link rel="subsection" href="{{url_for('feed_seriesindex')}}" type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/> <link rel="subsection" href="{{url_for('feed_seriesindex')}}" type="application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"/>
<id>{{url_for('feed_seriesindex')}}</id> <id>{{url_for('feed_seriesindex')}}</id>
<content type="text">{{_('Books ordered by series')}}</content> <content type="text">{{_('Books ordered by series')}}</content>

@ -472,7 +472,9 @@ def feed_new():
off = 0 off = 0
entries = db.session.query(db.Books).filter(filter).order_by(db.Books.timestamp.desc()).offset(off).limit( entries = db.session.query(db.Books).filter(filter).order_by(db.Books.timestamp.desc()).offset(off).limit(
config.NEWEST_BOOKS) config.NEWEST_BOOKS)
xml = render_template('feed.xml', entries=entries, pagination = Pagination((int(off)/(int(config.NEWEST_BOOKS))+1), config.NEWEST_BOOKS,
len(db.session.query(db.Books).filter(filter).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination,
next_url="/opds/new?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off))) next_url="/opds/new?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off)))
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -482,16 +484,17 @@ def feed_new():
@app.route("/opds/discover") @app.route("/opds/discover")
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_discover(): def feed_discover():
off = request.args.get("start_index") # off = request.args.get("start_index")
if current_user.filter_language() != "all": if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()) filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else: else:
filter = True filter = True
if not off: # if not off:
off = 0 # off = 0
entries = db.session.query(db.Books).filter(filter).order_by(func.random()).offset(off).limit(config.NEWEST_BOOKS) entries = db.session.query(db.Books).filter(filter).order_by(func.random()).limit(config.NEWEST_BOOKS)
xml = render_template('feed.xml', entries=entries, pagination = Pagination(1, config.NEWEST_BOOKS,int(config.NEWEST_BOOKS))
next_url="/opds/discover?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off))) xml = render_template('feed.xml', entries=entries, pagination=pagination,
next_url="/opds/discover")
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -509,8 +512,9 @@ def feed_hot():
off = 0 off = 0
entries = db.session.query(db.Books).filter(filter).filter(db.Books.ratings.any(db.Ratings.rating > 9)).offset( entries = db.session.query(db.Books).filter(filter).filter(db.Books.ratings.any(db.Ratings.rating > 9)).offset(
off).limit(config.NEWEST_BOOKS) off).limit(config.NEWEST_BOOKS)
pagination = Pagination((int(off)/(int(config.NEWEST_BOOKS))+1), config.NEWEST_BOOKS,
xml = render_template('feed.xml', entries=entries, len(db.session.query(db.Books).filter(filter).filter(db.Books.ratings.any(db.Ratings.rating > 9)).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination,
next_url="/opds/hot?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off))) next_url="/opds/hot?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off)))
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -521,6 +525,7 @@ def feed_hot():
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_authorindex(): def feed_authorindex():
off = request.args.get("start_index") off = request.args.get("start_index")
# ToDo: Language filter not working
if current_user.filter_language() != "all": if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()) filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else: else:
@ -528,7 +533,9 @@ def feed_authorindex():
if not off: if not off:
off = 0 off = 0
authors = db.session.query(db.Authors).order_by(db.Authors.sort).offset(off).limit(config.NEWEST_BOOKS) authors = db.session.query(db.Authors).order_by(db.Authors.sort).offset(off).limit(config.NEWEST_BOOKS)
xml = render_template('feed.xml', authors=authors, pagination = Pagination((int(off)/(int(config.NEWEST_BOOKS))+1), config.NEWEST_BOOKS,
len(db.session.query(db.Authors).all()))
xml = render_template('feed.xml', authors=authors, pagination=pagination,
next_url="/opds/author?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off))) next_url="/opds/author?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off)))
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -547,7 +554,9 @@ def feed_author(name):
off = 0 off = 0
entries = db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.name.like("%" + name + "%"))).filter( entries = db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.name.like("%" + name + "%"))).filter(
filter).offset(off).limit(config.NEWEST_BOOKS) filter).offset(off).limit(config.NEWEST_BOOKS)
xml = render_template('feed.xml', entries=entries, pagination = Pagination((int(off)/(int(config.NEWEST_BOOKS))+1), config.NEWEST_BOOKS,
len(db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.name.like("%" + name + "%"))).filter(filter).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination,
next_url="/opds/author?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off))) next_url="/opds/author?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off)))
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -561,7 +570,9 @@ def feed_categoryindex():
if not off: if not off:
off = 0 off = 0
entries = db.session.query(db.Tags).order_by(db.Tags.name).offset(off).limit(config.NEWEST_BOOKS) entries = db.session.query(db.Tags).order_by(db.Tags.name).offset(off).limit(config.NEWEST_BOOKS)
xml = render_template('feed.xml', categorys=entries, pagination = Pagination((int(off)/(int(config.NEWEST_BOOKS))+1), config.NEWEST_BOOKS,
len(db.session.query(db.Tags).all()))
xml = render_template('feed.xml', categorys=entries, pagination=pagination,
next_url="/opds/category?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off))) next_url="/opds/category?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off)))
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -580,7 +591,9 @@ def feed_category(name):
off = 0 off = 0
entries = db.session.query(db.Books).filter(db.Books.tags.any(db.Tags.name.like("%" + name + "%"))).order_by( entries = db.session.query(db.Books).filter(db.Books.tags.any(db.Tags.name.like("%" + name + "%"))).order_by(
db.Books.timestamp.desc()).filter(filter).offset(off).limit(config.NEWEST_BOOKS) db.Books.timestamp.desc()).filter(filter).offset(off).limit(config.NEWEST_BOOKS)
xml = render_template('feed.xml', entries=entries, pagination = Pagination((int(off)/(int(config.NEWEST_BOOKS))+1), config.NEWEST_BOOKS,
len(db.session.query(db.Books).filter(db.Books.tags.any(db.Tags.name.like("%" + name + "%"))).filter(filter).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination,
next_url="/opds/category?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off))) next_url="/opds/category?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off)))
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -591,10 +604,16 @@ def feed_category(name):
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_seriesindex(): def feed_seriesindex():
off = request.args.get("start_index") off = request.args.get("start_index")
if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else:
filter = True
if not off: if not off:
off = 0 off = 0
entries = db.session.query(db.Series).order_by(db.Series.name).offset(off).limit(config.NEWEST_BOOKS) entries = db.session.query(db.Series).order_by(db.Series.name).offset(off).limit(config.NEWEST_BOOKS)
xml = render_template('feed.xml', series=entries, pagination = Pagination((int(off)/(int(config.NEWEST_BOOKS))+1), config.NEWEST_BOOKS,
len(db.session.query(db.Series).all()))
xml = render_template('feed.xml', series=entries, pagination=pagination,
next_url="/opds/series?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off))) next_url="/opds/series?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off)))
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -613,7 +632,9 @@ def feed_series(name):
off = 0 off = 0
entries = db.session.query(db.Books).filter(db.Books.series.any(db.Series.name.like("%" + name + "%"))).order_by( entries = db.session.query(db.Books).filter(db.Books.series.any(db.Series.name.like("%" + name + "%"))).order_by(
db.Books.timestamp.desc()).filter(filter).offset(off).limit(config.NEWEST_BOOKS) db.Books.timestamp.desc()).filter(filter).offset(off).limit(config.NEWEST_BOOKS)
xml = render_template('feed.xml', entries=entries, pagination = Pagination((int(off)/(int(config.NEWEST_BOOKS))+1), config.NEWEST_BOOKS,
len(db.session.query(db.Books).filter(db.Books.series.any(db.Series.name.like("%" + name + "%"))).filter(filter).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination,
next_url="/opds/series?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off))) next_url="/opds/series?start_index=%d" % (int(config.NEWEST_BOOKS) + int(off)))
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -1037,10 +1058,11 @@ def get_cover(cover_path):
return send_from_directory(os.path.join(config.DB_ROOT, cover_path), "cover.jpg") return send_from_directory(os.path.join(config.DB_ROOT, cover_path), "cover.jpg")
@app.route("/opds/cover/<path:cover_path>") @app.route("/opds/cover/<path:book_id>")
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_get_cover(cover_path): def feed_get_cover(book_id):
return send_from_directory(os.path.join(config.DB_ROOT, cover_path), "cover.jpg") book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
return send_from_directory(os.path.join(config.DB_ROOT, book.path), "cover.jpg")
@app.route("/read/<int:book_id>/<format>") @app.route("/read/<int:book_id>/<format>")

Loading…
Cancel
Save