Class: YouTube::Video

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Video

Returns a new instance of Video.



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/youtube.rb', line 291

def initialize(payload)
  @author = payload['author'].to_s
  @comment_count = payload['comment_count'].to_i
  @description = payload['description'].to_s
  @id = payload['id']
  @length_seconds = payload['length_seconds'].to_i
  @rating_avg = payload['rating_avg'].to_f
  @rating_count = payload['rating_count'].to_i
  @tags = payload['tags']
  @thumbnail_url = payload['thumbnail_url']
  @title = payload['title'].to_s
  @upload_time = YouTube._string_to_time(payload['upload_time'])
  @url = payload['url']
  @view_count = payload['view_count'].to_i

  # the url provided via the API links to the video page -- for
  # convenience, generate the url used to embed in a page
  @embed_url = @url.delete('?').sub('=', '/')
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



276
277
278
# File 'lib/youtube.rb', line 276

def author
  @author
end

#comment_countObject (readonly)

Returns the value of attribute comment_count.



277
278
279
# File 'lib/youtube.rb', line 277

def comment_count
  @comment_count
end

#descriptionObject (readonly)

Returns the value of attribute description.



278
279
280
# File 'lib/youtube.rb', line 278

def description
  @description
end

#embed_urlObject (readonly)

Returns the value of attribute embed_url.



279
280
281
# File 'lib/youtube.rb', line 279

def embed_url
  @embed_url
end

#idObject (readonly)

Returns the value of attribute id.



280
281
282
# File 'lib/youtube.rb', line 280

def id
  @id
end

#length_secondsObject (readonly)

Returns the value of attribute length_seconds.



281
282
283
# File 'lib/youtube.rb', line 281

def length_seconds
  @length_seconds
end

#rating_avgObject (readonly)

Returns the value of attribute rating_avg.



282
283
284
# File 'lib/youtube.rb', line 282

def rating_avg
  @rating_avg
end

#rating_countObject (readonly)

Returns the value of attribute rating_count.



283
284
285
# File 'lib/youtube.rb', line 283

def rating_count
  @rating_count
end

#tagsObject (readonly)

Returns the value of attribute tags.



284
285
286
# File 'lib/youtube.rb', line 284

def tags
  @tags
end

#thumbnail_urlObject (readonly)

Returns the value of attribute thumbnail_url.



285
286
287
# File 'lib/youtube.rb', line 285

def thumbnail_url
  @thumbnail_url
end

#titleObject (readonly)

Returns the value of attribute title.



286
287
288
# File 'lib/youtube.rb', line 286

def title
  @title
end

#upload_timeObject (readonly)

Returns the value of attribute upload_time.



287
288
289
# File 'lib/youtube.rb', line 287

def upload_time
  @upload_time
end

#urlObject (readonly)

Returns the value of attribute url.



288
289
290
# File 'lib/youtube.rb', line 288

def url
  @url
end

#view_countObject (readonly)

Returns the value of attribute view_count.



289
290
291
# File 'lib/youtube.rb', line 289

def view_count
  @view_count
end

Instance Method Details

#embed_html(width = 425, height = 350) ⇒ Object

Returns HTML analogous to that provided by the YouTube web site to allow for easy embedding of this video in a web page. Optional width and height parameters allow specifying the dimensions of the video for display.



315
316
317
318
319
320
321
322
323
324
# File 'lib/youtube.rb', line 315

def embed_html(width = 425, height = 350)
  <<edoc
<object width="#{width}" height="#{height}">
  <param name="movie" value="#{embed_url}"></param>
  <param name="wmode" value="transparent"></param>
  <embed src="#{embed_url}" type="application/x-shockwave-flash" 
   wmode="transparent" width="#{width}" height="#{height}"></embed>
</object>
edoc
end