fix video embeds

This commit is contained in:
Cynthia Foxwell 2024-07-13 13:59:15 -06:00
parent 6e3fbff174
commit cc1f7d706c
6 changed files with 25 additions and 19 deletions

View file

@ -38,7 +38,7 @@ proc shortLink*(text: string; length=28): string =
result = text.replace(wwwRegex, "")
if result.len > length:
result = result[0 ..< length] & ""
proc stripHtml*(text: string; shorten=false): string =
var html = parseHtml(text)
for el in html.findAll("a"):

View file

@ -1,16 +1,15 @@
# SPDX-License-Identifier: AGPL-3.0-only
import asyncdispatch, strformat, logging
import config
from net import Port
from htmlgen import a
from os import getEnv
#from os import getEnv
import jester
import types, config, prefs, formatters, redis_cache, http_pool
import views/[general, about]
import routes/[
preferences, timeline, status, media, search, rss, list, debug,
preferences, timeline, status, media, search, rss, list, #debug,
unsupported, embed, resolver, router_utils, home, follow, twitter_api]
const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances"
@ -18,7 +17,7 @@ const issuesUrl = "https://github.com/zedeus/nitter/issues"
#let accountsPath = getEnv("NITTER_ACCOUNTS_FILE", "./guest_accounts.json")
# initAccountPool(cfg, accountsPath)
#initAccountPool(cfg, accountsPath)
if not cfg.enableDebug:
# Silence Jester's query warning

View file

@ -73,11 +73,17 @@ proc createStatusRouter*(cfg: Config) =
video = ""
if conv.tweet.video.isSome():
images = @[get(conv.tweet.video).thumb]
video = getVideoEmbed(cfg, conv.tweet.id)
let videoObj = get(conv.tweet.video)
images = @[videoObj.thumb]
let vars = videoObj.variants.filterIt(it.contentType == mp4)
# idk why this wont sort when it sorts everywhere else
#video = vars.sortedByIt(it.bitrate)[^1].url
video = vars[^1].url
elif conv.tweet.gif.isSome():
images = @[get(conv.tweet.gif).thumb]
video = getPicUrl(get(conv.tweet.gif).url)
let gif = get(conv.tweet.gif)
images = @[gif.thumb]
video = getPicUrl(gif.url)
elif conv.tweet.card.isSome():
let card = conv.tweet.card.get()
if card.image.len > 0:
@ -99,6 +105,6 @@ proc createStatusRouter*(cfg: Config) =
get "/i/web/status/@id":
redirect("/i/status/" & @"id")
get "/@name/thread/@id/?":
redirect("/$1/status/$2" % [@"name", @"id"])

View file

@ -1,22 +1,24 @@
# SPDX-License-Identifier: AGPL-3.0-only
import options
import options, algorithm, sequtils
import karax/[karaxdsl, vdom]
from jester import Request
import ".."/[types, formatters]
import ../types
import general, tweet
const doctype = "<!DOCTYPE html>\n"
proc renderVideoEmbed*(tweet: Tweet; cfg: Config; req: Request): string =
let thumb = get(tweet.video).thumb
let vidUrl = getVideoEmbed(cfg, tweet.id)
let video = get(tweet.video)
let thumb = video.thumb
let vars = video.variants.filterIt(it.contentType == mp4)
let vidUrl = vars.sortedByIt(it.bitrate)[^1].url
let prefs = Prefs(hlsPlayback: true, mp4Playback: true)
let node = buildHtml(html(lang="en")):
renderHead(prefs, cfg, req, video=vidUrl, images=(@[thumb]))
body:
tdiv(class="embed-video"):
renderVideo(get(tweet.video), prefs, "")
renderVideo(video, prefs, "")
result = doctype & $node

View file

@ -116,9 +116,8 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
meta(property="twitter:card", content="summary_large_image")
if video.len > 0:
let videoUrl = getUrlPrefix(cfg) & video
meta(property="og:video:url", content=videoUrl)
meta(property="og:video:secure_url", content=videoUrl)
meta(property="og:video:url", content=video)
meta(property="og:video:secure_url", content=video)
meta(property="og:video:type", content="video/mp4")
# this is last so images are also preloaded

View file

@ -100,7 +100,7 @@ proc renderVideo*(video: Video; prefs: Prefs; path: string): VNode =
else:
let
vars = video.variants.filterIt(it.contentType == playbackType)
vidUrl = vars.sortedByIt(it.resolution)[^1].url
vidUrl = vars.sortedByIt(it.bitrate)[^1].url
source = if prefs.proxyVideos: getVidUrl(vidUrl)
else: vidUrl
case playbackType