diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-03-03 19:10:25 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-03-03 19:10:25 -0600 |
| commit | 62dbd361deb00e89e206dee76b6744ac318e5832 (patch) | |
| tree | 2494341c1f54f8b3374c8af4c277e19e487999d3 /src | |
| parent | 1bf492ce78c93c7be2d33edbbd996f1e5e9e72e8 (diff) | |
| download | invidious-62dbd361deb00e89e206dee76b6744ac318e5832.tar.gz invidious-62dbd361deb00e89e206dee76b6744ac318e5832.tar.bz2 invidious-62dbd361deb00e89e206dee76b6744ac318e5832.zip | |
Add support for reddit redirect
Diffstat (limited to 'src')
| -rw-r--r-- | src/helpers.cr | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/helpers.cr b/src/helpers.cr index 3e41800d..e4674c3e 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -269,16 +269,26 @@ def make_client(url, context) end def get_reddit_comments(id, client) - youtube_url = URI.escape("https://youtube.com/watch?v=#{id}") - search_results = client.get("/submit.json?url=#{youtube_url}").body - search_results = RedditSubmit.from_json(search_results) + youtube_url = "https://www.youtube.com/watch?v=#{id}" + search_results = client.get("/submit.json?url=#{youtube_url}") - top_reddit_thread = search_results.data.children.sort_by { |child| child.data.score }[-1] + if search_results.status_code == 302 + search_results = client.get(search_results.headers["Location"]).body - comments = client.get("/r/#{top_reddit_thread.data.subreddit}/comments/#{top_reddit_thread.data.id}?sort=top&depth=3").body - comments = JSON.parse(comments) + result = JSON.parse(search_results) - return comments[1]["data"]["children"], top_reddit_thread + thread = RedditThread.from_json(result[0]["data"]["children"][0].to_json) + else + 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 = JSON.parse(result) + end + comments = result[1]["data"]["children"] + + return comments, thread end def template_comments(root) |
