From e8c9641548f26ae4e2097711df9ee1a0eef0ada9 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 10 Nov 2018 10:50:09 -0600 Subject: [PATCH] Update info extractor --- src/invidious/comments.cr | 8 ++++---- src/invidious/mixes.cr | 2 +- src/invidious/playlists.cr | 2 +- src/invidious/videos.cr | 18 +++++++++++++++--- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index ba5d6f08b..f4398b58c 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -58,7 +58,7 @@ end def fetch_youtube_comments(id, continuation, proxies, format) client = make_client(YT_URL) - html = client.get("/watch?v=#{id}&bpctr=#{Time.new.to_unix + 2000}&gl=US&hl=en&disable_polymer=1") + html = client.get("/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999") headers = HTTP::Headers.new headers["cookie"] = html.cookies.add_request_headers(headers)["cookie"] body = html.body @@ -83,7 +83,7 @@ def fetch_youtube_comments(id, continuation, proxies, format) proxy = HTTPProxy.new(proxy_host: proxy[:ip], proxy_port: proxy[:port]) proxy_client.set_proxy(proxy) - response = proxy_client.get("/watch?v=#{id}&bpctr=#{Time.new.to_unix + 2000}&gl=US&hl=en&disable_polymer=1") + response = proxy_client.get("/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999") proxy_headers = HTTP::Headers.new proxy_headers["cookie"] = response.cookies.add_request_headers(headers)["cookie"] proxy_html = response.body @@ -140,8 +140,8 @@ def fetch_youtube_comments(id, continuation, proxies, format) headers["content-type"] = "application/x-www-form-urlencoded" headers["x-client-data"] = "CIi2yQEIpbbJAQipncoBCNedygEIqKPKAQ==" - headers["x-spf-previous"] = "https://www.youtube.com/watch?v=#{id}&bpctr=#{Time.new.to_unix + 2000}&gl=US&hl=en&disable_polymer=1" - headers["x-spf-referer"] = "https://www.youtube.com/watch?v=#{id}&bpctr=#{Time.new.to_unix + 2000}&gl=US&hl=en&disable_polymer=1" + headers["x-spf-previous"] = "https://www.youtube.com/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999" + headers["x-spf-referer"] = "https://www.youtube.com/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999" headers["x-youtube-client-name"] = "1" headers["x-youtube-client-version"] = "2.20180719" diff --git a/src/invidious/mixes.cr b/src/invidious/mixes.cr index 66f7371d1..688a86224 100644 --- a/src/invidious/mixes.cr +++ b/src/invidious/mixes.cr @@ -26,7 +26,7 @@ def fetch_mix(rdid, video_id, cookies = nil) if cookies headers = cookies.add_request_headers(headers) end - response = client.get("/watch?v=#{video_id}&list=#{rdid}&bpctr=#{Time.new.to_unix + 2000}&gl=US&hl=en", headers) + response = client.get("/watch?v=#{video_id}&list=#{rdid}&gl=US&hl=en&has_verified=1&bpctr=9999999999", headers) yt_data = response.body.match(/window\["ytInitialData"\] = (?.*);/) if yt_data diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index cc149ea85..c1adb1d97 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -30,7 +30,7 @@ def fetch_playlist_videos(plid, page, video_count, continuation = nil) client = make_client(YT_URL) if continuation - html = client.get("/watch?v=#{continuation}&list=#{plid}&bpctr=#{Time.new.to_unix + 2000}&gl=US&hl=en&disable_polymer=1") + html = client.get("/watch?v=#{continuation}&list=#{plid}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999") html = XML.parse_html(html.body) index = html.xpath_node(%q(//span[@id="playlist-current-index"])).try &.content.to_i? diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index eaf2e17a8..a0fb7f227 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -546,7 +546,7 @@ def fetch_video(id, proxies) spawn do client = make_client(YT_URL) - html = client.get("/watch?v=#{id}&bpctr=#{Time.new.to_unix + 2000}&gl=US&hl=en&disable_polymer=1") + html = client.get("/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999") if md = html.headers["location"]?.try &.match(/v=(?[a-zA-Z0-9_-]{11})/) next html_channel.send(md["id"]) @@ -620,7 +620,7 @@ def fetch_video(id, proxies) client.connect_timeout = 10.seconds client.set_proxy(proxy) - html = XML.parse_html(client.get("/watch?v=#{id}&bpctr=#{Time.new.to_unix + 2000}&gl=US&hl=en&disable_polymer=1").body) + html = XML.parse_html(client.get("/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999").body) info = HTTP::Params.parse(client.get("/get_video_info?video_id=#{id}&el=detailpage&ps=default&eurl=&gl=US&hl=en&disable_polymer=1").body) if info["reason"]? @@ -641,7 +641,19 @@ def fetch_video(id, proxies) end if info["reason"]? - raise info["reason"] + html_info = html.to_s.match(/ytplayer\.config = (?.*?);ytplayer\.load/).try &.["info"] + if html_info + html_info = JSON.parse(html_info)["args"].as_h + info.delete("reason") + + html_info.each do |k, v| + info[k] = v.to_s + end + end + + if info["reason"]? + raise info["reason"] + end end title = info["title"]