mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-07 13:18:30 +00:00
Use extract_initial_data helper everywhere
This commit is contained in:
parent
a4f923839a
commit
9ea20cca32
@ -775,8 +775,6 @@ def extract_channel_community_cursor(continuation)
|
|||||||
cursor
|
cursor
|
||||||
end
|
end
|
||||||
|
|
||||||
INITDATA_PREQUERY = "window[\"ytInitialData\"] = {"
|
|
||||||
|
|
||||||
def get_about_info(ucid, locale)
|
def get_about_info(ucid, locale)
|
||||||
about = YT_POOL.client &.get("/channel/#{ucid}/about?gl=US&hl=en")
|
about = YT_POOL.client &.get("/channel/#{ucid}/about?gl=US&hl=en")
|
||||||
if about.status_code != 200
|
if about.status_code != 200
|
||||||
@ -792,18 +790,14 @@ def get_about_info(ucid, locale)
|
|||||||
raise error_message
|
raise error_message
|
||||||
end
|
end
|
||||||
|
|
||||||
initdata_pre = about.body.index(INITDATA_PREQUERY)
|
initdata = extract_initial_data(about.body)
|
||||||
initdata_post = initdata_pre.nil? ? nil : about.body.index("};", initdata_pre)
|
about = XML.parse_html(about.body)
|
||||||
if initdata_post.nil?
|
|
||||||
about = XML.parse_html(about.body)
|
if initdata.empty?
|
||||||
error_message = about.xpath_node(%q(//div[@class="yt-alert-content"])).try &.content.strip
|
error_message = about.xpath_node(%q(//div[@class="yt-alert-content"])).try &.content.strip
|
||||||
error_message ||= translate(locale, "Could not get channel info.")
|
error_message ||= translate(locale, "Could not get channel info.")
|
||||||
raise error_message
|
raise error_message
|
||||||
end
|
end
|
||||||
initdata_pre = initdata_pre.not_nil! + INITDATA_PREQUERY.size - 1
|
|
||||||
|
|
||||||
initdata = JSON.parse(about.body[initdata_pre, initdata_post - initdata_pre + 1])
|
|
||||||
about = XML.parse_html(about.body)
|
|
||||||
|
|
||||||
if about.xpath_node(%q(//div[contains(@class, "channel-empty-message")]))
|
if about.xpath_node(%q(//div[contains(@class, "channel-empty-message")]))
|
||||||
error_message = translate(locale, "This channel does not exist.")
|
error_message = translate(locale, "This channel does not exist.")
|
||||||
|
@ -839,8 +839,7 @@ def extract_polymer_config(body)
|
|||||||
params[f] = player_response[f] if player_response[f]?
|
params[f] = player_response[f] if player_response[f]?
|
||||||
end
|
end
|
||||||
|
|
||||||
yt_initial_data = body.match(/(window\["ytInitialData"\]|var\s+ytInitialData)\s*=\s*(?<info>.*?);\s*\n/)
|
yt_initial_data = extract_initial_data(body)
|
||||||
.try { |r| JSON.parse(r["info"]).as_h }
|
|
||||||
|
|
||||||
params["relatedVideos"] = yt_initial_data.try &.["playerOverlays"]?.try &.["playerOverlayRenderer"]?
|
params["relatedVideos"] = yt_initial_data.try &.["playerOverlays"]?.try &.["playerOverlayRenderer"]?
|
||||||
.try &.["endScreen"]?.try &.["watchNextEndScreenRenderer"]?.try &.["results"]?.try &.as_a.compact_map { |r|
|
.try &.["endScreen"]?.try &.["watchNextEndScreenRenderer"]?.try &.["results"]?.try &.as_a.compact_map { |r|
|
||||||
|
Loading…
Reference in New Issue
Block a user