Class: VgYoutube

Inherits:
Object show all
Defined in:
lib/acts_as_unvlogable/vg_youtube.rb

Overview


Class for Youtube (youtube.com)
http://www.youtube.com/watch?v=MVa4q-YVjD8

Direct Known Subclasses

VgYoutu

Instance Method Summary collapse

Constructor Details

#initialize(url = nil, options = {}) ⇒ VgYoutube

Returns a new instance of VgYoutube.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 8

def initialize(url=nil, options={})
  settings ||= YAML.load_file(RAILS_ROOT + '/config/unvlogable.yml') rescue {}
  Yt.configure do |config|
    config.api_key = options.nil? || options[:key].nil? ? settings['youtube_key'] : options[:key]
  end

  @url = url
  @video_id = @url.query_param('v')
  begin
    @details = Yt::Video.new id: @video_id
    raise if @details.blank? || !@details.embeddable?
  rescue
    raise ArgumentError, "Unsuported url or service"
  end
end

Instance Method Details

#durationObject



32
33
34
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 32

def duration
  @details.duration
end

#embed_html(width = 425, height = 344, options = {}, params = {}) ⇒ Object



41
42
43
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 41

def embed_html(width=425, height=344, options={}, params={})
  "<iframe id='ytplayer' type='text/html' width='#{width}' height='#{height}' src='#{embed_url}#{options.map {|k,v| "&#{k}=#{v}"}}' frameborder='0'/>" if @details.embeddable?
end

#embed_urlObject



36
37
38
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 36

def embed_url
  "http://www.youtube.com/embed/#{@video_id}" if @details.embeddable?
end

#serviceObject



45
46
47
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 45

def service
  "Youtube"
end

#thumbnailObject



28
29
30
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 28

def thumbnail
  @details.thumbnail_url
end

#titleObject



24
25
26
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 24

def title
  @details.title
end