Class: Getvideo::Youtube

Inherits:
Video
  • Object
show all
Defined in:
lib/getvideo/youtube.rb

Instance Attribute Summary

Attributes inherited from Video

#url

Instance Method Summary collapse

Methods inherited from Video

get_api_uri, #initialize, #json, #play_media, #response, set_api_uri

Constructor Details

This class inherits a constructor from Getvideo::Video

Instance Method Details

#coverObject



22
23
24
# File 'lib/getvideo/youtube.rb', line 22

def cover
  CGI::unescape(response.scan(/thumbnail_url=([^&]+)/)[0][0]).gsub("default.jpg","")+"0.jpg"
end

#flashObject



26
27
28
# File 'lib/getvideo/youtube.rb', line 26

def flash
  "http://www.youtube.com/v/#{id}"
end

#html_urlObject



6
7
8
9
10
11
12
# File 'lib/getvideo/youtube.rb', line 6

def html_url
  if url =~ /(?:v=|youtu\.be\/)/
    url
  else
    "http://www.youtube.com/watch?v=" + id
  end
end

#idObject



14
15
16
17
18
19
20
# File 'lib/getvideo/youtube.rb', line 14

def id
  if url =~ /(?:v=|youtu\.be\/|youtube\.com\/v\/)([^.|&]+)/
    url.scan(/(?:v=|youtu\.be\/|youtube\.com\/v\/)([^.|&]+)/)[0][0]
  else
    url
  end
end

#m3u8Object



30
31
32
# File 'lib/getvideo/youtube.rb', line 30

def m3u8
  media["mp4"][0]
end

#mediaObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/getvideo/youtube.rb', line 34

def media
  stream = CGI::unescape(response.scan(/url_encoded_fmt_stream_map=([^&]+)/)[0][0])
  media = stream.scan(/url=([^&]+)/)
  sig = stream.scan(/sig=([^&]+)/)
  type = stream.scan(/type=([^&]+)/)
  vedio_list = {}
  media.zip(sig, type).each do |m|
    m_type = m[2][0].match(/(flv|mp4|webm|3gp)/)[0]
    u = CGI::unescape(m[0][0])
    if m[1]
      u += "&signature=" + m[1][0]
    end
    if vedio_list[m_type].nil?
      vedio_list[m_type] = []
      vedio_list[m_type] << u
    else
      vedio_list[m_type] << u
    end
  end
  return vedio_list
end

#titleObject



56
57
58
# File 'lib/getvideo/youtube.rb', line 56

def title
  CGI::unescape response.scan(/title=([^&]+)/)[0][0]
end