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

Add solution for Recipe 0013. #211

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions docs/recipes/0013-placeholderCanvas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Load a Preview Image Before the Main Content
| | **Cookbook URLs** |
|--------------|-------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0013-placeholderCanvas/](https://iiif.io/api/cookbook/recipe/0013-placeholderCanvas/) |
| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0013-placeholderCanvas/manifest.json](https://iiif.io/api/cookbook/recipe/0013-placeholderCanvas/manifest.json) |

### Method 1 - Use PlaceholderCanvas and add_item() helper
```python
--8<-- "docs/recipes/scripts/0013-placeholderCanvas-method1.py"
```
2 changes: 1 addition & 1 deletion docs/recipes/0014-accompanyingcanvas.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# "Audio Presentation with Accompanying Image"
# Audio Presentation with Accompanying Image
| | **Cookbook URLs** |
|--------------|-------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0014-accompanyingcanvas/](https://iiif.io/api/cookbook/recipe/0014-accompanyingcanvas/) |
Expand Down
62 changes: 62 additions & 0 deletions docs/recipes/scripts/0013-placeholderCanvas-method1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config, PlaceholderCanvas

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"
base_url = "https://iiif.io/api/cookbook/recipe/0013-placeholderCanvas"

manifest = Manifest(
id=f"{base_url}/manifest.json",
label="Video recording of Donizetti's _The Elixer of Love_",
)
placeholder_canvas = PlaceholderCanvas(
id=f"{base_url}/canvas/donizetti/placeholder",
width=640,
height=360,
)
pc_anno_page = AnnotationPage(
id=f"{base_url}/canvas/donizetti/placeholder/1"
)
pc_anno_body = ResourceItem(
id="https://fixtures.iiif.io/video/indiana/donizetti-elixir/act1-thumbnail.png",
type="Image",
format="image/png",
width=640,
height=360,
)
pc_anno = Annotation(
id=f"{base_url}/canvas/donizetti/placeholder/1-image",
motivation="painting",
body=pc_anno_body,
target=f"{base_url}/canvas/donizetti/placeholder"
)
pc_anno_page.add_item(pc_anno)
placeholder_canvas.add_item(pc_anno_page)

canvas = manifest.make_canvas(
id=f"{base_url}/canvas/donizetti",
duration=7278.466,
height=360,
width=640,
placeholderCanvas=placeholder_canvas,
)

anno_body = ResourceItem(
id="https://fixtures.iiif.io/video/indiana/donizetti-elixir/vae0637_accessH264_low.mp4",
type="Video",
duration=7278.466,
width=640,
height=360,
format="video/mp4"
)
anno = Annotation(
id=f"{base_url}/donizetti/1-video",
motivation="painting",
body=anno_body,
target=canvas.id
)
anno_page = AnnotationPage(
id=f"{base_url}/donizetti/1",
)
anno_page.add_item(anno)
canvas.add_item(anno_page)

print(manifest.json(indent=2))
4 changes: 2 additions & 2 deletions iiif_prezi3/helpers/add_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ..loader import monkeypatch_schema
from ..skeleton import (AccompanyingCanvas, AnnotationPage, Canvas, Collection,
Manifest, Range, Reference)
Manifest, PlaceholderCanvas, Range, Reference)


class AddItem:
Expand Down Expand Up @@ -37,5 +37,5 @@ def add_item_by_reference(self, item):
self.items = self.items # Force Pydantic to validate?


monkeypatch_schema([Collection, Manifest, Canvas, Range, AnnotationPage, Reference, AccompanyingCanvas], AddItem)
monkeypatch_schema([Collection, Manifest, Canvas, Range, AnnotationPage, Reference, AccompanyingCanvas, PlaceholderCanvas], AddItem)
monkeypatch_schema([Collection, Range, Canvas, AnnotationPage, AccompanyingCanvas], AddItemByReference)
Loading