Class: YoutubeVideoInfo::Response

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/youtube_video_info/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_responseObject

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

#authorObject



11
12
13
# File 'lib/youtube_video_info/response.rb', line 11

def author
  self['author'].first
end


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


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

#titleObject



8
9
10
# File 'lib/youtube_video_info/response.rb', line 8

def title
  self['title'].first
end

#video_download_headersObject



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