Class: YoutubeVideoInfo::Response
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- YoutubeVideoInfo::Response
- Defined in:
- lib/youtube_video_info/response.rb
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
Returns the value of attribute raw_response.
Instance Method Summary collapse
- #author ⇒ Object
-
#initialize(http_response, cgi_module) ⇒ Response
constructor
A new instance of Response.
- #links ⇒ Object
- #links_by_itag ⇒ Object
- #title ⇒ Object
- #video_download_headers ⇒ Object
Constructor Details
#initialize(http_response, cgi_module) ⇒ Response
Returns a new instance of Response.
4 5 6 7 |
# File 'lib/youtube_video_info/response.rb', line 4 def initialize http_response, cgi_module @cgi_module = cgi_module super @cgi_module.parse(http_response) end |
Instance Attribute Details
#raw_response ⇒ Object
Returns the value of attribute raw_response.
3 4 5 |
# File 'lib/youtube_video_info/response.rb', line 3 def raw_response @raw_response end |
Instance Method Details
#author ⇒ Object
11 12 13 |
# File 'lib/youtube_video_info/response.rb', line 11 def self['author'].first end |
#links ⇒ Object
14 15 16 |
# File 'lib/youtube_video_info/response.rb', line 14 def links @cgi_module.parse(self['url_encoded_fmt_stream_map'].first)['url'] end |
#links_by_itag ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/youtube_video_info/response.rb', line 17 def links_by_itag parsed_links = {} list_of_links = links list_of_links.each do |link| parsed_link = @cgi_module.parse(link) itag = parsed_link['itag'].first parsed_links[itag] = link end parsed_links end |
#title ⇒ Object
8 9 10 |
# File 'lib/youtube_video_info/response.rb', line 8 def title self['title'].first end |
#video_download_headers ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/youtube_video_info/response.rb', line 27 def video_download_headers # This is just for convenience. # Many of these are here to make the request appear genuine. { "Connection" => "keep-alive", "Origin" => "https://www.youtube.com", "X-FirePHP-Version" => "0.0.6", "User-Agent" => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.95 Safari/537.36", "Accept" => "*/*", "DNT" => "1", "Referer" => "https://www.youtube.com/watch?v=#{video_id[0]}", "Accept-Encoding" => "gzip, deflate, sdch", "Accept-Language" => "en-US,en;q=0.8,de-DE;q=0.6,de;q=0.4" } end |