Do some minimal validation on video transcripts

main
Bob Mottram 2023-02-19 13:17:09 +00:00
parent 924c58a0fe
commit 3df7703d42
1 changed files with 9 additions and 0 deletions

View File

@ -553,6 +553,14 @@ def _store_video_transcript(video_transcript: str,
media_filename: str) -> bool: media_filename: str) -> bool:
"""Stores a video transcript """Stores a video transcript
""" """
video_transcript = video_transcript.strip()
if not video_transcript.startswith('WEBVTT') or \
'-->' not in video_transcript or \
':' not in video_transcript or \
'- ' not in video_transcript:
print('WARN: does not look like a video transcript ' +
video_transcript)
return False
try: try:
with open(media_filename + '.vtt', 'w+', encoding='utf-8') as fp_vtt: with open(media_filename + '.vtt', 'w+', encoding='utf-8') as fp_vtt:
fp_vtt.write(video_transcript) fp_vtt.write(video_transcript)
@ -633,6 +641,7 @@ def attach_media(base_dir: str, http_prefix: str,
attachment_json['width'] = attach_image_width attachment_json['width'] = attach_image_width
attachment_json['height'] = attach_image_height attachment_json['height'] = attach_image_height
# create video transcript
post_json['attachment'] = [attachment_json] post_json['attachment'] = [attachment_json]
if video_transcript and 'video' in media_type: if video_transcript and 'video' in media_type:
if _store_video_transcript(video_transcript, media_filename): if _store_video_transcript(video_transcript, media_filename):