From 9bfd159402a7c1e1d55085fd87e08d1e9b9c5c17 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 18 Feb 2023 19:21:24 +0000 Subject: [PATCH] Support video transcripts --- webapp_utils.py | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/webapp_utils.py b/webapp_utils.py index 43348c65f..9058986c2 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -1237,6 +1237,27 @@ def get_post_attachments_as_html(base_dir: str, if post_json_object['object'].get('id'): post_id = post_json_object['object']['id'] post_id = remove_id_ending(post_id).replace('/', '--') + + # obtain transcripts + transcripts = {} + for attach in post_json_object['object']['attachment']: + if not attach.get('mediaType'): + continue + if attach['mediaType'] != 'text/vtt': + continue + name = None + if attach.get('name'): + name = attach['name'] + elif attach.get('hreflang'): + name = attach['hreflang'] + url = None + if attach.get('url'): + url = attach['url'] + elif attach.get('href'): + url = attach['href'] + if name and url: + transcripts[name] = url + for attach in post_json_object['object']['attachment']: if not (attach.get('mediaType') and attach.get('url')): continue @@ -1423,8 +1444,15 @@ def get_post_attachments_as_html(base_dir: str, '" alt="' + image_description + \ '" title="' + image_description + \ '" class="attachment" type="video/' + \ - extension + '">' - idx = 'Your browser does not support the video tag.' + extension + '">\n' + if transcripts: + for transcript_name, transcript_url in \ + transcripts.items(): + gallery_str += \ + '\n' + idx = 'Your browser does not support the video tag.\n' gallery_str += translate[idx] gallery_str += ' \n' gallery_str += ' \n' @@ -1458,13 +1486,20 @@ def get_post_attachments_as_html(base_dir: str, ' ' + attachment_str += '\n ' attachment_ctr += 1 elif _is_audio_mime_type(media_type): extension = '.mp3'