浏览代码

Add video playback preferences

Zed 7 年之前
父节点
当前提交
ed327bac24
共有 4 个文件被更改,包括 43 次插入14 次删除
  1. 1 0
      nitter.conf
  2. 10 2
      src/prefs_impl.nim
  3. 3 1
      src/types.nim
  4. 29 11
      src/views/tweet.nim

+ 1 - 0
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"
 

+ 10 - 2
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",

+ 3 - 1
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

+ 29 - 11
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")):