fix video embeds
This commit is contained in:
parent
6e3fbff174
commit
cc1f7d706c
6 changed files with 25 additions and 19 deletions
|
@ -38,7 +38,7 @@ proc shortLink*(text: string; length=28): string =
|
||||||
result = text.replace(wwwRegex, "")
|
result = text.replace(wwwRegex, "")
|
||||||
if result.len > length:
|
if result.len > length:
|
||||||
result = result[0 ..< length] & "…"
|
result = result[0 ..< length] & "…"
|
||||||
|
|
||||||
proc stripHtml*(text: string; shorten=false): string =
|
proc stripHtml*(text: string; shorten=false): string =
|
||||||
var html = parseHtml(text)
|
var html = parseHtml(text)
|
||||||
for el in html.findAll("a"):
|
for el in html.findAll("a"):
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import asyncdispatch, strformat, logging
|
import asyncdispatch, strformat, logging
|
||||||
import config
|
|
||||||
from net import Port
|
from net import Port
|
||||||
from htmlgen import a
|
from htmlgen import a
|
||||||
from os import getEnv
|
#from os import getEnv
|
||||||
|
|
||||||
import jester
|
import jester
|
||||||
|
|
||||||
import types, config, prefs, formatters, redis_cache, http_pool
|
import types, config, prefs, formatters, redis_cache, http_pool
|
||||||
import views/[general, about]
|
import views/[general, about]
|
||||||
import routes/[
|
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]
|
unsupported, embed, resolver, router_utils, home, follow, twitter_api]
|
||||||
|
|
||||||
const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances"
|
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")
|
#let accountsPath = getEnv("NITTER_ACCOUNTS_FILE", "./guest_accounts.json")
|
||||||
|
|
||||||
# initAccountPool(cfg, accountsPath)
|
#initAccountPool(cfg, accountsPath)
|
||||||
|
|
||||||
if not cfg.enableDebug:
|
if not cfg.enableDebug:
|
||||||
# Silence Jester's query warning
|
# Silence Jester's query warning
|
||||||
|
|
|
@ -73,11 +73,17 @@ proc createStatusRouter*(cfg: Config) =
|
||||||
video = ""
|
video = ""
|
||||||
|
|
||||||
if conv.tweet.video.isSome():
|
if conv.tweet.video.isSome():
|
||||||
images = @[get(conv.tweet.video).thumb]
|
let videoObj = get(conv.tweet.video)
|
||||||
video = getVideoEmbed(cfg, conv.tweet.id)
|
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():
|
elif conv.tweet.gif.isSome():
|
||||||
images = @[get(conv.tweet.gif).thumb]
|
let gif = get(conv.tweet.gif)
|
||||||
video = getPicUrl(get(conv.tweet.gif).url)
|
images = @[gif.thumb]
|
||||||
|
video = getPicUrl(gif.url)
|
||||||
elif conv.tweet.card.isSome():
|
elif conv.tweet.card.isSome():
|
||||||
let card = conv.tweet.card.get()
|
let card = conv.tweet.card.get()
|
||||||
if card.image.len > 0:
|
if card.image.len > 0:
|
||||||
|
@ -99,6 +105,6 @@ proc createStatusRouter*(cfg: Config) =
|
||||||
|
|
||||||
get "/i/web/status/@id":
|
get "/i/web/status/@id":
|
||||||
redirect("/i/status/" & @"id")
|
redirect("/i/status/" & @"id")
|
||||||
|
|
||||||
get "/@name/thread/@id/?":
|
get "/@name/thread/@id/?":
|
||||||
redirect("/$1/status/$2" % [@"name", @"id"])
|
redirect("/$1/status/$2" % [@"name", @"id"])
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import options
|
import options, algorithm, sequtils
|
||||||
import karax/[karaxdsl, vdom]
|
import karax/[karaxdsl, vdom]
|
||||||
from jester import Request
|
from jester import Request
|
||||||
|
|
||||||
import ".."/[types, formatters]
|
import ../types
|
||||||
import general, tweet
|
import general, tweet
|
||||||
|
|
||||||
const doctype = "<!DOCTYPE html>\n"
|
const doctype = "<!DOCTYPE html>\n"
|
||||||
|
|
||||||
proc renderVideoEmbed*(tweet: Tweet; cfg: Config; req: Request): string =
|
proc renderVideoEmbed*(tweet: Tweet; cfg: Config; req: Request): string =
|
||||||
let thumb = get(tweet.video).thumb
|
let video = get(tweet.video)
|
||||||
let vidUrl = getVideoEmbed(cfg, tweet.id)
|
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 prefs = Prefs(hlsPlayback: true, mp4Playback: true)
|
||||||
let node = buildHtml(html(lang="en")):
|
let node = buildHtml(html(lang="en")):
|
||||||
renderHead(prefs, cfg, req, video=vidUrl, images=(@[thumb]))
|
renderHead(prefs, cfg, req, video=vidUrl, images=(@[thumb]))
|
||||||
|
|
||||||
body:
|
body:
|
||||||
tdiv(class="embed-video"):
|
tdiv(class="embed-video"):
|
||||||
renderVideo(get(tweet.video), prefs, "")
|
renderVideo(video, prefs, "")
|
||||||
|
|
||||||
result = doctype & $node
|
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")
|
meta(property="twitter:card", content="summary_large_image")
|
||||||
|
|
||||||
if video.len > 0:
|
if video.len > 0:
|
||||||
let videoUrl = getUrlPrefix(cfg) & video
|
meta(property="og:video:url", content=video)
|
||||||
meta(property="og:video:url", content=videoUrl)
|
meta(property="og:video:secure_url", content=video)
|
||||||
meta(property="og:video:secure_url", content=videoUrl)
|
|
||||||
meta(property="og:video:type", content="video/mp4")
|
meta(property="og:video:type", content="video/mp4")
|
||||||
|
|
||||||
# this is last so images are also preloaded
|
# this is last so images are also preloaded
|
||||||
|
|
|
@ -100,7 +100,7 @@ proc renderVideo*(video: Video; prefs: Prefs; path: string): VNode =
|
||||||
else:
|
else:
|
||||||
let
|
let
|
||||||
vars = video.variants.filterIt(it.contentType == playbackType)
|
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)
|
source = if prefs.proxyVideos: getVidUrl(vidUrl)
|
||||||
else: vidUrl
|
else: vidUrl
|
||||||
case playbackType
|
case playbackType
|
||||||
|
|
Loading…
Reference in a new issue