diff options
| author | saltycrys <73420320+saltycrys@users.noreply.github.com> | 2020-12-03 18:10:41 +0100 |
|---|---|---|
| committer | saltycrys <73420320+saltycrys@users.noreply.github.com> | 2020-12-03 18:10:41 +0100 |
| commit | 7823c07f1aea70828f0eb9244b961d90abb5d23f (patch) | |
| tree | d6da3651cf7e82c20368f8bb2128db6eaa4467dd | |
| parent | ff3b53e34ad8f6d7c09f427aa123e8e67c9a2733 (diff) | |
| download | invidious-7823c07f1aea70828f0eb9244b961d90abb5d23f.tar.gz invidious-7823c07f1aea70828f0eb9244b961d90abb5d23f.tar.bz2 invidious-7823c07f1aea70828f0eb9244b961d90abb5d23f.zip | |
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.
| -rw-r--r-- | src/invidious/videos.cr | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 8b20c181..edbff14e 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -816,7 +816,7 @@ end def extract_polymer_config(body) 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 } if body.includes?("To continue with your YouTube experience, please fill out the form below.") || @@ -914,10 +914,14 @@ def extract_polymer_config(body) .try { |r| JSON.parse(r["info"]) }.try &.["args"]["player_response"]? .try &.as_s?.try &.try { |r| JSON.parse(r).as_h } - return params if !initial_data - - {"playabilityStatus", "streamingData"}.each do |f| - params[f] = initial_data[f] if initial_data[f]? + if initial_data + {"playabilityStatus", "streamingData"}.each do |f| + params[f] = initial_data[f] if initial_data[f]? + end + else + {"playabilityStatus", "streamingData"}.each do |f| + params[f] = player_response[f] if player_response[f]? + end end params |
