From f7f26bc459e42e96179b99fbe09056462f496ccb Mon Sep 17 00:00:00 2001 From: Mike Shaver Date: Sun, 9 Feb 2025 09:55:13 -0500 Subject: [PATCH] Video embedding improvements: - Support embedding "imgur.io" links, incl webm and gifv (:corsair:) - Any other raw .mp4 link because I'm sick of chasing new popular domains (Maybe we don't need special imgur handling any more?) --- App/Misc/HTMLRenderingHelpers.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/App/Misc/HTMLRenderingHelpers.swift b/App/Misc/HTMLRenderingHelpers.swift index bee360af2..a6fe1f5f0 100644 --- a/App/Misc/HTMLRenderingHelpers.swift +++ b/App/Misc/HTMLRenderingHelpers.swift @@ -294,9 +294,11 @@ extension HTMLDocument { if containingPostIsNWS(node: a) { continue } - + let lowerHost = host.lowercased() + if let ext = href.range(of: #"(\.gifv|\.webm|\.mp4)$"#, options: .regularExpression) { - if host.lowercased().hasSuffix("imgur.com") { + if lowerHost.hasSuffix("imgur.com") || + lowerHost.hasSuffix("imgur.io") { let videoElement = HTMLElement(tagName: "video", attributes: [ "width": "300", "preload":"metadata", @@ -309,8 +311,9 @@ extension HTMLDocument { a.parent?.replace(child: a, with: videoElement) } - if host.lowercased().hasSuffix(".discordapp.com") && - href.hasSuffix(".mp4") + + // any raw .mp4 URLs can embed, what the hell + if href == a.textContent && href.hasSuffix(".mp4") { let videoElement = HTMLElement(tagName: "video", attributes: [ "width": "300", @@ -323,7 +326,6 @@ extension HTMLDocument { a.parent?.replace(child: a, with: videoElement) } - //todo gifcat mp4 files } // only replace youtube links that are raw URLs