|
|
@ -268,18 +268,20 @@ def fetch_reddit_comments(id, sort_by = "confidence")
|
|
|
|
headers = HTTP::Headers{"User-Agent" => "web:invidious:v#{CURRENT_VERSION} (by github.com/iv-org/invidious)"}
|
|
|
|
headers = HTTP::Headers{"User-Agent" => "web:invidious:v#{CURRENT_VERSION} (by github.com/iv-org/invidious)"}
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: Use something like #479 for a static list of instances to use here
|
|
|
|
# TODO: Use something like #479 for a static list of instances to use here
|
|
|
|
query = "(url:3D#{id}%20OR%20url:#{id})%20(site:invidio.us%20OR%20site:youtube.com%20OR%20site:youtu.be)"
|
|
|
|
query = URI::Params.encode({q: "(url:3D#{id} OR url:#{id}) AND (site:invidio.us OR site:youtube.com OR site:youtu.be)"})
|
|
|
|
search_results = client.get("/search.json?q=#{query}", headers)
|
|
|
|
search_results = client.get("/search.json?#{query}", headers)
|
|
|
|
|
|
|
|
|
|
|
|
if search_results.status_code == 200
|
|
|
|
if search_results.status_code == 200
|
|
|
|
search_results = RedditThing.from_json(search_results.body)
|
|
|
|
search_results = RedditThing.from_json(search_results.body)
|
|
|
|
|
|
|
|
|
|
|
|
# For videos that have more than one thread, choose the one with the highest score
|
|
|
|
# For videos that have more than one thread, choose the one with the highest score
|
|
|
|
thread = search_results.data.as(RedditListing).children.sort_by { |child| child.data.as(RedditLink).score }[-1]
|
|
|
|
threads = search_results.data.as(RedditListing).children
|
|
|
|
thread = thread.data.as(RedditLink)
|
|
|
|
thread = threads.max_by? { |child| child.data.as(RedditLink).score }.try(&.data.as(RedditLink))
|
|
|
|
|
|
|
|
result = thread.try do |t|
|
|
|
|
result = client.get("/r/#{thread.subreddit}/comments/#{thread.id}.json?limit=100&sort=#{sort_by}", headers).body
|
|
|
|
body = client.get("/r/#{t.subreddit}/comments/#{t.id}.json?limit=100&sort=#{sort_by}", headers).body
|
|
|
|
result = Array(RedditThing).from_json(result)
|
|
|
|
Array(RedditThing).from_json(body)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
result ||= [] of RedditThing
|
|
|
|
elsif search_results.status_code == 302
|
|
|
|
elsif search_results.status_code == 302
|
|
|
|
# Previously, if there was only one result then the API would redirect to that result.
|
|
|
|
# Previously, if there was only one result then the API would redirect to that result.
|
|
|
|
# Now, it appears it will still return a listing so this section is likely unnecessary.
|
|
|
|
# Now, it appears it will still return a listing so this section is likely unnecessary.
|
|
|
@ -294,7 +296,8 @@ def fetch_reddit_comments(id, sort_by = "confidence")
|
|
|
|
|
|
|
|
|
|
|
|
client.close
|
|
|
|
client.close
|
|
|
|
|
|
|
|
|
|
|
|
comments = result[1].data.as(RedditListing).children
|
|
|
|
comments = result[1]?.try(&.data.as(RedditListing).children)
|
|
|
|
|
|
|
|
comments ||= [] of RedditThing
|
|
|
|
return comments, thread
|
|
|
|
return comments, thread
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|