Prefer mp4 to m3u8 for Video Playback if proxyVideos is off

m3u8 videos only work when the proxy is enabled. Further, this allows
video playback without Javascript.

This is only done when proxying is disabled to avoid excessive memory
usage on the nitter instance that would result from loading longer
videos in a single chunk.
This commit is contained in:
girst 2022-02-25 19:26:24 +01:00
parent 683c052036
commit 0633ec2c39

View file

@ -62,11 +62,14 @@ proc renderAlbum(tweet: Tweet): VNode =
a(href=getPicUrl(orig), class="still-image", target="_blank"): a(href=getPicUrl(orig), class="still-image", target="_blank"):
genImg(small) genImg(small)
proc isPlaybackEnabled(prefs: Prefs; video: Video): bool = proc isPlaybackEnabled(prefs: Prefs; playbackType: VideoType): bool =
case video.playbackType case playbackType
of mp4: prefs.mp4Playback of mp4: prefs.mp4Playback
of m3u8, vmap: prefs.hlsPlayback of m3u8, vmap: prefs.hlsPlayback
proc hasMp4Url(video: Video): bool =
video.variants.anyIt(it.contentType == mp4)
proc renderVideoDisabled(video: Video; path: string): VNode = proc renderVideoDisabled(video: Video; path: string): VNode =
buildHtml(tdiv(class="video-overlay")): buildHtml(tdiv(class="video-overlay")):
case video.playbackType case video.playbackType
@ -87,6 +90,9 @@ proc renderVideo*(video: Video; prefs: Prefs; path: string): VNode =
let container = let container =
if video.description.len > 0 or video.title.len > 0: " card-container" if video.description.len > 0 or video.title.len > 0: " card-container"
else: "" else: ""
let playbackType =
if not prefs.proxyVideos and video.hasMp4Url: mp4
else: video.playbackType
buildHtml(tdiv(class="attachments card")): buildHtml(tdiv(class="attachments card")):
tdiv(class="gallery-video" & container): tdiv(class="gallery-video" & container):
@ -95,13 +101,13 @@ proc renderVideo*(video: Video; prefs: Prefs; path: string): VNode =
if not video.available: if not video.available:
img(src=thumb) img(src=thumb)
renderVideoUnavailable(video) renderVideoUnavailable(video)
elif not prefs.isPlaybackEnabled(video): elif not prefs.isPlaybackEnabled(playbackType):
img(src=thumb) img(src=thumb)
renderVideoDisabled(video, path) renderVideoDisabled(video, path)
else: else:
let vid = video.variants.filterIt(it.contentType == video.playbackType) let vid = video.variants.filterIt(it.contentType == playbackType)
let source = getVidUrl(vid[0].url) let source = if prefs.proxyVideos: getVidUrl(vid[0].url) else: vid[0].url
case video.playbackType case playbackType
of mp4: of mp4:
if prefs.muteVideos: if prefs.muteVideos:
video(poster=thumb, controls="", muted=""): video(poster=thumb, controls="", muted=""):