fix video embeds
This commit is contained in:
parent
6e3fbff174
commit
cc1f7d706c
6 changed files with 25 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue