From ed327bac242146fd347fec9c836703315fc43bac Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 19 Aug 2019 03:28:04 +0200 Subject: [PATCH] Add video playback preferences --- nitter.conf | 1 + src/prefs_impl.nim | 12 ++++++++++-- src/types.nim | 4 +++- src/views/tweet.nim | 40 +++++++++++++++++++++++++++++----------- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/nitter.conf b/nitter.conf index 2e3c023..41b961c 100644 --- a/nitter.conf +++ b/nitter.conf @@ -1,6 +1,7 @@ [Server] address = "0.0.0.0" port = 8080 +https = true # disable to enable cookies when not using https title = "nitter" staticDir = "./public" diff --git a/src/prefs_impl.nim b/src/prefs_impl.nim index 410ec95..eda6cb2 100644 --- a/src/prefs_impl.nim +++ b/src/prefs_impl.nim @@ -32,8 +32,16 @@ const prefList*: Table[string, seq[Pref]] = { ], "Media": @[ - Pref(kind: checkbox, name: "videoPlayback", - label: "Enable hls.js video playback (requires JavaScript)", + Pref(kind: checkbox, name: "mp4Playback", + label: "Enable mp4 video playback", + defaultState: true), + + Pref(kind: checkbox, name: "hlsPlayback", + label: "Enable hls video streaming (requires JavaScript)", + defaultState: false), + + Pref(kind: checkbox, name: "muteVideos", + label: "Mute videos by default", defaultState: false), Pref(kind: checkbox, name: "autoplayGifs", label: "Autoplay gifs", diff --git a/src/types.nim b/src/types.nim index 247a65c..611b361 100644 --- a/src/types.nim +++ b/src/types.nim @@ -51,7 +51,9 @@ db("cache.db", "", "", ""): .}: VideoType Prefs* = object - videoPlayback*: bool + hlsPlayback*: bool + mp4Playback*: bool + muteVideos*: bool autoplayGifs*: bool hideTweetStats*: bool hideBanner*: bool diff --git a/src/views/tweet.nim b/src/views/tweet.nim index d36ac84..4800ee2 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -45,24 +45,42 @@ proc renderAlbum(tweet: Tweet): VNode = target="_blank", style={display: flex}): genImg(photo) +proc isPlaybackEnabled(prefs: Prefs; video: Video): bool = + case video.playbackType + of mp4: prefs.mp4Playback + of m3u8, vmap: prefs.hlsPlayback + +proc renderVideoDisabled(video: Video): VNode = + buildHtml(tdiv): + img(src=video.thumb.getSigUrl("pic")) + tdiv(class="video-overlay"): + case video.playbackType + of mp4: + p: text "mp4 playback disabled in preferences" + of m3u8, vmap: + p: text "hls playback disabled in preferences" + proc renderVideo(video: Video; prefs: Prefs): VNode = buildHtml(tdiv(class="attachments")): tdiv(class="gallery-video"): tdiv(class="attachment video-container"): - let thumb = video.thumb.getSigUrl("pic") - case video.playbackType - of mp4: - video(poster=thumb, controls=""): - source(src=video.url.getSigUrl("video"), `type`="video/mp4") - of m3u8, vmap: - if prefs.videoPlayback: + if prefs.isPlaybackEnabled(video): + let thumb = video.thumb.getSigUrl("pic") + let source = video.url.getSigUrl("video") + case video.playbackType + of mp4: + if prefs.muteVideos: + video(poster=thumb, controls="", muted=""): + source(src=source, `type`="video/mp4") + else: + video(poster=thumb, controls=""): + source(src=source, `type`="video/mp4") + of m3u8, vmap: video(poster=thumb) tdiv(class="video-overlay"): p: text "Video playback not supported yet" - else: - img(src=thumb) - tdiv(class="video-overlay"): - p: text "Video playback disabled" + else: + renderVideoDisabled(video) proc renderGif(gif: Gif; prefs: Prefs): VNode = buildHtml(tdiv(class="attachments media-gif")):