From ca43402beda7b6e3dab3a7e0f3e4cd3094d5134f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 7 Mar 2021 10:24:27 +0000 Subject: [PATCH] Tidying --- webapp_utils.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/webapp_utils.py b/webapp_utils.py index efda6070c..4ad922a5f 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -840,6 +840,20 @@ def _isAttachedImage(attachmentFilename: str) -> bool: return False +def _isAttachedVideo(attachmentFilename: str) -> bool: + """Is the given attachment filename a video? + """ + if '.' not in attachmentFilename: + return False + videoExt = ( + 'mp4', 'webm', 'ogv' + ) + ext = attachmentFilename.split('.')[-1] + if ext in videoExt: + return True + return False + + def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {}, isMuted: bool, avatarLink: str, replyStr: str, announceStr: str, likeStr: str, @@ -907,12 +921,8 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {}, imageDescription + '" class="attachment">\n' attachmentCtr += 1 elif _isVideoMimeType(mediaType): - extension = '.mp4' - if attach['url'].endswith('.webm'): - extension = '.webm' - elif attach['url'].endswith('.ogv'): - extension = '.ogv' - if attach['url'].endswith(extension): + if _isAttachedVideo(attach['url']): + extension = attach['url'].split('.')[-1] if attachmentCtr > 0: attachmentStr += '
' if boxName == 'tlmedia': @@ -926,7 +936,7 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {}, '" alt="' + imageDescription + \ '" title="' + imageDescription + \ '" class="attachment" type="video/' + \ - extension.replace('.', '') + '">' + extension + '">' idx = 'Your browser does not support the video tag.' galleryStr += translate[idx] galleryStr += ' \n' @@ -960,7 +970,7 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {}, '' + extension + '">' attachmentStr += \ translate['Your browser does not support the video tag.'] attachmentStr += ''