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 0219 Using Caption File. #196

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/0219-using-caption-file.md
Original file line number Diff line number Diff line change
@@ -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"
```
44 changes: 44 additions & 0 deletions docs/recipes/scripts/0219-using-caption-file-method1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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=f"{base_url}/manifest.json",
label="Lunchroom Manners"
)
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=f"{base_url}/canvas/page"
)
painting_anno = Annotation(
id=f"{base_url}/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)
caption_body = ResourceItem(
id="https://fixtures.iiif.io/video/indiana/lunchroom_manners/lunchroom_manners.vtt",
type="Text",
language="en",
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",
body=caption_body,
target=f"{base_url}/canvas",
anno_page_id=f"{base_url}/canvas/page2"
)
print(manifest.json(indent=2))
Loading