From 3820a79ecd3ecec08a6cfd87e7949f11461a3d87 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 30 Aug 2019 12:32:48 +0100 Subject: [PATCH] Support embedded audio --- webinterface.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/webinterface.py b/webinterface.py index 2f0230a92..59f5bc205 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1177,6 +1177,37 @@ def htmlRemplaceEmojiFromTags(content: str,tag: {}) -> str: content=content.replace(tagItem['name'],emojiHtml) return content +def addEmbeddedAudio(content: str) -> str: + """Adds embedded audio for mp3/ogg + """ + if not ('.mp3' in content or '.ogg' in content): + return content + + extension='.mp3' + if '.ogg' in content: + extension='.ogg' + + words=content.strip('\n').split(' ') + for w in words: + if extension not in w: + continue + if w.endswith('.'): + w=w[:-1] + if w.endswith(';'): + w=w[:-1] + if w.endswith(':'): + w=w[:-1] + if not w.endswidth(extension): + continue + if not (w.startswith('http') or w.startswith('dat:')): + continue + url=w + content+='' + return content + def addEmbeddedVideo(content: str,width=400,height=300) -> str: """Adds embedded videos """ @@ -1482,6 +1513,7 @@ def individualPostAsHtml(baseDir: str, \ if not postJsonObject['object']['sensitive']: contentStr=postJsonObject['object']['content']+attachmentStr contentStr=addEmbeddedVideo(contentStr) + contentStr=addEmbeddedAudio(contentStr) else: postID='post'+str(createPassword(8)) contentStr='' @@ -1495,6 +1527,7 @@ def individualPostAsHtml(baseDir: str, \ contentStr+='
' contentStr+=postJsonObject['object']['content']+attachmentStr contentStr=addEmbeddedVideo(contentStr) + contentStr=addEmbeddedAudio(contentStr) contentStr+='
' if postJsonObject['object'].get('tag'):