Class: YouTubeIt::Model::Video

Inherits:
Record
  • Object
show all
Defined in:
lib/youtube_it/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 YouTubeIt::Record

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



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

def author
  @author
end

#categoriesObject (readonly)

Returns the value of attribute categories.



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

def categories
  @categories
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#favorite_countObject (readonly)

Returns the value of attribute favorite_count.



116
117
118
# File 'lib/youtube_it/model/video.rb', line 116

def favorite_count
  @favorite_count
end

#html_contentObject (readonly)

Returns the value of attribute html_content.



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

def html_content
  @html_content
end

#insight_uriObject (readonly)

Returns the value of attribute insight_uri.



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

def insight_uri
  @insight_uri
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



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

def keywords
  @keywords
end

#latitudeObject (readonly)

Returns the value of attribute latitude.



127
128
129
# File 'lib/youtube_it/model/video.rb', line 127

def latitude
  @latitude
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



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

def longitude
  @longitude
end

#media_contentObject (readonly)

Returns the value of attribute media_content.



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

def media_content
  @media_content
end

#noembedObject (readonly)

Returns the value of attribute noembed.



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

def noembed
  @noembed
end

#player_urlObject (readonly)

Returns the value of attribute player_url.



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

def player_url
  @player_url
end

#positionObject (readonly)

Returns the value of attribute position.



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

def position
  @position
end

#published_atObject (readonly)

Returns the value of attribute published_at.



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

def published_at
  @published_at
end

#ratingObject (readonly)

Returns the value of attribute rating.



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

def rating
  @rating
end

#safe_searchObject (readonly)

Returns the value of attribute safe_search.



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

def safe_search
  @safe_search
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

#thumbnailsObject (readonly)

Returns the value of attribute thumbnails.



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

def thumbnails
  @thumbnails
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

#video_idObject (readonly)

Returns the value of attribute video_id.



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

def video_id
  @video_id
end

#view_countObject (readonly)

Returns the value of attribute view_count.



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

def view_count
  @view_count
end

#widescreenObject (readonly)

Returns the value of attribute widescreen.



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

def widescreen
  @widescreen
end

Instance Method Details

#default_media_contentObject



177
178
179
# File 'lib/youtube_it/model/video.rb', line 177

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

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



185
186
187
188
189
190
191
192
193
194
# File 'lib/youtube_it/model/video.rb', line 185

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_html5(params = {}) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/youtube_it/model/video.rb', line 200

def embed_html5(params = {})
  opts = {:class  => params[:class]  || "",
          :id     => params[:id]     || "",
          :width  => params[:width]  || "425",
          :height => params[:height] || "350",
          :frameborder => params[:frameborder] || "0",
          :url_params => params[:url_params] || {}
          }
  url_opts = opts[:url_params].empty? ? "" : "?#{Rack::Utils::build_query(opts[:url_params])}"
  <<EDOC
<iframe class="#{opts[:class]}" id="#{opts[:id]}" type="text/html" width="#{opts[:width]}" height="#{opts[:height]}" src="http://www.youtube.com/embed/#{unique_id}#{url_opts}" frameborder="#{opts[:frameborder]}"></iframe>
EDOC
end

#embed_html_with_width(width = 1280) ⇒ Object

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

Returns

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



218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/youtube_it/model/video.rb', line 218

def embed_html_with_width(width = 1280)
  height = (widescreen? ? width * 9/16 : width * 3/4) + 25

  <<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


235
236
237
# File 'lib/youtube_it/model/video.rb', line 235

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

#embeddable?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/youtube_it/model/video.rb', line 161

def embeddable?
  not @noembed
end


134
135
136
# File 'lib/youtube_it/model/video.rb', line 134

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

#responsesObject



141
142
143
# File 'lib/youtube_it/model/video.rb', line 141

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

#unique_idObject



153
154
155
# File 'lib/youtube_it/model/video.rb', line 153

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

#widescreen?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/youtube_it/model/video.rb', line 169

def widescreen?
  @widescreen
end