Skip to content

Commit

Permalink
Adding support for multilingual vtt files
Browse files Browse the repository at this point in the history
  • Loading branch information
glenrobson committed May 16, 2024
1 parent b45bd71 commit f5df7fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
14 changes: 7 additions & 7 deletions iiify/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,12 @@ def create_manifest3(identifier, domain=None, page=None):
originals.append(f)

if f['format'] == 'Web Video Text Tracks':
# Example: 34C3_-_International_Image_Interoperability_Framework_IIIF_Kulturinstitutionen_schaffen_interop-SvH4fbjOT0A.autogenerated.vtt
sourceFilename = f['name'].replace('.autogenerated.vtt', '')
# Example: cruz-test.en.vtt
sourceFilename = sourceFilename.replace('[a-z][a-z].vtt', '')

vttfiles[sourceFilename] = [f]
# Example: cruz-test.en.vtt and 34C3_-_International_Image_Interoperability_Framework_IIIF_Kulturinstitutionen_schaffen_interop-SvH4fbjOT0A.autogenerated.vtt
sourceFilename = re.sub('\.[a-zA-H-]*\.vtt', '', f['name'])
if sourceFilename not in vttfiles:
vttfiles[sourceFilename] = []
vttfiles[sourceFilename].append(f)

# create the canvases for each original
for file in [f for f in originals if f['format'] in ['MPEG4', 'h.264 MPEG4', '512Kb MPEG4', 'HiRes MPEG4', 'MPEG2', 'h.264', 'Matroska', 'Ogg Video', 'Ogg Theora', 'WebM', 'Windows Media', 'Cinepack']]:
Expand Down Expand Up @@ -552,7 +552,7 @@ def create_manifest3(identifier, domain=None, page=None):
# Assume langauge
splitName = vttFile['name'].split(".")
lang = splitName[-2]
vtAnno.body.add_label(lang, language=lang)
vtAnno.body.add_label(lang, language="none")
vtAnno.body.language = lang

vttNo += 1
Expand Down
17 changes: 17 additions & 0 deletions tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ def test_vtt_autogenerated(self):
self.assertFalse("language" in body, "We don't know the language for this item so there shouldn't be a language specified")
self.assertEqual(body['id'], "https://archive.org/download/youtube-SvH4fbjOT0A/34C3_-_International_Image_Interoperability_Framework_IIIF_Kulturinstitutionen_schaffen_interop-SvH4fbjOT0A.autogenerated.vtt","Unexpected URL for the VTT file")

def test_vtt_multilingual(self):
resp = self.test_app.get("/iiif/3/cruz-test/manifest.json?recache=true")
self.assertEqual(resp.status_code, 200)
manifest = resp.json

canvas = manifest['items'][0]
self.assertTrue('annotations' in canvas, 'Expected annotations in Canvas')
self.assertEqual(len(canvas['annotations']), 1, 'Expected one AnnotationPage')
annotations = canvas['annotations'][0]['items']
self.assertEqual(len(annotations), 104, 'Expected all 104 langues')

# Check welsh
for item in annotations:
self.assertTrue('language' in item['body'], f"All vtt files should have a language: {item}")
if item['body']['language'] == 'cy':
self.assertEqual(item['body']['id'], 'https://archive.org/download/cruz-test/cruz-test.cy.vtt', 'Unexpected link for the Welsh vtt file')


if __name__ == '__main__':
unittest.main()

0 comments on commit f5df7fe

Please sign in to comment.