Class: YouTubeG::Model::Video

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

Defined Under Namespace

Classes: AppControl, 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

#app_controlObject (readonly)

YouTubeG::Model::Video::AppControl The state of this video if post upload



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

def app_control
  @app_control
end

#authorObject (readonly)

YouTubeG::Model::Author

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



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

def author
  @author
end

#categoriesObject (readonly)

Array

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



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

def categories
  @categories
end

#descriptionObject (readonly)

String

Description of the video.



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

def description
  @description
end

#durationObject (readonly)

Fixnum

Duration of a video in seconds.



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

def duration
  @duration
end

#html_contentObject (readonly)

String

Description of the video.



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

def html_content
  @html_content
end

#keywordsObject (readonly)

Array

An array of words associated with the video.



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

def keywords
  @keywords
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.



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

def media_content
  @media_content
end

#noembedObject (readonly)

Boolean

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



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

def noembed
  @noembed
end

#player_urlObject (readonly)

String

The link to watch the URL on YouTubes website.



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

def player_url
  @player_url
end

#positionObject (readonly)

Fixnum

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



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

def position
  @position
end

#published_atObject (readonly)

Time

When the video was published on Youtube.



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

def published_at
  @published_at
end

#racyObject (readonly)

Boolean

Specifies that a video is flagged as adult or not.



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

def racy
  @racy
end

#ratingObject (readonly)

YouTubeG::Model::Rating

Information about the videos rating.



126
127
128
# File 'lib/youtube_g/model/video.rb', line 126

def rating
  @rating
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



131
132
133
# File 'lib/youtube_g/model/video.rb', line 131

def statistics
  @statistics
end

#status_urlObject (readonly)

String

The URL to check the processing status of the video at YT.



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

def status_url
  @status_url
end

#thumbnailsObject (readonly)

Array

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



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

def thumbnails
  @thumbnails
end

#titleObject (readonly)

String

Title for the video.



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

def title
  @title
end

#updated_atObject (readonly)

Time

When the video’s data was last updated.



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

def updated_at
  @updated_at
end

#video_idObject (readonly)

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



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

def video_id
  @video_id
end

#view_countObject (readonly)

Fixnum

Number of times that the video has been viewed



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

def view_count
  @view_count
end

Instance Method Details

#default_media_contentObject

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

Returns

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


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

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.


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

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


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

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)


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

def embeddable?
  not @noembed
end

#processed?Boolean

Has this vid been processed by YT?

Returns

Boolean

Returns:

  • (Boolean)


205
206
207
208
# File 'lib/youtube_g/model/video.rb', line 205

def processed?
  return true if self.app_control == nil
  return false if self.app_control.state.upcase == 'PROCESSING' || self.app_control.state.upcase == 'REJECTED' || self.app_control.state.upcase == 'FAILED'
end

Videos related to the current video.

Returns

YouTubeG::Response::VideoSearch


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

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


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

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.


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

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