Invidious is an alternative front-end to YouTube
Videos: Send player sts when required
Samantaz Fox10e5788c2125
diff --git a/src/invidious/helpers/signatures.cr b/src/invidious/helpers/signatures.crindex d9aab31c..b58af73f 100644--- a/src/invidious/helpers/signatures.cr+++ b/src/invidious/helpers/signatures.cr@@ -34,4 +34,13 @@ struct Invidious::DecryptFunctionLOGGER.trace(ex.inspect_with_backtrace)return nilend++ def get_sts : UInt64?+ self.check_update+ return SigHelper::Client.get_sts+ rescue ex+ LOGGER.debug(ex.message || "Signature: Unknown error")+ LOGGER.trace(ex.inspect_with_backtrace)+ return nil+ endenddiff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.crindex c8b037c8..f4ee35e5 100644--- a/src/invidious/yt_backend/youtube_api.cr+++ b/src/invidious/yt_backend/youtube_api.cr@@ -2,6 +2,8 @@# This file contains youtube API wrappers#+private STS_FETCHER = IV::DecryptFunction.new+module YoutubeAPIextend self@@ -272,7 +274,7 @@ module YoutubeAPI# Return, as a Hash, the "context" data required to request the# youtube API endpoints.#- private def make_context(client_config : ClientConfig | Nil) : Hash+ private def make_context(client_config : ClientConfig | Nil, video_id = "dQw4w9WgXcQ") : Hash# Use the default client config if nil is passedclient_config ||= DEFAULT_CLIENT_CONFIG@@ -292,7 +294,7 @@ module YoutubeAPIif client_config.screen == "EMBED"client_context["thirdParty"] = {- "embedUrl" => "https://www.youtube.com/embed/dQw4w9WgXcQ",+ "embedUrl" => "https://www.youtube.com/embed/#{video_id}",} of String => String | Int64end@@ -453,19 +455,29 @@ module YoutubeAPIparams : String,client_config : ClientConfig | Nil = nil)+ # Playback context, separate because it can be different between clients+ playback_ctx = {+ "html5Preference" => "HTML5_PREF_WANTS",+ "referer" => "https://www.youtube.com/watch?v=#{video_id}",+ } of String => String | Int64++ if {"WEB", "TVHTML5"}.any? { |s| client_config.name.starts_with? s }+ if sts = STS_FETCHER.get_sts+ playback_ctx["signatureTimestamp"] = sts.to_i64+ end+ end+# JSON Request data, required by the APIdata = {"contentCheckOk" => true,"videoId" => video_id,- "context" => self.make_context(client_config),+ "context" => self.make_context(client_config, video_id),"racyCheckOk" => true,"user" => {"lockedSafetyMode" => false,},"playbackContext" => {- "contentPlaybackContext" => {- "html5Preference": "HTML5_PREF_WANTS",- },+ "contentPlaybackContext" => playback_ctx,},}