mirror of
https://gitea.invidious.io/iv-org/invidious.git
synced 2024-08-15 00:53:41 +00:00
Videos: Send player sts when required
This commit is contained in:
parent
b509aa91d5
commit
10e5788c21
2 changed files with 27 additions and 6 deletions
|
@ -34,4 +34,13 @@ struct Invidious::DecryptFunction
|
|||
LOGGER.trace(ex.inspect_with_backtrace)
|
||||
return nil
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
# This file contains youtube API wrappers
|
||||
#
|
||||
|
||||
private STS_FETCHER = IV::DecryptFunction.new
|
||||
|
||||
module YoutubeAPI
|
||||
extend 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 passed
|
||||
client_config ||= DEFAULT_CLIENT_CONFIG
|
||||
|
||||
|
@ -292,7 +294,7 @@ module YoutubeAPI
|
|||
|
||||
if 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 | Int64
|
||||
end
|
||||
|
||||
|
@ -453,19 +455,29 @@ module YoutubeAPI
|
|||
params : 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 API
|
||||
data = {
|
||||
"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,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue