Skip to content

Commit

Permalink
Video embedding improvements:
Browse files Browse the repository at this point in the history
- 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?)
  • Loading branch information
shaver committed Feb 9, 2025
1 parent 0817911 commit f7f26bc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions App/Misc/HTMLRenderingHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit f7f26bc

Please sign in to comment.