diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-07-20 16:39:31 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-07-20 16:39:31 -0500 |
| commit | 5c3494006f1bc06f165d977a0e17ad25cfd05eed (patch) | |
| tree | aef0faf478aee0539ceb8ade03a4830cb6a06478 | |
| parent | 56e35def8a6d0c37de5900a5ca79a418fa4ed70a (diff) | |
| download | invidious-5c3494006f1bc06f165d977a0e17ad25cfd05eed.tar.gz invidious-5c3494006f1bc06f165d977a0e17ad25cfd05eed.tar.bz2 invidious-5c3494006f1bc06f165d977a0e17ad25cfd05eed.zip | |
Optimize fetch_video
| -rw-r--r-- | src/invidious/helpers.cr | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/invidious/helpers.cr b/src/invidious/helpers.cr index c33af1b8..d579abae 100644 --- a/src/invidious/helpers.cr +++ b/src/invidious/helpers.cr @@ -221,20 +221,34 @@ def elapsed_text(elapsed) end def fetch_video(id, client) - info = client.get("/get_video_info?video_id=#{id}&el=detailpage&ps=default&eurl=&gl=US&hl=en&disable_polymer=1").body - html = client.get("/watch?v=#{id}&bpctr=#{Time.new.epoch + 2000}&disable_polymer=1").body + info_channel = Channel(HTTP::Params).new + html_channel = Channel(XML::Node).new - html = XML.parse_html(html) - info = HTTP::Params.parse(info) + spawn do + html = client.get("/watch?v=#{id}&bpctr=#{Time.new.epoch + 2000}&disable_polymer=1").body + html = XML.parse_html(html) + + html_channel.send(html) + end - if info["reason"]? - info = client.get("/get_video_info?video_id=#{id}&ps=default&eurl=&gl=US&hl=en&disable_polymer=1").body + spawn do + info = client.get("/get_video_info?video_id=#{id}&el=detailpage&ps=default&eurl=&gl=US&hl=en&disable_polymer=1").body info = HTTP::Params.parse(info) + if info["reason"]? - raise info["reason"] + info = client.get("/get_video_info?video_id=#{id}&ps=default&eurl=&gl=US&hl=en&disable_polymer=1").body + info = HTTP::Params.parse(info) + if info["reason"]? + raise info["reason"] + end end + + info_channel.send(info) end + html = html_channel.receive + info = info_channel.receive + title = info["title"] views = info["view_count"].to_i64 author = info["author"] |
