mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-09 20:24:03 +00:00
Major fixes, add options for YT, add User-Agent for Reddit
This commit is contained in:
@@ -243,31 +243,31 @@ end
|
||||
|
||||
def make_client(url, context)
|
||||
client = HTTP::Client.new(url, context)
|
||||
client.read_timeout = 30.seconds
|
||||
client.connect_timeout = 30.seconds
|
||||
client.read_timeout = 10.seconds
|
||||
client.connect_timeout = 10.seconds
|
||||
return client
|
||||
end
|
||||
|
||||
def get_reddit_comments(id, client)
|
||||
def get_reddit_comments(id, client, headers)
|
||||
query = "(url:3D#{id}%20OR%20url:#{id})%20(site:youtube.com%20OR%20site:youtu.be)"
|
||||
search_results = client.get("/search.json?q=#{query}")
|
||||
search_results = client.get("/search.json?q=#{query}", headers)
|
||||
|
||||
if search_results.status_code == 302
|
||||
search_results = client.get(search_results.headers["Location"]).body
|
||||
|
||||
result = JSON.parse(search_results)
|
||||
|
||||
thread = RedditThread.from_json(result[0]["data"]["children"][0].to_json)
|
||||
else
|
||||
if search_results.status_code == 200
|
||||
search_results = RedditSubmit.from_json(search_results.body)
|
||||
|
||||
thread = search_results.data.children.sort_by { |child| child.data.score }[-1]
|
||||
|
||||
result = client.get("/r/#{thread.data.subreddit}/comments/#{thread.data.id}?sort=top&depth=3").body
|
||||
result = client.get("/r/#{thread.data.subreddit}/comments/#{thread.data.id}?sort=top&depth=3", headers).body
|
||||
result = JSON.parse(result)
|
||||
end
|
||||
comments = result[1]["data"]["children"]
|
||||
elsif search_results.status_code == 302
|
||||
search_results = client.get(search_results.headers["Location"], headers).body
|
||||
|
||||
result = JSON.parse(search_results)
|
||||
thread = RedditThread.from_json(result[0]["data"]["children"][0].to_json)
|
||||
else
|
||||
raise "Got error code #{search_results.status_code}"
|
||||
end
|
||||
|
||||
comments = result[1]["data"]["children"]
|
||||
return comments, thread
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user