From e9d49c91b0974324a3e16cd246a91b05ee3c9df3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 6 Mar 2021 23:03:14 +0000 Subject: [PATCH 01/19] Check that media file exists --- media.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/media.py b/media.py index eb0df3d43..66b6823e3 100644 --- a/media.py +++ b/media.py @@ -54,6 +54,10 @@ def removeMetaData(imageFilename: str, outputFilename: str) -> None: def _isMedia(imageFilename: str) -> bool: + """Is the given file a media file? + """ + if not os.path.isfile(_isMedia): + return False permittedMedia = getMediaExtensions() for m in permittedMedia: if imageFilename.endswith('.' + m): From dc66f79a3af3170627834d8dfac2135e23a3a45a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 6 Mar 2021 23:04:58 +0000 Subject: [PATCH 02/19] Debug --- media.py | 1 + 1 file changed, 1 insertion(+) diff --git a/media.py b/media.py index 66b6823e3..d644dca97 100644 --- a/media.py +++ b/media.py @@ -57,6 +57,7 @@ def _isMedia(imageFilename: str) -> bool: """Is the given file a media file? """ if not os.path.isfile(_isMedia): + print('Media file does not exist ' + imageFilename) return False permittedMedia = getMediaExtensions() for m in permittedMedia: From ada6680cf97c09accace981f6593eeadebb5860e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 6 Mar 2021 23:07:54 +0000 Subject: [PATCH 03/19] Image filename --- media.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/media.py b/media.py index d644dca97..358c98932 100644 --- a/media.py +++ b/media.py @@ -56,8 +56,8 @@ def removeMetaData(imageFilename: str, outputFilename: str) -> None: def _isMedia(imageFilename: str) -> bool: """Is the given file a media file? """ - if not os.path.isfile(_isMedia): - print('Media file does not exist ' + imageFilename) + if not os.path.isfile(imageFilename): + print('WARN: Media file does not exist ' + imageFilename) return False permittedMedia = getMediaExtensions() for m in permittedMedia: From 6b2f22d562d390a099e3eacd197398dcc9f07c4e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 6 Mar 2021 23:16:54 +0000 Subject: [PATCH 04/19] Check that media file is written --- content.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/content.py b/content.py index c1b2ff418..a0bbab004 100644 --- a/content.py +++ b/content.py @@ -973,9 +973,15 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, os.remove(possibleOtherFormat) fd = open(filename, 'wb') + if not fd: + return None, None fd.write(mediaBytes[startPos:]) fd.close() + if not os.path.isfile(filename): + print('WARN: Media file could not be written to file: ' + filename) + return None, None + return filename, attachmentMediaType From 3e7e64f5d01ef97c45e418cfd1c7b992d07d7264 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 6 Mar 2021 23:19:03 +0000 Subject: [PATCH 05/19] Debug --- content.py | 1 + 1 file changed, 1 insertion(+) diff --git a/content.py b/content.py index a0bbab004..32858c926 100644 --- a/content.py +++ b/content.py @@ -981,6 +981,7 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, if not os.path.isfile(filename): print('WARN: Media file could not be written to file: ' + filename) return None, None + print('Uploaded media file written: ' + filename) return filename, attachmentMediaType From c6da9ce269062301dee1cc088d5e1ca574506e5c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 6 Mar 2021 23:29:44 +0000 Subject: [PATCH 06/19] Filename for video --- daemon.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/daemon.py b/daemon.py index ccf9b446e..cfefb8300 100644 --- a/daemon.py +++ b/daemon.py @@ -12673,7 +12673,9 @@ class PubServer(BaseHTTPRequestHandler): postImageFilename) else: if os.path.isfile(filename): - os.rename(filename, filename.replace('.temp', '')) + newFilename = filename.replace('.temp', '') + os.rename(filename, newFilename) + filename = newFilename fields = \ extractTextFieldsInPOST(postBytes, boundary, From 06f324b7d65b3e649afd5d4abbc6f1a26a45ec60 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 7 Mar 2021 10:15:17 +0000 Subject: [PATCH 07/19] Mime type detection functions --- webapp_utils.py | 77 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/webapp_utils.py b/webapp_utils.py index a0f7d0076..efda6070c 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -785,6 +785,61 @@ def addEmojiToDisplayName(baseDir: str, httpPrefix: str, return displayName +def _isImageMimeType(mimeType: str) -> bool: + """Is the given mime type an image? + """ + imageMimeTypes = ( + 'image/png', + 'image/jpeg', + 'image/webp', + 'image/avif', + 'image/svg+xml', + 'image/gif' + ) + if mimeType in imageMimeTypes: + return True + return False + + +def _isVideoMimeType(mimeType: str) -> bool: + """Is the given mime type a video? + """ + videoMimeTypes = ( + 'video/mp4', + 'video/webm', + 'video/ogv' + ) + if mimeType in videoMimeTypes: + return True + return False + + +def _isAudioMimeType(mimeType: str) -> bool: + """Is the given mime type an audio file? + """ + audioMimeTypes = ( + 'audio/mpeg', + 'audio/ogg' + ) + if mimeType in audioMimeTypes: + return True + return False + + +def _isAttachedImage(attachmentFilename: str) -> bool: + """Is the given attachment filename an image? + """ + if '.' not in attachmentFilename: + return False + imageExt = ( + 'png', 'jpg', 'jpeg', 'webp', 'avif', 'svg', 'gif' + ) + ext = attachmentFilename.split('.')[-1] + if ext in imageExt: + return True + return False + + def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {}, isMuted: bool, avatarLink: str, replyStr: str, announceStr: str, likeStr: str, @@ -810,19 +865,8 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {}, imageDescription = '' if attach.get('name'): imageDescription = attach['name'].replace('"', "'") - if mediaType == 'image/png' or \ - mediaType == 'image/jpeg' or \ - mediaType == 'image/webp' or \ - mediaType == 'image/avif' or \ - mediaType == 'image/svg+xml' or \ - mediaType == 'image/gif': - if attach['url'].endswith('.png') or \ - attach['url'].endswith('.jpg') or \ - attach['url'].endswith('.jpeg') or \ - attach['url'].endswith('.webp') or \ - attach['url'].endswith('.avif') or \ - attach['url'].endswith('.svg') or \ - attach['url'].endswith('.gif'): + if _isImageMimeType(mediaType): + if _isAttachedImage(attach['url']): if attachmentCtr > 0: attachmentStr += '
' if boxName == 'tlmedia': @@ -862,9 +906,7 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {}, '" alt="' + imageDescription + '" title="' + \ imageDescription + '" class="attachment">\n' attachmentCtr += 1 - elif (mediaType == 'video/mp4' or - mediaType == 'video/webm' or - mediaType == 'video/ogv'): + elif _isVideoMimeType(mediaType): extension = '.mp4' if attach['url'].endswith('.webm'): extension = '.webm' @@ -923,8 +965,7 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {}, translate['Your browser does not support the video tag.'] attachmentStr += '' attachmentCtr += 1 - elif (mediaType == 'audio/mpeg' or - mediaType == 'audio/ogg'): + elif _isAudioMimeType(mediaType): extension = '.mp3' if attach['url'].endswith('.ogg'): extension = '.ogg' From ca43402beda7b6e3dab3a7e0f3e4cd3094d5134f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 7 Mar 2021 10:24:27 +0000 Subject: [PATCH 08/19] 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 += '' From 3181398df521bc60892e18372efbcd179d4274db Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 7 Mar 2021 10:58:18 +0000 Subject: [PATCH 09/19] Allow video and audio in media timeline --- posts.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/posts.py b/posts.py index a2340eaa1..d010d8d23 100644 --- a/posts.py +++ b/posts.py @@ -3055,7 +3055,10 @@ def _addPostStringToTimeline(postStr: str, boxname: str, return False elif boxname == 'tlmedia': if '"Create"' in postStr: - if 'mediaType' not in postStr or 'image/' not in postStr: + if ('mediaType' not in postStr or \ + ('image/' not in postStr and + 'video/' not in postStr and + 'audio/' not in postStr)): return False # add the post to the dictionary postsInBox.append(postStr) From c19a072c97a17b63e2b80286e5e7bb817bd0acb5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 7 Mar 2021 11:55:06 +0000 Subject: [PATCH 10/19] Video style --- epicyon-profile.css | 35 +++++++++++++++++++++++++++++++++++ webapp_utils.py | 6 +++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/epicyon-profile.css b/epicyon-profile.css index 6ef938ec7..aa4dfc68c 100644 --- a/epicyon-profile.css +++ b/epicyon-profile.css @@ -184,6 +184,41 @@ body, html { image-rendering: var(--rendering); } +video { + width: 100%; +} + +figure[data-fullscreen=true] { + max-width: 100%; + width: 100%; + margin: 0; + padding: 0; + max-height: 100%; +} + +figure[data-fullscreen=true] video { + height: auto; +} + +figure[data-fullscreen=true] .controls { + position: absolute; + bottom: 2%; + width: 100%; + z-index: 2147483647; +} +figure[data-fullscreen=true] .controls li { + width: 5%; +} +figure[data-fullscreen=true] .controls .progress { + width: 68%; +} + +figure { + padding-left: 0; + padding-right: 0; + height: auto; +} + .cw { font-style: var(--cw-style); font-weight: var(--cw-weight); diff --git a/webapp_utils.py b/webapp_utils.py index 4ad922a5f..626fb6389 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -930,7 +930,10 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {}, if not isMuted: galleryStr += ' \n' galleryStr += \ - '