From ecd027abb95de5d408a8e6da9e2535f8bc5b0cad Mon Sep 17 00:00:00 2001 From: Josh Hadro Date: Thu, 5 Oct 2023 15:40:08 -0400 Subject: [PATCH 1/9] Try adding helper --- iiify/app.py | 11 +++++++++++ iiify/templates/helper.html | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 iiify/templates/helper.html diff --git a/iiify/app.py b/iiify/app.py index 91a3b49..9a5c778 100755 --- a/iiify/app.py +++ b/iiify/app.py @@ -77,6 +77,17 @@ def demo(): def documentation(): return render_template('docs/index.html', version=version) +@app.route('/iiif/helper/') +def helper(identifier): + domain = purify_domain(request.args.get('domain', request.url_root)) + uri = '%s%s' % (domain, identifier) + try: + cantaloupe_id = cantaloupe_resolver(identifier) + info_url = f"{image_server}/3/{cantaloupe_id}/info.json" + image_url = f"{image_server}/3/{cantaloupe_id}/full/max/0/default.jpg" + return render_template('helper.html', domain=domain, uri=uri, info_url=info_url, image_url=image_url, identifier=identifier) + except ValueError: + abort(404) @app.route('/iiif/') def view(identifier): diff --git a/iiify/templates/helper.html b/iiify/templates/helper.html new file mode 100644 index 0000000..d3d2ee9 --- /dev/null +++ b/iiify/templates/helper.html @@ -0,0 +1,27 @@ + + + + + IIIF Image and Presentation API Helper + + + + + + +

The IA identifier is: {{ identifier }}

+

The IA item page URL is: https://archive.org/details/{{ identifier }}

+

The manifest URL is: {{ uri }}/manifest.json

+

The Image API URL for the full image is: {{image_url}}

+

The Image API info.json for the image is: {{info_url}}

+ +
+ +{{ cantaloupe_id }} +

The Image API URL for the full image is: https://iiif.prod.archive.org/image/iiif/3/{{ cantaloupe_id }}/full/max/0/default.jpg

+

The Image API info.json for the image is: https://iiif.prod.archive.org/image/iiif/3/{{ cantaloupe_id }}/info.json

+ + + From 4c6ada5fdbb50387d82bc4420ee9e2ef0a4f90b8 Mon Sep 17 00:00:00 2001 From: Josh Hadro Date: Thu, 5 Oct 2023 15:50:36 -0400 Subject: [PATCH 2/9] Tweak helper --- iiify/app.py | 4 +--- iiify/templates/helper.html | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/iiify/app.py b/iiify/app.py index 9a5c778..006f79a 100755 --- a/iiify/app.py +++ b/iiify/app.py @@ -79,13 +79,11 @@ def documentation(): @app.route('/iiif/helper/') def helper(identifier): - domain = purify_domain(request.args.get('domain', request.url_root)) - uri = '%s%s' % (domain, identifier) try: cantaloupe_id = cantaloupe_resolver(identifier) info_url = f"{image_server}/3/{cantaloupe_id}/info.json" image_url = f"{image_server}/3/{cantaloupe_id}/full/max/0/default.jpg" - return render_template('helper.html', domain=domain, uri=uri, info_url=info_url, image_url=image_url, identifier=identifier) + return render_template('helper.html', info_url=info_url, image_url=image_url, identifier=identifier, cantaloupe_id=cantaloupe_id) except ValueError: abort(404) diff --git a/iiify/templates/helper.html b/iiify/templates/helper.html index d3d2ee9..198fcf2 100644 --- a/iiify/templates/helper.html +++ b/iiify/templates/helper.html @@ -19,9 +19,9 @@
-{{ cantaloupe_id }} -

The Image API URL for the full image is: https://iiif.prod.archive.org/image/iiif/3/{{ cantaloupe_id }}/full/max/0/default.jpg

-

The Image API info.json for the image is: https://iiif.prod.archive.org/image/iiif/3/{{ cantaloupe_id }}/info.json

+

Using cantaloupe_id

+

The Image API URL for the full image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/full/max/0/default.jpg

+

The Image API info.json for the image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/info.json

From 73036afafb650ca2d25d53b9dee96f6ce66dac03 Mon Sep 17 00:00:00 2001 From: Josh Hadro Date: Thu, 5 Oct 2023 15:56:53 -0400 Subject: [PATCH 3/9] Cleanup --- iiify/app.py | 6 +++--- iiify/templates/helper.html | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/iiify/app.py b/iiify/app.py index 006f79a..259efd2 100755 --- a/iiify/app.py +++ b/iiify/app.py @@ -79,11 +79,11 @@ def documentation(): @app.route('/iiif/helper/') def helper(identifier): + domain = purify_domain(request.args.get('domain', request.url_root)) + uri = '%s%s' % (domain, identifier) try: cantaloupe_id = cantaloupe_resolver(identifier) - info_url = f"{image_server}/3/{cantaloupe_id}/info.json" - image_url = f"{image_server}/3/{cantaloupe_id}/full/max/0/default.jpg" - return render_template('helper.html', info_url=info_url, image_url=image_url, identifier=identifier, cantaloupe_id=cantaloupe_id) + return render_template('helper.html', uri=uri, identifier=identifier, cantaloupe_id=cantaloupe_id) except ValueError: abort(404) diff --git a/iiify/templates/helper.html b/iiify/templates/helper.html index 198fcf2..1bdf133 100644 --- a/iiify/templates/helper.html +++ b/iiify/templates/helper.html @@ -12,16 +12,14 @@

The IA identifier is: {{ identifier }}

+

The IA item page URL is: https://archive.org/details/{{ identifier }}

+

The manifest URL is: {{ uri }}/manifest.json

-

The Image API URL for the full image is: {{image_url}}

-

The Image API info.json for the image is: {{info_url}}

-
+

The Image API URL for the full image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/full/max/0/default.jpg

-

Using cantaloupe_id

-

The Image API URL for the full image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/full/max/0/default.jpg

-

The Image API info.json for the image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/info.json

+

The Image API info.json for the image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/info.json

From 9a8299308e0ef0b15ff9ff5aaae5ca584b172a0f Mon Sep 17 00:00:00 2001 From: Josh Hadro Date: Fri, 6 Oct 2023 14:54:37 -0400 Subject: [PATCH 4/9] More nuance to helpers --- iiify/app.py | 26 ++++++++++++--- iiify/templates/helpers/audio.html | 44 ++++++++++++++++++++++++++ iiify/templates/helpers/image.html | 47 ++++++++++++++++++++++++++++ iiify/templates/helpers/movies.html | 44 ++++++++++++++++++++++++++ iiify/templates/helpers/texts.html | 41 ++++++++++++++++++++++++ iiify/templates/helpers/unknown.html | 25 +++++++++++++++ 6 files changed, 222 insertions(+), 5 deletions(-) create mode 100644 iiify/templates/helpers/audio.html create mode 100644 iiify/templates/helpers/image.html create mode 100644 iiify/templates/helpers/movies.html create mode 100644 iiify/templates/helpers/texts.html create mode 100644 iiify/templates/helpers/unknown.html diff --git a/iiify/app.py b/iiify/app.py index 259efd2..7fb39b1 100755 --- a/iiify/app.py +++ b/iiify/app.py @@ -2,6 +2,7 @@ import hashlib import os import time +import requests from flask import Flask, send_file, jsonify, abort, request, render_template, redirect from flask_cors import CORS from flask_caching import Cache @@ -19,6 +20,7 @@ cors = CORS(app) if cors else None cache = Cache(app) +ARCHIVE = 'http://archive.org' # cache.init_app(app) @@ -81,11 +83,25 @@ def documentation(): def helper(identifier): domain = purify_domain(request.args.get('domain', request.url_root)) uri = '%s%s' % (domain, identifier) - try: - cantaloupe_id = cantaloupe_resolver(identifier) - return render_template('helper.html', uri=uri, identifier=identifier, cantaloupe_id=cantaloupe_id) - except ValueError: - abort(404) + metadata = requests.get('%s/metadata/%s' % (ARCHIVE, identifier)).json() + mediatype = metadata['metadata']['mediatype'] + + if mediatype == "image": + try: + cantaloupe_id = cantaloupe_resolver(identifier) + return render_template('helpers/image.html', uri=uri, identifier=identifier, cantaloupe_id=cantaloupe_id) + except ValueError: + abort(404) + + elif mediatype == "audio" or mediatype == "etree": + return render_template('helpers/audio.html', uri=uri, identifier=identifier) + elif mediatype == "movies": + return render_template('helpers/movies.html', uri=uri, identifier=identifier) + elif mediatype == "texts": + return render_template('helpers/texts.html', uri=uri, identifier=identifier) + else: + pass + @app.route('/iiif/') def view(identifier): diff --git a/iiify/templates/helpers/audio.html b/iiify/templates/helpers/audio.html new file mode 100644 index 0000000..1405d7b --- /dev/null +++ b/iiify/templates/helpers/audio.html @@ -0,0 +1,44 @@ + + + + + + IIIF Image and Presentation API Audio Helper + + + + + + + + + + + +
+ +
+
+ +

IIIF Presentation API Audio Helper

+ +

The IA item page URL is: https://archive.org/details/{{ identifier }}

+ +

The IA identifier is: {{ identifier }}

+ +

The IIIF manifest URL is: {{ uri }}/manifest.json

+ +

IIIF Viewer options for this mediatype:

+ + + + diff --git a/iiify/templates/helpers/image.html b/iiify/templates/helpers/image.html new file mode 100644 index 0000000..5809386 --- /dev/null +++ b/iiify/templates/helpers/image.html @@ -0,0 +1,47 @@ + + + + + + IIIF Image Helper + + + + + + + + + + + +
+ +
+
+ +

IIIF Image Helper

+ +

The IA item page URL is: https://archive.org/details/{{ identifier }}

+ +

The IA identifier is: {{ identifier }}

+ +

The IIIF manifest URL is: {{ uri }}/manifest.json

+ +

The Image API URL for the full image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/full/max/0/default.jpg

+ +

The Image API info.json for the image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/info.json

+ +

IIIF Viewer options

+ + + + diff --git a/iiify/templates/helpers/movies.html b/iiify/templates/helpers/movies.html new file mode 100644 index 0000000..51897da --- /dev/null +++ b/iiify/templates/helpers/movies.html @@ -0,0 +1,44 @@ + + + + + + IIIF Image and Presentation API Movies Helper + + + + + + + + + + + +
+ +
+
+ +

IIIF Presentation API Movies Helper

+ +

The IA item page URL is: https://archive.org/details/{{ identifier }}

+ +

The IA identifier is: {{ identifier }}

+ +

The IIIF manifest URL is: {{ uri }}/manifest.json

+ +

IIIF Viewer options for this mediatype:

+ + + + diff --git a/iiify/templates/helpers/texts.html b/iiify/templates/helpers/texts.html new file mode 100644 index 0000000..ef082e5 --- /dev/null +++ b/iiify/templates/helpers/texts.html @@ -0,0 +1,41 @@ + + + + + + IIIF Image and Presentation API Texts Helper + + + + + + + + + + + +
+ +
+
+ +

IIIF Presentation API Texts Helper

+ +

The IA item page URL is: https://archive.org/details/{{ identifier }}

+ +

The IA identifier is: {{ identifier }}

+ +

The IIIF manifest URL is: {{ uri }}/manifest.json

+ +

IIIF Viewer options for this mediatype:

+ + + + diff --git a/iiify/templates/helpers/unknown.html b/iiify/templates/helpers/unknown.html new file mode 100644 index 0000000..8a59da0 --- /dev/null +++ b/iiify/templates/helpers/unknown.html @@ -0,0 +1,25 @@ + + + + + IIIF Image and Presentation API Helper + + + + + + +

Unknown

+ +

The IA identifier is: {{ identifier }}

+ +

The IA item page URL is: https://archive.org/details/{{ identifier }}

+ +

The manifest URL is: {{ uri }}/manifest.json

+ +

The material type of the item you're requested is not a recognized material type for IIIF viewers.

+ + + From 67d31fa19a8e7c4007dd60818625120a282fd15d Mon Sep 17 00:00:00 2001 From: Josh Hadro Date: Fri, 6 Oct 2023 16:39:10 -0400 Subject: [PATCH 5/9] Helpers cleanup --- iiify/app.py | 9 +++--- iiify/templates/helpers/audio.html | 12 ++++---- iiify/templates/helpers/image.html | 12 ++++---- iiify/templates/helpers/movies.html | 12 ++++---- iiify/templates/helpers/texts.html | 6 ++-- iiify/templates/helpers/unknown.html | 41 ++++++++++++++++++---------- 6 files changed, 49 insertions(+), 43 deletions(-) diff --git a/iiify/app.py b/iiify/app.py index 7fb39b1..339af9f 100755 --- a/iiify/app.py +++ b/iiify/app.py @@ -82,23 +82,22 @@ def documentation(): @app.route('/iiif/helper/') def helper(identifier): domain = purify_domain(request.args.get('domain', request.url_root)) - uri = '%s%s' % (domain, identifier) metadata = requests.get('%s/metadata/%s' % (ARCHIVE, identifier)).json() mediatype = metadata['metadata']['mediatype'] if mediatype == "image": try: cantaloupe_id = cantaloupe_resolver(identifier) - return render_template('helpers/image.html', uri=uri, identifier=identifier, cantaloupe_id=cantaloupe_id) + return render_template('helpers/image.html', identifier=identifier, cantaloupe_id=cantaloupe_id) except ValueError: abort(404) elif mediatype == "audio" or mediatype == "etree": - return render_template('helpers/audio.html', uri=uri, identifier=identifier) + return render_template('helpers/audio.html', identifier=identifier) elif mediatype == "movies": - return render_template('helpers/movies.html', uri=uri, identifier=identifier) + return render_template('helpers/movies.html', identifier=identifier) elif mediatype == "texts": - return render_template('helpers/texts.html', uri=uri, identifier=identifier) + return render_template('helpers/texts.html', identifier=identifier) else: pass diff --git a/iiify/templates/helpers/audio.html b/iiify/templates/helpers/audio.html index 1405d7b..12f8e1b 100644 --- a/iiify/templates/helpers/audio.html +++ b/iiify/templates/helpers/audio.html @@ -28,15 +28,13 @@

IIIF Presentation API Audio Helper

The IA identifier is: {{ identifier }}

-

The IIIF manifest URL is: {{ uri }}/manifest.json

+

The IIIF manifest URL is: https://iiif.archive.org/iiif/3/{{ identifier }}/manifest.json

-

IIIF Viewer options for this mediatype:

+

IIIF viewer options for this mediatype:

diff --git a/iiify/templates/helpers/image.html b/iiify/templates/helpers/image.html index 5809386..9cedd6c 100644 --- a/iiify/templates/helpers/image.html +++ b/iiify/templates/helpers/image.html @@ -28,18 +28,18 @@

IIIF Image Helper

The IA identifier is: {{ identifier }}

-

The IIIF manifest URL is: {{ uri }}/manifest.json

+

The IIIF manifest URL is: https://iiif.archive.org/iiif/3/{{ identifier }}/manifest.json

The Image API URL for the full image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/full/max/0/default.jpg

The Image API info.json for the image is: https://iiif.archive.org/image/iiif/3/{{ cantaloupe_id }}/info.json

-

IIIF Viewer options

+

IIIF viewer options

diff --git a/iiify/templates/helpers/movies.html b/iiify/templates/helpers/movies.html index 51897da..ce87094 100644 --- a/iiify/templates/helpers/movies.html +++ b/iiify/templates/helpers/movies.html @@ -28,15 +28,13 @@

IIIF Presentation API Movies Helper

The IA identifier is: {{ identifier }}

-

The IIIF manifest URL is: {{ uri }}/manifest.json

+

The IIIF manifest URL is: https://iiif.archive.org/iiif/3/{{ identifier }}/manifest.json

-

IIIF Viewer options for this mediatype:

+

IIIF viewer options for this mediatype:

diff --git a/iiify/templates/helpers/texts.html b/iiify/templates/helpers/texts.html index ef082e5..7467f3e 100644 --- a/iiify/templates/helpers/texts.html +++ b/iiify/templates/helpers/texts.html @@ -32,9 +32,9 @@

IIIF Presentation API Texts Helper

IIIF Viewer options for this mediatype:

diff --git a/iiify/templates/helpers/unknown.html b/iiify/templates/helpers/unknown.html index 8a59da0..88cdd34 100644 --- a/iiify/templates/helpers/unknown.html +++ b/iiify/templates/helpers/unknown.html @@ -1,25 +1,36 @@ - + + + + IIIF Image and Presentation API Helper + + + + + + + + + + + +
+ +
+
+ +

IIIF Presentation API Helper

- IIIF Image and Presentation API Helper - - - - - - -

Unknown

+

The IA item page URL is: https://archive.org/details/{{ identifier }}

The IA identifier is: {{ identifier }}

-

The IA item page URL is: https://archive.org/details/{{ identifier }}

- -

The manifest URL is: {{ uri }}/manifest.json

+

The IIIF manifest URL is: https://iiif.archive.org/iiif/3/{{ identifier }}/manifest.json

The material type of the item you're requested is not a recognized material type for IIIF viewers.

- + \ No newline at end of file From cc9e3c60945037579d86211850a66ed567095315 Mon Sep 17 00:00:00 2001 From: Josh Hadro Date: Thu, 12 Oct 2023 14:31:43 -0400 Subject: [PATCH 6/9] Update helpers --- iiify/app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iiify/app.py b/iiify/app.py index 339af9f..4511738 100755 --- a/iiify/app.py +++ b/iiify/app.py @@ -11,6 +11,8 @@ purify_domain, cantaloupe_resolver, create_collection3 from .configs import options, cors, approot, cache_root, media_root, \ cache_expr, version, image_server, cache_timeouts +from urllib.parse import quote + app = Flask(__name__) # disabling sorting of the output json @@ -79,7 +81,7 @@ def demo(): def documentation(): return render_template('docs/index.html', version=version) -@app.route('/iiif/helper/') +@app.route('/iiif/helper//') def helper(identifier): domain = purify_domain(request.args.get('domain', request.url_root)) metadata = requests.get('%s/metadata/%s' % (ARCHIVE, identifier)).json() @@ -88,7 +90,8 @@ def helper(identifier): if mediatype == "image": try: cantaloupe_id = cantaloupe_resolver(identifier) - return render_template('helpers/image.html', identifier=identifier, cantaloupe_id=cantaloupe_id) + esc_cantaloupe_id = quote(cantaloupe_id) + return render_template('helpers/image.html', identifier=identifier, cantaloupe_id=cantaloupe_id, esc_cantaloupe_id=esc_cantaloupe_id) except ValueError: abort(404) From 62a83b7ab7da88d3fbd20e9dfc6de82951d8d460 Mon Sep 17 00:00:00 2001 From: Josh Hadro Date: Thu, 12 Oct 2023 14:31:56 -0400 Subject: [PATCH 7/9] Add image tools --- iiify/templates/helpers/image.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/iiify/templates/helpers/image.html b/iiify/templates/helpers/image.html index 9cedd6c..69faf7e 100644 --- a/iiify/templates/helpers/image.html +++ b/iiify/templates/helpers/image.html @@ -39,9 +39,16 @@

IIIF viewer options

  • Mirador
  • Universal Viewer
  • Clover
  • -
  • Annona
  • +

    IIIF image tool options

    + + From 705cb6d35b8d6a4aca1540acb616e48fb8e9c85c Mon Sep 17 00:00:00 2001 From: Josh Hadro Date: Thu, 12 Oct 2023 14:32:06 -0400 Subject: [PATCH 8/9] Fix texts helper manifest generator --- iiify/templates/helpers/texts.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiify/templates/helpers/texts.html b/iiify/templates/helpers/texts.html index 7467f3e..4c7ef0f 100644 --- a/iiify/templates/helpers/texts.html +++ b/iiify/templates/helpers/texts.html @@ -28,7 +28,7 @@

    IIIF Presentation API Texts Helper

    The IA identifier is: {{ identifier }}

    -

    The IIIF manifest URL is: {{ uri }}/manifest.json

    +

    The IIIF manifest URL is: https://iiif.archive.org/iiif/3/{{ identifier }}/manifest.json

    IIIF Viewer options for this mediatype:

      From ac64a1ed64977f735b15058bb83421c16ef927ff Mon Sep 17 00:00:00 2001 From: Josh Hadro Date: Thu, 12 Oct 2023 14:40:43 -0400 Subject: [PATCH 9/9] Fix unknown --- iiify/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiify/app.py b/iiify/app.py index 4511738..63edbd3 100755 --- a/iiify/app.py +++ b/iiify/app.py @@ -102,7 +102,7 @@ def helper(identifier): elif mediatype == "texts": return render_template('helpers/texts.html', identifier=identifier) else: - pass + return render_template('helpers/unknown.html', identifier=identifier) @app.route('/iiif/')