Use POST requests for /videoplayback requests

This commit is contained in:
Fijxu 2024-10-29 19:02:05 -03:00
parent 02cab4bf31
commit 51c5a05b94
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4

View file

@ -3,6 +3,11 @@ module Invidious::Routes::VideoPlayback
def self.get_video_playback(env) def self.get_video_playback(env)
locale = env.get("preferences").as(Preferences).locale locale = env.get("preferences").as(Preferences).locale
query_params = env.params.query query_params = env.params.query
array = UInt8[0x78, 0]
protobuf = Bytes.new(array.size)
array.each_with_index do |byte, index|
protobuf[index] = byte
end
fvip = query_params["fvip"]? || "3" fvip = query_params["fvip"]? || "3"
mns = query_params["mn"]?.try &.split(",") mns = query_params["mn"]?.try &.split(",")
@ -100,7 +105,7 @@ module Invidious::Routes::VideoPlayback
end end
begin begin
client.get(url, headers) do |resp| client.post(url, headers, protobuf) do |resp|
resp.headers.each do |key, value| resp.headers.each do |key, value|
if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase)
env.response.headers[key] = value env.response.headers[key] = value
@ -151,7 +156,7 @@ module Invidious::Routes::VideoPlayback
headers["Range"] = "bytes=#{chunk_start}-#{chunk_end}" headers["Range"] = "bytes=#{chunk_start}-#{chunk_end}"
begin begin
client.get(url, headers) do |resp| client.post(url, headers, protobuf) do |resp|
if first_chunk if first_chunk
if !env.request.headers["Range"]? && resp.status_code == 206 if !env.request.headers["Range"]? && resp.status_code == 206
env.response.status_code = 200 env.response.status_code = 200