Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make production ready #136

Merged
merged 5 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions iiify/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from iiif2 import iiif, web
from .resolver import ia_resolver, create_manifest, create_manifest3, getids, collection, \
purify_domain, cantaloupe_resolver, create_collection3
from .url2iiif import url2ia
from .configs import options, cors, approot, cache_root, media_root, \
cache_expr, version, image_server, cache_timeouts

Expand Down Expand Up @@ -54,21 +53,6 @@ def index():
return jsonify(getids(q, cursor=cursor))


@app.route('/iiif/url2iiif')
def url2iiif():
url = request.args.get('url', '')
if not url:
abort(400)
try:
domain = purify_domain(request.args.get('domain', request.url_root))
filehash = url2ia(url)
time.sleep(20)
return redirect('%surl2iiif$%s' % (domain, filehash))
except Exception as e:
print(e)
abort(400)


@app.route('/iiif/collection.json')
def catalog():
cursor = request.args.get('cursor', '')
Expand Down
4 changes: 2 additions & 2 deletions iiify/configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def getdef(self, section, option, default_value):
# Especially useful for SeaDragon viewers running locally
cors = bool(int(config.getdef('server', 'cors', 0)))

iiif_domain = config.getdef('server', 'domain', 'https://iiif.archivelab.org')
iiif_uri = config.getdef('server', 'uri', 'https://iiif.archivelab.org/iiif')
media_root = config.getdef('media', 'root', 'media')
if not os.path.isabs(media_root):
media = os.path.join(approot, media_root)
Expand All @@ -66,7 +66,7 @@ def getdef(self, section, option, default_value):
s3secret = config.getdef('url2iiif', 's3secret', '')

# cantaloupe server
image_server = config.getdef('cantaloupe', 'url', 'https://services-ia-iiif-cantaloupe-experiment.dev.archive.org/iiif')
image_server = config.getdef('cantaloupe', 'url', 'https://cantaloupe.prod.archive.org/iiif')

# caching
cache_timeouts = {
Expand Down
28 changes: 13 additions & 15 deletions iiify/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
import os
import requests
from iiif2 import iiif, web
from .configs import options, cors, approot, cache_root, media_root, apiurl
from .configs import options, cors, approot, cache_root, media_root, apiurl, image_server, iiif_uri
from iiif_prezi3 import Manifest, config, Annotation, AnnotationPage, Canvas, Manifest, ResourceItem, ServiceItem, Choice, Collection, ManifestRef, CollectionRef
from urllib.parse import urlparse, parse_qs
import json
import math

IMG_CTX = 'http://iiif.io/api/image/2/context.json'
PRZ_CTX = 'http://iiif.io/api/presentation/2/context.json'
ARCHIVE = 'http://archive.org'
IMG_SRV = 'https://services-ia-iiif-cantaloupe-experiment.dev.archive.org/iiif'
METADATA_FIELDS = ("title", "volume", "publisher", "subject", "date", "contributor", "creator")
ARCHIVE = 'http://archive.org'
bookdata = 'http://%s/BookReader/BookReaderJSON.php'
bookreader = "http://%s/BookReader/BookReaderImages.php"
URI_PRIFIX = "https://iiif.archive.org/iiif"

valid_filetypes = ['jpg', 'jpeg', 'png', 'gif', 'tif', 'jp2', 'pdf', 'tiff']

Expand Down Expand Up @@ -269,16 +267,16 @@ def singleImage(metadata, identifier, manifest, uri):
fileName = f"{f['name']}/{f['name'].replace('.zip','')}/{f['name'].replace('jp2.zip','0000.jp2')}"

imgId = f"{identifier}/{fileName}".replace('/','%2f')
imgURL = f"{IMG_SRV}/3/{imgId}"
imgURL = f"{image_server}/3/{imgId}"

manifest.make_canvas_from_iiif(url=imgURL,
id=f"{URI_PRIFIX}/{identifier}/canvas",
id=f"{iiif_uri}/{identifier}/canvas",
label="1",
anno_page_id=f"{uri}/annotationPage/1",
anno_id=f"{uri}/annotation/1")

def addMetadata(item, identifier, metadata, collection=False):
item.homepage = [{"id": f"https://archive.org/details/{identifier}",
item.homepage = [{"id": f"{ARCHIVE}/details/{identifier}",
"type": "Text",
"label": {"en": ["Item Page on Internet Archive"]},
"format": "text/html"}]
Expand Down Expand Up @@ -367,9 +365,9 @@ def create_manifest3(identifier, domain=None, page=None):
fileUrl = urlparse(page['uri'])
fileName = parse_qs(fileUrl.query).get('file')[0]
imgId = f"{zipFile}/{fileName}".replace('/','%2f')
imgURL = f"{IMG_SRV}/3/{imgId}"
imgURL = f"{image_server}/3/{imgId}"

canvas = Canvas(id=f"{URI_PRIFIX}/{identifier}${pageCount}/canvas", label=f"{page['leafNum']}")
canvas = Canvas(id=f"{iiif_uri}/{identifier}${pageCount}/canvas", label=f"{page['leafNum']}")

body = ResourceItem(id=f"{imgURL}/full/max/0/default.jpg", type="Image")
body.format = "image/jpeg"
Expand Down Expand Up @@ -408,12 +406,12 @@ def create_manifest3(identifier, domain=None, page=None):
for file in [f for f in originals if f['format'] in ['VBR MP3', '32Kbps MP3', '56Kbps MP3', '64Kbps MP3', '96Kbps MP3', '128Kbps MP3', 'MPEG-4 Audio', 'Flac', 'AIFF', 'Apple Lossless Audio', 'Ogg Vorbis', 'WAVE', '24bit Flac', 'Shorten']]:
normalised_id = file['name'].rsplit(".", 1)[0]
slugged_id = normalised_id.replace(" ", "-")
c_id = f"{URI_PRIFIX}/{identifier}/{slugged_id}/canvas"
c_id = f"{iiif_uri}/{identifier}/{slugged_id}/canvas"
c = Canvas(id=c_id, label=normalised_id, duration=float(file['length']))

# create intermediary objects
ap = AnnotationPage(id=f"{URI_PRIFIX}/{identifier}/{slugged_id}/page")
anno = Annotation(id=f"{URI_PRIFIX}/{identifier}/{slugged_id}/annotation", motivation="painting", target=c.id)
ap = AnnotationPage(id=f"{iiif_uri}/{identifier}/{slugged_id}/page")
anno = Annotation(id=f"{iiif_uri}/{identifier}/{slugged_id}/annotation", motivation="painting", target=c.id)

# create body based on whether there are derivatives or not:
if file['name'] in derivatives:
Expand Down Expand Up @@ -461,12 +459,12 @@ def create_manifest3(identifier, domain=None, page=None):
for file in [f for f in originals if f['format'] in ['MPEG4', 'h.264 MPEG4', '512Kb MPEG4', 'HiRes MPEG4', 'MPEG2', 'h.264', 'Matroska', 'Ogg Video', 'Ogg Theora', 'WebM', 'Windows Media', 'Cinepack']]:
normalised_id = file['name'].rsplit(".", 1)[0]
slugged_id = normalised_id.replace(" ", "-")
c_id = f"{URI_PRIFIX}/{identifier}/{slugged_id}/canvas"
c_id = f"{iiif_uri}/{identifier}/{slugged_id}/canvas"
c = Canvas(id=c_id, label=normalised_id, duration=float(file['length']), height=int(file['height']), width=int(file['width']))

# create intermediary objects
ap = AnnotationPage(id=f"{URI_PRIFIX}/{identifier}/{slugged_id}/page")
anno = Annotation(id=f"{URI_PRIFIX}/{identifier}/{slugged_id}/annotation", motivation="painting", target=c.id)
ap = AnnotationPage(id=f"{iiif_uri}/{identifier}/{slugged_id}/page")
anno = Annotation(id=f"{iiif_uri}/{identifier}/{slugged_id}/annotation", motivation="painting", target=c.id)

# create body based on whether there are derivatives or not:
if file['name'] in derivatives:
Expand Down
66 changes: 0 additions & 66 deletions iiify/url2iiif.py

This file was deleted.

Loading