-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from markpbaggett/recipe_0074
Add recipe for 0074 Multiple Language Captions.
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
62
docs/recipes/scripts/0074-multiple-language-captions-method1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |