Class: YouTube

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/you_tube.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ YouTube

Returns a new instance of YouTube.



7
8
9
10
11
# File 'lib/you_tube.rb', line 7

def initialize(obj)
  @clip_id   = obj.video_url.split('?v=').last.split('&').first
  @embed_url = "http://www.youtube.com/v/#{@clip_id}&hl=en&fs=1"
  @response  = self.class.get("/feeds/api/videos/#{@clip_id}")
end

Instance Method Details

#embed_html(width = 425) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/you_tube.rb', line 24

def embed_html(width = 425)
  width = 425 if width.to_i < 1
  height = (width.to_f * screen_ratio).to_i
  <<-END
    <object width="#{width}" height="#{height}" style="z-index: 0; position: relative;">
      <param name="movie" value="#{@embed_url}" />
      <param name="allowFullScreen" value="true" />
      <param name="wmode" value="transparent" />
      <param name="bgcolor" value="#FFFFFF" />
      <embed src="#{@embed_url}" type="application/x-shockwave-flash" bgcolor="#FFFFFF" allowfullscreen="true" wmode="transparent" width="#{width}" height="#{height}" />
    </object>
  END
end

#screen_ratioObject



13
14
15
16
17
# File 'lib/you_tube.rb', line 13

def screen_ratio
  height = @response["entry"]["media:group"]["media:thumbnail"][0]["height"].to_f
  width = @response["entry"]["media:group"]["media:thumbnail"][0]["width"].to_f
  height / width
end

#thumbnail_urlObject



19
20
21
22
# File 'lib/you_tube.rb', line 19

def thumbnail_url
  #@response["entry"]["media:group"]["media:thumbnail"][0]["url"]
  "http://img.youtube.com/vi/#{@clip_id}/0.jpg"
end