diff --git a/iiify/resolver.py b/iiify/resolver.py index ee1b715..974be9d 100644 --- a/iiify/resolver.py +++ b/iiify/resolver.py @@ -398,6 +398,28 @@ def create_manifest3(identifier, domain=None, page=None): # id=f"https://iiif.archivelab.org/iiif/{identifier}${pageCount}/canvas", # label=f"{page['leafNum']}") pageCount += 1 + + + # Setting logic for paging behavior and starting canvases + # Start with paged (default) or individual behaviors + try: + if bookreader['data']['brOptions']['defaults'] == "mode/1up": + manifest.behavior = "individuals" + except: + manifest.behavior = "paged" + + # Then set left-to-right or right-to-left if present + try: + if bookreader['data']['brOptions']['pageProgression'] == "lr": + viewingDirection = "left-to-right" + elif bookreader['data']['brOptions']['pageProgression'] == "rl": + viewingDirection = "right-to-left" + if viewingDirection: + manifest.viewingDirection = viewingDirection + except: + pass + + elif mediatype == 'image': singleImage(metadata, identifier, manifest, uri) elif mediatype == 'audio' or mediatype == 'etree': diff --git a/tests/test_manifests.py b/tests/test_manifests.py index 1be76a3..3fa25ba 100644 --- a/tests/test_manifests.py +++ b/tests/test_manifests.py @@ -104,6 +104,22 @@ def test_provider_logo(self): self.assertEqual(manifest['provider'][0]['homepage'][0]['id'] == "https://archive.org", True, f"Expected 'https://archive.org' but got {manifest['provider'][0]['id']}") self.assertEqual(manifest['provider'][0]['logo'][0]['id'] == "https://archive.org/images/glogo.png", True, f"Expected logo URI but got {manifest['provider'][0]['logo'][0]['id']}") + def test_page_behavior(self): + resp = self.test_app.get("/iiif/3/rbmsbk_ap2-v4_2001_V55N4/manifest.json") + self.assertEqual(resp.status_code, 200) + manifest = resp.json + self.assertEqual(len(manifest['items']),116,f"Expected 116 canvas but got: {len(manifest['items'])}") + self.assertEqual(manifest['viewingDirection'],"left-to-right",f"Expected 'left-to-right' canvas but got: {manifest['viewingDirection']}") + self.assertEqual(manifest['behavior'][0],"paged",f"Expected 'paged' but got: {manifest['behavior'][0]}") + + def test_page_behavior_r_to_l(self): + resp = self.test_app.get("/iiif/3/nybc314063/manifest.json") + self.assertEqual(resp.status_code, 200) + manifest = resp.json + self.assertEqual(len(manifest['items']),544,f"Expected 544 canvas but got: {len(manifest['items'])}") + self.assertEqual(manifest['viewingDirection'],"right-to-left",f"Expected 'right-to-left' canvas but got: {manifest['viewingDirection']}") + self.assertEqual(manifest['behavior'][0],"paged",f"Expected 'paged' but got: {manifest['behavior'][0]}") + def test_escape_cantaloupe_urls(self): resp = self.test_app.get("/iiif/3/0-._20211206/manifest.json") self.assertEqual(resp.status_code, 200)