forked from midou/invidious
Fix comments
The YouTube headers are now always added for requests to YouTube. Previously they were only added for requests going through QUIC. The session token is now JSON decoded to unescape escaped Unicode characters. The comment continuation protobuf has been updated and the request now goes through the YouTube `pbj` JSON API.
This commit is contained in:
parent
527f408f6a
commit
2de206cb81
@ -88,7 +88,7 @@ def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, so
|
|||||||
"cookie" => video.cookie,
|
"cookie" => video.cookie,
|
||||||
}
|
}
|
||||||
|
|
||||||
response = YT_POOL.client(region, &.post("/comment_service_ajax?action_get_comments=1&hl=en&gl=US", headers, form: post_req))
|
response = YT_POOL.client(region, &.post("/comment_service_ajax?action_get_comments=1&hl=en&gl=US&pbj=1", headers, form: post_req))
|
||||||
response = JSON.parse(response.body)
|
response = JSON.parse(response.body)
|
||||||
|
|
||||||
if !response["response"]["continuationContents"]?
|
if !response["response"]["continuationContents"]?
|
||||||
@ -581,13 +581,17 @@ def produce_comment_continuation(video_id, cursor = "", sort_by = "top")
|
|||||||
object = {
|
object = {
|
||||||
"2:embedded" => {
|
"2:embedded" => {
|
||||||
"2:string" => video_id,
|
"2:string" => video_id,
|
||||||
"24:varint" => 1_i64,
|
"25:varint" => 0_i64,
|
||||||
"25:varint" => 1_i64,
|
|
||||||
"28:varint" => 1_i64,
|
"28:varint" => 1_i64,
|
||||||
"36:embedded" => {
|
"36:embedded" => {
|
||||||
"5:varint" => -1_i64,
|
"5:varint" => -1_i64,
|
||||||
"8:varint" => 0_i64,
|
"8:varint" => 0_i64,
|
||||||
},
|
},
|
||||||
|
"40:embedded" => {
|
||||||
|
"1:varint" => 4_i64,
|
||||||
|
"3:string" => "https://www.youtube.com",
|
||||||
|
"4:string" => "",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"3:varint" => 6_i64,
|
"3:varint" => 6_i64,
|
||||||
"6:embedded" => {
|
"6:embedded" => {
|
||||||
|
@ -83,6 +83,7 @@ def make_client(url : URI, region = nil)
|
|||||||
# TODO: Migrate any applicable endpoints to QUIC
|
# TODO: Migrate any applicable endpoints to QUIC
|
||||||
client = HTTPClient.new(url, OpenSSL::SSL::Context::Client.insecure)
|
client = HTTPClient.new(url, OpenSSL::SSL::Context::Client.insecure)
|
||||||
client.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::UNSPEC
|
client.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::UNSPEC
|
||||||
|
client.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com"
|
||||||
client.read_timeout = 10.seconds
|
client.read_timeout = 10.seconds
|
||||||
client.connect_timeout = 10.seconds
|
client.connect_timeout = 10.seconds
|
||||||
|
|
||||||
|
@ -830,7 +830,8 @@ def extract_polymer_config(body)
|
|||||||
params["reason"] = JSON::Any.new(reason)
|
params["reason"] = JSON::Any.new(reason)
|
||||||
end
|
end
|
||||||
|
|
||||||
params["sessionToken"] = JSON::Any.new(body.match(/"XSRF_TOKEN":"(?<session_token>[^"]+)"/).try &.["session_token"]?)
|
session_token_json_encoded = body.match(/"XSRF_TOKEN":"(?<session_token>[^"]+)"/).try &.["session_token"]? || ""
|
||||||
|
params["sessionToken"] = JSON.parse(%({"key": "#{session_token_json_encoded}"}))["key"]
|
||||||
params["shortDescription"] = JSON::Any.new(body.match(/"og:description" content="(?<description>[^"]+)"/).try &.["description"]?)
|
params["shortDescription"] = JSON::Any.new(body.match(/"og:description" content="(?<description>[^"]+)"/).try &.["description"]?)
|
||||||
|
|
||||||
return params if !player_response
|
return params if !player_response
|
||||||
|
Loading…
Reference in New Issue
Block a user