From c6d1c186f0f78f55abc61dd7d038ca5a9daa81d1 Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Mon, 9 Jan 2017 21:18:49 +0100 Subject: [PATCH] Metadata viewing should work with calibre-companion now (#79) --- cps/templates/json.txt | 49 ++++++++++++++++++++++++++++++++++++++++++ cps/web.py | 12 +++++++++++ 2 files changed, 61 insertions(+) create mode 100644 cps/templates/json.txt diff --git a/cps/templates/json.txt b/cps/templates/json.txt new file mode 100644 index 00000000..4e327850 --- /dev/null +++ b/cps/templates/json.txt @@ -0,0 +1,49 @@ +{ + "pubdate": "{{entry.pubdate}}", + "title": "{{entry.title}}", + "format_metadata": { + {% for format in entry.data %} + "{{format.format}}": { + "mtime": "{{entry.last_modified}}", + "size": {{format.uncompressed_size}}, + "path": "/mnt/share/Data/alte_ebooks/Cornelia Ziegler/111 Orte auf Kreta die man gesehen haben muss (391)/111 Orte auf Kreta die man gesehen haben m - Cornelia Ziegler.epub" + }{% if not loop.last %},{% endif %} + {% endfor %} + }, + "formats": [ + {% for format in entry.data %} + "{{format.format}}"{% if not loop.last %},{% endif %} + {% endfor %} + ], + "series": null, + "cover": "/opds/cover/{{entry.id}}", + "languages": [ + {% for lang in entry.languages %} + "{{lang.lang_code}}"{% if not loop.last %},{% endif %} + {% endfor %} + ], + "comments": "{% if entry.comments|length > 0 %}{{entry.comments[0].text|safe}}{% endif %}", + "tags": [ + {% for tag in entry.tags %} + "{{tag.name}}"{% if not loop.last %},{% endif %} + {% endfor %} + ], + "application_id": {{entry.id}}, + "series_index": {% if entry.series|length > 0 %}"{{entry.series_index}}"{% else %}null{% endif %}, + "last_modified": "{{entry.last_modified}}", + "author_sort": "{{entry.author_sort}}", + "uuid": "{{entry.uuid}}", + "timestamp": "{{entry.timestamp}}", + "thumbnail": "/opds/cover/{{entry.id}}", + "main_format": { + "epub": "/get/epub/391" + }, + "rating": 0.0, + "authors": [ + {% for author in entry.authors %} + "{{author.name}}"{% if not loop.last %},{% endif %} + {% endfor %} + ], + "other_formats": {}, + "title_sort": "{{entry.sort}}" +} \ No newline at end of file diff --git a/cps/web.py b/cps/web.py index c39cde55..160a57f1 100755 --- a/cps/web.py +++ b/cps/web.py @@ -664,6 +664,17 @@ def get_opds_download_link(book_id, format): response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (data.name, format) return response +@app.route("/ajax/book/") +@login_required_if_no_ano +def get_metadata_calibre_companion(uuid): + entry = db.session.query(db.Books).filter(db.Books.uuid.like("%"+uuid+"%")).first() + if entry is not None : + js = render_template('json.txt',entry=entry) + response = make_response(js) + response.headers["Content-Type"] = "application/json" + return response + else: + return "" @app.route("/get_authors_json", methods=['GET', 'POST']) @login_required_if_no_ano @@ -1064,6 +1075,7 @@ def get_cover(cover_path): return send_from_directory(os.path.join(config.DB_ROOT, cover_path), "cover.jpg") @app.route("/opds/thumb_240_240/") +@app.route("/opds/cover_240_240/") @app.route("/opds/cover_90_90/") @app.route("/opds/cover/") @requires_basic_auth_if_no_ano