Fix `extract_polymer_config`

The `ytInitialPlayerResponse` regex can now handle `var` and `window`
assignments.

The video streams can now be extracted from `player_response` and
`initial_data`.

This fixes the descriptions on videos and videos themselves. Videos are
technically broken right now, but work becasue of a fallback that goes through
embeds.
pull/1525/head
saltycrys 2020-12-03 18:10:41 +01:00
rodzic ff3b53e34a
commit 7823c07f1a
1 zmienionych plików z 9 dodań i 5 usunięć

Wyświetl plik

@ -816,7 +816,7 @@ end
def extract_polymer_config(body) def extract_polymer_config(body)
params = {} of String => JSON::Any params = {} of String => JSON::Any
player_response = body.match(/window\["ytInitialPlayerResponse"\]\s*=\s*(?<info>.*?);\n/) player_response = body.match(/(window\["ytInitialPlayerResponse"\]|var\sytInitialPlayerResponse)\s*=\s*(?<info>{.*?});/m)
.try { |r| JSON.parse(r["info"]).as_h } .try { |r| JSON.parse(r["info"]).as_h }
if body.includes?("To continue with your YouTube experience, please fill out the form below.") || if body.includes?("To continue with your YouTube experience, please fill out the form below.") ||
@ -914,11 +914,15 @@ def extract_polymer_config(body)
.try { |r| JSON.parse(r["info"]) }.try &.["args"]["player_response"]? .try { |r| JSON.parse(r["info"]) }.try &.["args"]["player_response"]?
.try &.as_s?.try &.try { |r| JSON.parse(r).as_h } .try &.as_s?.try &.try { |r| JSON.parse(r).as_h }
return params if !initial_data if initial_data
{"playabilityStatus", "streamingData"}.each do |f| {"playabilityStatus", "streamingData"}.each do |f|
params[f] = initial_data[f] if initial_data[f]? params[f] = initial_data[f] if initial_data[f]?
end end
else
{"playabilityStatus", "streamingData"}.each do |f|
params[f] = player_response[f] if player_response[f]?
end
end
params params
end end