This commit is contained in:
Butter Cat 2024-01-11 20:58:06 -08:00 committed by GitHub
commit 3ac8053e3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 22 deletions

View file

@ -21,6 +21,7 @@ redisMaxConnections = 30
[Config] [Config]
hmacKey = "secretkey" # random key for cryptographic signing of video urls hmacKey = "secretkey" # random key for cryptographic signing of video urls
nonceString = "secretstring" # random string for the Content-Security-Policy header with script-src
base64Media = false # use base64 encoding for proxied media urls base64Media = false # use base64 encoding for proxied media urls
enableRSS = true # set this to false to disable RSS feeds enableRSS = true # set this to false to disable RSS feeds
enableDebug = false # enable request logs and debug endpoints (/.accounts) enableDebug = false # enable request logs and debug endpoints (/.accounts)

View file

@ -1,25 +1,40 @@
// @license http://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0 // @license http://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
function playVideo(overlay) { function playVideo() {
const video = overlay.parentElement.querySelector('video'); const video_overlay = document.getElementsByClassName("video-overlay");
const url = video.getAttribute("data-url");
video.setAttribute("controls", ""); for (var i = 0 ; i < video_overlay.length; i++) {
overlay.style.display = "none"; video_overlay[i].addEventListener('click', function () {
if (Hls.isSupported()) { const video = this.parentElement.querySelector('video');
var hls = new Hls({autoStartLoad: false}); const url = video.getAttribute("data-url");
hls.loadSource(url); video.setAttribute("controls", "");
hls.attachMedia(video); this.style.display = "none";
hls.on(Hls.Events.MANIFEST_PARSED, function () {
hls.loadLevel = hls.levels.length - 1; if (Hls.isSupported()) {
hls.startLoad(); var hls = new Hls({autoStartLoad: false});
video.play(); hls.loadSource(url);
}); hls.attachMedia(video);
} else if (video.canPlayType('application/vnd.apple.mpegurl')) { hls.on(Hls.Events.MANIFEST_PARSED, function () {
video.src = url; hls.loadLevel = hls.levels.length - 1;
video.addEventListener('canplay', function() { hls.startLoad();
video.play(); video.play();
});
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url;
video.addEventListener('canplay', function() {
video.play();
});
}
}); });
} }
} }
var observer = new MutationObserver(function () {
playVideo()
});
playVideo()
observer.observe(document.body, {childList: true, subtree: true});
// @license-end // @license-end

View file

@ -35,6 +35,7 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
# Config # Config
hmacKey: cfg.get("Config", "hmacKey", "secretkey"), hmacKey: cfg.get("Config", "hmacKey", "secretkey"),
nonceString: cfg.get("Config", "nonceString", "secretstring"),
base64Media: cfg.get("Config", "base64Media", false), base64Media: cfg.get("Config", "base64Media", false),
minTokens: cfg.get("Config", "tokenCount", 10), minTokens: cfg.get("Config", "tokenCount", 10),
enableRss: cfg.get("Config", "enableRSS", true), enableRss: cfg.get("Config", "enableRSS", true),

View file

@ -261,6 +261,7 @@ type
staticDir*: string staticDir*: string
hmacKey*: string hmacKey*: string
nonceString*: string
base64Media*: bool base64Media*: bool
minTokens*: int minTokens*: int
enableRss*: bool enableRss*: bool

View file

@ -73,11 +73,11 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
link(rel="alternate", type="application/rss+xml", href=rss, title="RSS feed") link(rel="alternate", type="application/rss+xml", href=rss, title="RSS feed")
if prefs.hlsPlayback: if prefs.hlsPlayback:
script(src="/js/hls.light.min.js", `defer`="") script(nonce=cfg.nonceString, src="/js/hls.light.min.js", `defer`="")
script(src="/js/hlsPlayback.js", `defer`="") script(nonce=cfg.nonceString, src="/js/hlsPlayback.js", `defer`="")
if prefs.infiniteScroll: if prefs.infiniteScroll:
script(src="/js/infiniteScroll.js", `defer`="") script(nonce=cfg.nonceString, src="/js/infiniteScroll.js", `defer`="")
title: title:
if titleText.len > 0: if titleText.len > 0:

View file

@ -109,7 +109,7 @@ proc renderVideo*(video: Video; prefs: Prefs; path: string): VNode =
source(src=source, `type`="video/mp4") source(src=source, `type`="video/mp4")
of m3u8, vmap: of m3u8, vmap:
video(poster=thumb, data-url=source, data-autoload="false", muted=prefs.muteVideos) video(poster=thumb, data-url=source, data-autoload="false", muted=prefs.muteVideos)
verbatim "<div class=\"video-overlay\" onclick=\"playVideo(this)\">" verbatim "<div class=\"video-overlay\">"
tdiv(class="overlay-circle"): span(class="overlay-triangle") tdiv(class="overlay-circle"): span(class="overlay-triangle")
verbatim "</div>" verbatim "</div>"
if container.len > 0: if container.len > 0: