diff --git a/src/parser.nim b/src/parser.nim index 5ec21e4..76d3da3 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -84,8 +84,8 @@ proc parseVideo(js: JsonNode): Video = views: js{"ext", "mediaStats", "r", "ok", "viewCount"}.getStr($js{"mediaStats", "viewCount"}.getInt), available: js{"ext_media_availability", "status"}.getStr.toLowerAscii == "available", title: js{"ext_alt_text"}.getStr, - durationMs: js{"video_info", "duration_millis"}.getInt - # playbackType: mp4 + durationMs: js{"video_info", "duration_millis"}.getInt, + playbackType: m3u8 ) with title, js{"additional_media_info", "title"}: @@ -99,6 +99,9 @@ proc parseVideo(js: JsonNode): Video = contentType = parseEnum[VideoType](v{"content_type"}.getStr("summary")) url = v{"url"}.getStr + if contentType == mp4: + result.playbackType = mp4 + result.variants.add VideoVariant( contentType: contentType, bitrate: v{"bitrate"}.getInt, diff --git a/src/routes/media.nim b/src/routes/media.nim index 95a83d5..02481a6 100644 --- a/src/routes/media.nim +++ b/src/routes/media.nim @@ -13,7 +13,7 @@ export httpclient, os, strutils, asyncstreams, base64, re const m3u8Mime* = "application/vnd.apple.mpegurl" mp4Mime* = "video/mp4" - maxAge* = "max-age=604800" + maxAge* = "public, max-age=604800, must-revalidate" proc safeFetch*(url: string): Future[string] {.async.} = let client = newAsyncHttpClient() @@ -61,9 +61,12 @@ proc proxyMedia*(req: jester.Request; url: string): Future[HttpCode] {.async.} = return Http404 var headers = @{ - "Accept-Ranges": "bytes", - "Content-Type": res.headers["content-type", 0], - "Cache-Control": maxAge + "accept-ranges": "bytes", + "content-type": $res.headers.getOrDefault("content-type"), + "cache-control": maxAge, + "age": $res.headers.getOrDefault("age"), + "date": $res.headers.getOrDefault("date"), + "last-modified": $res.headers.getOrDefault("last-modified") } var tries = 0 @@ -74,10 +77,10 @@ proc proxyMedia*(req: jester.Request; url: string): Future[HttpCode] {.async.} = let contentLength = res.getContentLength if contentLength.len > 0: - headers.add ("Content-Length", contentLength) + headers.add ("content-length", contentLength) if res.headers.hasKey("content-range"): - headers.add ("Content-Range", $res.headers.getOrDefault("content-range")) + headers.add ("content-range", $res.headers.getOrDefault("content-range")) respond(request, Http206, headers) else: respond(request, Http200, headers) diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 70bbe20..7032ce9 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -101,8 +101,7 @@ proc renderVideo*(video: Video; prefs: Prefs; path: string): VNode = else: vidUrl case playbackType of mp4: - video(poster=thumb, controls="", muted=prefs.muteVideos): - source(src=source, `type`="video/mp4") + video(src=source, poster=thumb, controls="", muted=prefs.muteVideos, preload="metadata") of m3u8, vmap: video(poster=thumb, data-url=source, data-autoload="false", muted=prefs.muteVideos) verbatim "
"