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.



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/youtube.rb', line 212

def initialize(payload)
  @author = payload['author']
  @comment_count = payload['comment_count'].to_i
  @description = payload['description']
  @id = payload['id']
  @length = payload['length']
  @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']
  @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.



197
198
199
# File 'lib/youtube.rb', line 197

def author
  @author
end

#comment_countObject (readonly)

Returns the value of attribute comment_count.



198
199
200
# File 'lib/youtube.rb', line 198

def comment_count
  @comment_count
end

#descriptionObject (readonly)

Returns the value of attribute description.



199
200
201
# File 'lib/youtube.rb', line 199

def description
  @description
end

#embed_urlObject (readonly)

Returns the value of attribute embed_url.



200
201
202
# File 'lib/youtube.rb', line 200

def embed_url
  @embed_url
end

#idObject (readonly)

Returns the value of attribute id.



201
202
203
# File 'lib/youtube.rb', line 201

def id
  @id
end

#lengthObject (readonly)

Returns the value of attribute length.



202
203
204
# File 'lib/youtube.rb', line 202

def length
  @length
end

#rating_avgObject (readonly)

Returns the value of attribute rating_avg.



203
204
205
# File 'lib/youtube.rb', line 203

def rating_avg
  @rating_avg
end

#rating_countObject (readonly)

Returns the value of attribute rating_count.



204
205
206
# File 'lib/youtube.rb', line 204

def rating_count
  @rating_count
end

#tagsObject (readonly)

Returns the value of attribute tags.



205
206
207
# File 'lib/youtube.rb', line 205

def tags
  @tags
end

#thumbnail_urlObject (readonly)

Returns the value of attribute thumbnail_url.



206
207
208
# File 'lib/youtube.rb', line 206

def thumbnail_url
  @thumbnail_url
end

#titleObject (readonly)

Returns the value of attribute title.



207
208
209
# File 'lib/youtube.rb', line 207

def title
  @title
end

#upload_timeObject (readonly)

Returns the value of attribute upload_time.



208
209
210
# File 'lib/youtube.rb', line 208

def upload_time
  @upload_time
end

#urlObject (readonly)

Returns the value of attribute url.



209
210
211
# File 'lib/youtube.rb', line 209

def url
  @url
end

#view_countObject (readonly)

Returns the value of attribute view_count.



210
211
212
# File 'lib/youtube.rb', line 210

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.



236
237
238
239
240
241
242
243
244
245
# File 'lib/youtube.rb', line 236

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