Skip to content

Commit

Permalink
Merge pull request #197 from markpbaggett/recipe_0074
Browse files Browse the repository at this point in the history
Add recipe for 0074 Multiple Language Captions.
  • Loading branch information
glenrobson authored Dec 11, 2024
2 parents 07c867a + 3edd8a9 commit 303f847
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/recipes/0074-multiple-language-captions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Using Caption and Subtitle Files in Multiple Languages with Video Content
| | **Cookbook URLs** |
|--------------|-------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions/](https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions/) |
| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions/manifest.json](https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions/manifest.json) |

### Method 1 - Construct Supplementing Annotation Using the `make_annotation` helper and a dictionary of the `body` properties
```python
--8<-- "docs/recipes/scripts/0074-multiple-language-captions-method1.py"
```
62 changes: 62 additions & 0 deletions docs/recipes/scripts/0074-multiple-language-captions-method1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, KeyValueString, config, Choice

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"
base_url = "https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions"

manifest = Manifest(
id=f"{base_url}/manifest.json",
label="For ladies. French models",
rights="http://rightsstatements.org/vocab/InC/1.0/",
requiredStatement=KeyValueString(label="Rights", value="All rights reserved Cinecittà Luce spa")
)
manifest.add_label(language="it", value="Per voi signore. Modelli francesi")

canvas = manifest.make_canvas(
id=f"{base_url}/canvas"
)
video_resource = ResourceItem(
id="https://fixtures.iiif.io/video/europeana/Per_voi_signore_Modelli_francesi.mp4",
type="Video",
format="video/mp4"
)
video_hwd = {"height": 384, "width": 288, "duration": 65.0}
video_resource.set_hwd(**video_hwd)
canvas.set_hwd(**video_hwd)
painting_annotation = Annotation(
id=f"{base_url}/canvas/page/annotation",
motivation="painting",
body=video_resource,
target=canvas.id
)
annotation_page = AnnotationPage(
id=f"{base_url}/canvas/page"
)
annotation_page.add_item(painting_annotation)
canvas.add_item(annotation_page)

italian_captions = ResourceItem(
id=f"{base_url}/Per_voi_signore_Modelli_francesi_it.vtt",
type="Text",
format="text/vtt",
language="it",
)
italian_captions.add_label(language="it", value="Sottotitoli in formato WebVTT")
english_captions = ResourceItem(
id=f"{base_url}/Per_voi_signore_Modelli_francesi_en.vtt",
type="Text",
format="text/vtt",
language="en"
)
english_captions.add_label(language="en", value="Captions in WebVTT format")
choice = Choice(
items=[english_captions, italian_captions]
)

caption_annotation = canvas.make_annotation(
id=f"{base_url}/manifest.json/subtitles_captions-files-vtt",
motivation="supplementing",
body=choice,
target=canvas.id,
anno_page_id=f"{base_url}/manifest.json/anno/page/1"
)
print(manifest.json(indent=2))

0 comments on commit 303f847

Please sign in to comment.