Optimize fetch_video

This commit is contained in:
Omar Roth 2018-07-20 16:39:31 -05:00
parent 56e35def8a
commit 5c3494006f
1 changed files with 24 additions and 10 deletions

View File

@ -221,10 +221,18 @@ 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
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
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"]?
@ -235,6 +243,12 @@ def fetch_video(id, client)
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"]