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 recipe for 0074 Multiple Language Captions. #197

Merged
merged 6 commits into from
Dec 11, 2024
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
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))
Loading