Class: YouTubeG::Model::Video

Inherits:
Record
  • Object
show all
Defined in:
lib/youtube_g/model/video.rb

Defined Under Namespace

Classes: Format

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Record

#initialize

Constructor Details

This class inherits a constructor from YouTubeG::Record

Instance Attribute Details

#authorObject (readonly)

YouTubeG::Model::Author

Information about the YouTube user who owns a piece of video content.



95
96
97
# File 'lib/youtube_g/model/video.rb', line 95

def author
  @author
end

#categoriesObject (readonly)

Array

A array of YouTubeG::Model::Category objects that describe the videos categories.



80
81
82
# File 'lib/youtube_g/model/video.rb', line 80

def categories
  @categories
end

#descriptionObject (readonly)

String

Description of the video.



86
87
88
# File 'lib/youtube_g/model/video.rb', line 86

def description
  @description
end

#durationObject (readonly)

Fixnum

Duration of a video in seconds.



59
60
61
# File 'lib/youtube_g/model/video.rb', line 59

def duration
  @duration
end

#favorite_countObject (readonly)

Fixnum

Number of times that the video has been favorited



113
114
115
# File 'lib/youtube_g/model/video.rb', line 113

def favorite_count
  @favorite_count
end

#html_contentObject (readonly)

String

Description of the video.



92
93
94
# File 'lib/youtube_g/model/video.rb', line 92

def html_content
  @html_content
end

#keywordsObject (readonly)

Array

An array of words associated with the video.



83
84
85
# File 'lib/youtube_g/model/video.rb', line 83

def keywords
  @keywords
end

#latitudeObject (readonly)

Returns the value of attribute latitude.



119
120
121
# File 'lib/youtube_g/model/video.rb', line 119

def latitude
  @latitude
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



120
121
122
# File 'lib/youtube_g/model/video.rb', line 120

def longitude
  @longitude
end

#media_contentObject (readonly)

Array

An array of YouTubeG::Model::Content objects describing the individual media content data available for this video. Most, but not all, videos offer this.



98
99
100
# File 'lib/youtube_g/model/video.rb', line 98

def media_content
  @media_content
end

#noembedObject (readonly)

Boolean

Specifies that a video may or may not be embedded on other websites.



62
63
64
# File 'lib/youtube_g/model/video.rb', line 62

def noembed
  @noembed
end

#player_urlObject (readonly)

String

The link to watch the URL on YouTubes website.



104
105
106
# File 'lib/youtube_g/model/video.rb', line 104

def player_url
  @player_url
end

#positionObject (readonly)

Fixnum

Specifies the order in which the video appears in a playlist.



65
66
67
# File 'lib/youtube_g/model/video.rb', line 65

def position
  @position
end

#published_atObject (readonly)

Time

When the video was published on Youtube.



74
75
76
# File 'lib/youtube_g/model/video.rb', line 74

def published_at
  @published_at
end

#racyObject (readonly)

Boolean

Specifies that a video is flagged as adult or not.



68
69
70
# File 'lib/youtube_g/model/video.rb', line 68

def racy
  @racy
end

#ratingObject (readonly)

YouTubeG::Model::Rating

Information about the videos rating.



107
108
109
# File 'lib/youtube_g/model/video.rb', line 107

def rating
  @rating
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



122
123
124
# File 'lib/youtube_g/model/video.rb', line 122

def statistics
  @statistics
end

#thumbnailsObject (readonly)

Array

An array of YouTubeG::Model::Thumbnail objects that contain information regarding the videos thumbnail images.



101
102
103
# File 'lib/youtube_g/model/video.rb', line 101

def thumbnails
  @thumbnails
end

#titleObject (readonly)

String

Title for the video.



89
90
91
# File 'lib/youtube_g/model/video.rb', line 89

def title
  @title
end

#updated_atObject (readonly)

Time

When the video’s data was last updated.



77
78
79
# File 'lib/youtube_g/model/video.rb', line 77

def updated_at
  @updated_at
end

#video_idObject (readonly)

String: Specifies a URI that uniquely and permanently identifies the video.



71
72
73
# File 'lib/youtube_g/model/video.rb', line 71

def video_id
  @video_id
end

#view_countObject (readonly)

Fixnum

Number of times that the video has been viewed



110
111
112
# File 'lib/youtube_g/model/video.rb', line 110

def view_count
  @view_count
end

#whereObject (readonly)

Geodata



117
118
119
# File 'lib/youtube_g/model/video.rb', line 117

def where
  @where
end

Instance Method Details

#comments_search(options = {}) ⇒ Object

Comments on the current video.

Returns

YouTubeG::Response::CommentsSearch


144
145
146
147
# File 'lib/youtube_g/model/video.rb', line 144

def comments_search(options={})
  url = YouTubeG::Request::CommentsSearch.new(unique_id,options).url
  YouTubeG::Parser::CommentsFeedParser.new(url).parse
end

#default_media_contentObject

Provides a URL and various other types of information about a video.

Returns

YouTubeG::Model::Content: Data about the embeddable video.


175
176
177
# File 'lib/youtube_g/model/video.rb', line 175

def default_media_content
  @media_content.find { |c| c.is_default? }
end

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

Gives you the HTML to embed the video on your website.

Returns

String: The HTML for embedding the video on your website.


183
184
185
186
187
188
189
190
191
192
# File 'lib/youtube_g/model/video.rb', line 183

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

#embed_urlObject

The URL needed for embedding the video in a page.

Returns

String: Absolute URL for embedding video


198
199
200
# File 'lib/youtube_g/model/video.rb', line 198

def embed_url
  @player_url.sub('watch?', '').sub('=', '/')          
end

#embeddable?Boolean

Allows you to check whether the video can be embedded on a webpage.

Returns

Boolean: True if the video can be embedded, false if not.

Returns:

  • (Boolean)


167
168
169
# File 'lib/youtube_g/model/video.rb', line 167

def embeddable?
  not @noembed
end

Videos related to the current video.

Returns

YouTubeG::Response::VideoSearch


128
129
130
# File 'lib/youtube_g/model/video.rb', line 128

def related
  YouTubeG::Parser::VideosFeedParser.new("http://gdata.youtube.com/feeds/api/videos/#{unique_id}/related").parse
end

#responsesObject

Video responses to the current video.

Returns

YouTubeG::Response::VideoSearch


136
137
138
# File 'lib/youtube_g/model/video.rb', line 136

def responses
  YouTubeG::Parser::VideosFeedParser.new("http://gdata.youtube.com/feeds/api/videos/#{unique_id}/responses").parse
end

#unique_idObject

The ID of the video, useful for searching for the video again without having to store it anywhere. A regular query search, with this id will return the same video.

Example

>> video.unique_id
=> "ZTUVgYoeN_o"

Returns

String: The Youtube video id.


159
160
161
# File 'lib/youtube_g/model/video.rb', line 159

def unique_id
  video_id[/videos\/([^<]+)/, 1]
end