Class: YouTube
Instance Method Summary collapse
- #embed_html(width = 425) ⇒ Object
-
#initialize(obj) ⇒ YouTube
constructor
A new instance of YouTube.
- #screen_ratio ⇒ Object
- #thumbnail_url ⇒ Object
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 (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_ratio ⇒ Object
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_url ⇒ Object
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 |