Skip to content

Commit

Permalink
Add vtt for audio
Browse files Browse the repository at this point in the history
  • Loading branch information
hadro committed Aug 1, 2023
1 parent 5d9ac69 commit 7bdce50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion iiify/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,30 @@ def create_manifest3(identifier, domain=None, page=None):
anno.body = body
ap.add_item(anno)
c.add_item(ap)


#Add VTT files as captions if they exist
for count, f in enumerate([file for file in metadata['files'] if file['name'].endswith('.vtt')]):
langIdentifier = f['name'].rsplit(".", 2)[1]
filename = f['name'].rsplit(".", 2)[0]

vtt_anno = c.make_annotation(
id=f"{URI_PRIFIX}/{identifier}/{slugged_id}/page{count+2}/a{count+1}",
motivation="supplementing",
body=[{
"id": f"https://archive.org/download/{identifier}/{quote(f['name'])}",
"type": "Text",
"language": langIdentifier,
"format": "text/vtt",
"label": {"en": [f"WebVTT captions ({langIdentifier})"]},
}],
label="Captions in WebVTT format",
target=f"{c_id}",
anno_page_id=f"{URI_PRIFIX}/{identifier}/{slugged_id}/page{count+2}"
)



manifest.add_item(c)

elif mediatype == "movies":
Expand Down Expand Up @@ -530,7 +554,7 @@ def create_manifest3(identifier, domain=None, page=None):
id=f"{URI_PRIFIX}/{identifier}/{slugged_id}/page{count+2}/a{count+1}",
motivation="supplementing",
body=[{
"id": f"https://archive.org/download/{identifier}/{f['name']}",
"id": f"https://archive.org/download/{identifier}/{quote(f['name'])}",
"type": "Text",
"language": langIdentifier,
"format": "text/vtt",
Expand Down
1 change: 1 addition & 0 deletions tests/test_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_v3_single_quote_filename(self):
kaled_jalil (no derivatives)
Dokku_obrash (geo-restricted?)
m4a filetypes (No length to files?)
78_mr-sandman_the-chordettes-archie-bleyer-pat-ballard-archie-ballard_gbia0017988b (audio file with auto-generated VTT)
'''

if __name__ == '__main__':
Expand Down

0 comments on commit 7bdce50

Please sign in to comment.