From 0bd8aeebc193d508182a5a81a884fbc93b3bba50 Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Fri, 6 Sep 2024 11:37:50 -0500 Subject: [PATCH 1/6] Add recipe for 0219 Using Caption File. --- docs/recipes/0219-using-caption-file.md | 10 +++++ .../0219-using-caption-file-method1.py | 45 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 docs/recipes/0219-using-caption-file.md create mode 100644 docs/recipes/scripts/0219-using-caption-file-method1.py diff --git a/docs/recipes/0219-using-caption-file.md b/docs/recipes/0219-using-caption-file.md new file mode 100644 index 0000000..f0f4859 --- /dev/null +++ b/docs/recipes/0219-using-caption-file.md @@ -0,0 +1,10 @@ +# Using Caption and Subtitle Files with Video Content +| | **Cookbook URLs** | +|--------------|-------------------| +| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0219-using-caption-file/](https://iiif.io/api/cookbook/recipe/0219-using-caption-file/) | +| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0219-using-caption-file/manifest.json](https://iiif.io/api/cookbook/recipe/0219-using-caption-file/manifest.json) | + +### Method 1 - Construct Supplementing Annotation Using the `make_annotation` helper and a dictionary of the `body` properties +```python +--8<-- "docs/recipes/scripts/0219-using-caption-file-method1.py" +``` diff --git a/docs/recipes/scripts/0219-using-caption-file-method1.py b/docs/recipes/scripts/0219-using-caption-file-method1.py new file mode 100644 index 0000000..9e310de --- /dev/null +++ b/docs/recipes/scripts/0219-using-caption-file-method1.py @@ -0,0 +1,45 @@ +from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config + +config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en" +manifest = Manifest( + id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/manifest.json", + label="Lunchroom Manners" +) +canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas") +painting_anno_body = ResourceItem( + id="https://fixtures.iiif.io/video/indiana/lunchroom_manners/high/lunchroom_manners_1024kb.mp4", + type="Video", + format="video/mp4" +) +painting_anno_page = AnnotationPage( + id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas/page" +) +painting_anno = Annotation( + id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas/page/annotation1", + motivation="painting", + body=painting_anno_body, + target=canvas.id +) +hwd = {"height": 360, "width": 480, "duration": 572.034} +painting_anno_body.set_hwd(**hwd) +canvas.set_hwd(**hwd) +painting_anno_page.add_item(painting_anno) +canvas.add_item(painting_anno_page) +captions = canvas.make_annotation( + id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas/page2/a1", + motivation="supplementing", + body={ + "id": f"https://fixtures.iiif.io/video/indiana/lunchroom_manners/lunchroom_manners.vtt", + "type": "Text", + "language": "en", + "format": "text/vtt", + "label": { + "en": [ + "Captions in WebVTT format" + ] + } + }, + target="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas", + anno_page_id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas/page2" +) +print(manifest.json(indent=2)) From a7c48578608297dd0c9558523c36915b2a143c41 Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Sat, 7 Sep 2024 09:10:52 -0500 Subject: [PATCH 2/6] Clean. --- docs/recipes/0047-homepage.md | 7 +++++++ docs/recipes/scripts/0219-using-caption-file-method1.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 docs/recipes/0047-homepage.md diff --git a/docs/recipes/0047-homepage.md b/docs/recipes/0047-homepage.md new file mode 100644 index 0000000..2c2072b --- /dev/null +++ b/docs/recipes/0047-homepage.md @@ -0,0 +1,7 @@ +# Linking to Web Page of an Object +| | **Cookbook URLs** | +|--------------|-------------------| +| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0047-homepage/](https://iiif.io/api/cookbook/recipe/0047-homepage/) | +| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0047-homepage/manifest.json](https://iiif.io/api/cookbook/recipe/0047-homepage/manifest.json) | + +### Method 1 - diff --git a/docs/recipes/scripts/0219-using-caption-file-method1.py b/docs/recipes/scripts/0219-using-caption-file-method1.py index 9e310de..8f795e0 100644 --- a/docs/recipes/scripts/0219-using-caption-file-method1.py +++ b/docs/recipes/scripts/0219-using-caption-file-method1.py @@ -29,7 +29,7 @@ id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas/page2/a1", motivation="supplementing", body={ - "id": f"https://fixtures.iiif.io/video/indiana/lunchroom_manners/lunchroom_manners.vtt", + "id": "https://fixtures.iiif.io/video/indiana/lunchroom_manners/lunchroom_manners.vtt", "type": "Text", "language": "en", "format": "text/vtt", From 0717dba5b296515442ad7b22f0186ec580e94c4f Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Sat, 7 Sep 2024 09:13:37 -0500 Subject: [PATCH 3/6] Fix mistake. --- docs/recipes/0047-homepage.md | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 docs/recipes/0047-homepage.md diff --git a/docs/recipes/0047-homepage.md b/docs/recipes/0047-homepage.md deleted file mode 100644 index 2c2072b..0000000 --- a/docs/recipes/0047-homepage.md +++ /dev/null @@ -1,7 +0,0 @@ -# Linking to Web Page of an Object -| | **Cookbook URLs** | -|--------------|-------------------| -| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0047-homepage/](https://iiif.io/api/cookbook/recipe/0047-homepage/) | -| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0047-homepage/manifest.json](https://iiif.io/api/cookbook/recipe/0047-homepage/manifest.json) | - -### Method 1 - From 3e7c96735e01e96615ca610fc5f078100bbc9a8b Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Fri, 6 Dec 2024 11:16:13 -0600 Subject: [PATCH 4/6] Use base_url. --- .../scripts/0219-using-caption-file-method1.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/recipes/scripts/0219-using-caption-file-method1.py b/docs/recipes/scripts/0219-using-caption-file-method1.py index 8f795e0..c20be85 100644 --- a/docs/recipes/scripts/0219-using-caption-file-method1.py +++ b/docs/recipes/scripts/0219-using-caption-file-method1.py @@ -1,21 +1,23 @@ from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en" +base_url = "https://iiif.io/api/cookbook/recipe/0219-using-caption-file" + manifest = Manifest( - id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/manifest.json", + id=f"{base_url}/manifest.json", label="Lunchroom Manners" ) -canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas") +canvas = manifest.make_canvas(id=f"{base_url}/canvas") painting_anno_body = ResourceItem( id="https://fixtures.iiif.io/video/indiana/lunchroom_manners/high/lunchroom_manners_1024kb.mp4", type="Video", format="video/mp4" ) painting_anno_page = AnnotationPage( - id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas/page" + id=f"{base_url}/canvas/page" ) painting_anno = Annotation( - id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas/page/annotation1", + id=f"{base_url}/canvas/page/annotation1", motivation="painting", body=painting_anno_body, target=canvas.id @@ -26,7 +28,7 @@ painting_anno_page.add_item(painting_anno) canvas.add_item(painting_anno_page) captions = canvas.make_annotation( - id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas/page2/a1", + id=f"{base_url}/canvas/page2/a1", motivation="supplementing", body={ "id": "https://fixtures.iiif.io/video/indiana/lunchroom_manners/lunchroom_manners.vtt", @@ -39,7 +41,7 @@ ] } }, - target="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas", - anno_page_id="https://iiif.io/api/cookbook/recipe/0219-using-caption-file/canvas/page2" + target=f"{base_url}/canvas", + anno_page_id=f"{base_url}/canvas/page2" ) print(manifest.json(indent=2)) From 3e7c48e883cb7e3d2f8366f639a19a95f09aae17 Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Wed, 11 Dec 2024 10:36:04 -0600 Subject: [PATCH 5/6] Make caption a resourceitem. --- .../0219-using-caption-file-method1.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/docs/recipes/scripts/0219-using-caption-file-method1.py b/docs/recipes/scripts/0219-using-caption-file-method1.py index c20be85..6946fc7 100644 --- a/docs/recipes/scripts/0219-using-caption-file-method1.py +++ b/docs/recipes/scripts/0219-using-caption-file-method1.py @@ -27,20 +27,17 @@ canvas.set_hwd(**hwd) painting_anno_page.add_item(painting_anno) canvas.add_item(painting_anno_page) +caption_body = ResourceItem( + id="https://fixtures.iiif.io/video/indiana/lunchroom_manners/lunchroom_manners.vtt", + type="Text", + language="en", + format="text/vtt", + label="Captions" +) captions = canvas.make_annotation( id=f"{base_url}/canvas/page2/a1", motivation="supplementing", - body={ - "id": "https://fixtures.iiif.io/video/indiana/lunchroom_manners/lunchroom_manners.vtt", - "type": "Text", - "language": "en", - "format": "text/vtt", - "label": { - "en": [ - "Captions in WebVTT format" - ] - } - }, + body=caption_body, target=f"{base_url}/canvas", anno_page_id=f"{base_url}/canvas/page2" ) From 4d05f752dd443659622f14708c61a791508b3f54 Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Wed, 11 Dec 2024 10:45:26 -0600 Subject: [PATCH 6/6] Make body a ResourceItem. --- docs/recipes/scripts/0219-using-caption-file-method1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/recipes/scripts/0219-using-caption-file-method1.py b/docs/recipes/scripts/0219-using-caption-file-method1.py index 6946fc7..f2554fe 100644 --- a/docs/recipes/scripts/0219-using-caption-file-method1.py +++ b/docs/recipes/scripts/0219-using-caption-file-method1.py @@ -31,9 +31,9 @@ id="https://fixtures.iiif.io/video/indiana/lunchroom_manners/lunchroom_manners.vtt", type="Text", language="en", - format="text/vtt", - label="Captions" + format="text/vtt" ) +caption_body.add_label(language="en", value="Captions in WebVTT format") captions = canvas.make_annotation( id=f"{base_url}/canvas/page2/a1", motivation="supplementing",