diff --git a/webinterface.py b/webinterface.py index e068b4c39..8611450c3 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1208,6 +1208,39 @@ def addEmbeddedAudio(content: str) -> str: content+='' return content +def addEmbeddedVideo(content: str,width=400,height=300) -> str: + """Adds embedded video for mp4/webm/ogv + """ + if not ('.mp4' in content or '.webm' in content or '.ogv' in content): + return content + + extension='.mp4' + if '.webm' in content: + extension='.webm' + elif '.ogv' in content: + extension='.ogv' + + 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:') or '/' in w): + continue + url=w + content+='' + return content + def addEmbeddedVideoFromSites(content: str,width=400,height=300) -> str: """Adds embedded videos """ @@ -1514,6 +1547,7 @@ def individualPostAsHtml(baseDir: str, \ contentStr=postJsonObject['object']['content']+attachmentStr contentStr=addEmbeddedVideoFromSites(contentStr) contentStr=addEmbeddedAudio(contentStr) + contentStr=addEmbeddedVideo(contentStr) else: postID='post'+str(createPassword(8)) contentStr='' @@ -1528,6 +1562,7 @@ def individualPostAsHtml(baseDir: str, \ contentStr+=postJsonObject['object']['content']+attachmentStr contentStr=addEmbeddedVideoFromSites(contentStr) contentStr=addEmbeddedAudio(contentStr) + contentStr=addEmbeddedVideo(contentStr) contentStr+='' if postJsonObject['object'].get('tag'):