Class: VgYoutube

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of VgYoutube.



9
10
11
12
13
14
15
16
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 9

def initialize(url=nil, options={})
  object = YouTubeIt::Client.new({})
  @url = url
  @video_id = @url.query_param('v')
  @details = object.video_by(@video_id)
  @details.instance_variable_set(:@noembed, false)
  raise if @details.blank?
end

Instance Method Details

#download_urlObject



49
50
51
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 49

def download_url
  flv
end

#durationObject



26
27
28
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 26

def duration
  @details.duration
end

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

options

You can read more about the youtube player options in 
http://code.google.com/intl/en/apis/youtube/player_parameters.html
Use them in options (ex {:rel => 0, :color1 => '0x333333'})


39
40
41
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 39

def embed_html(width=425, height=344, options={})
  "<object width='#{width}' height='#{height}'><param name='movie' value='#{embed_url}#{options.map {|k,v| "&#{k}=#{v}"}}'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='#{embed_url}#{options.map {|k,v| "&#{k}=#{v}"}}' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='#{width}' height='#{height}'></embed></object>" if @details.noembed == false
end

#embed_urlObject



30
31
32
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 30

def embed_url
  @details.media_content.first.url if @details.noembed == false
end

#flvObject



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

def flv
  doc = URI::parse("http://www.youtube.com/get_video_info?&video_id=#{@video_id}").read
  CGI::unescape(doc.split("&fmt_url_map=")[1].split("&")[0]).split("|")[1].split(",")[0]
end

#serviceObject



53
54
55
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 53

def service
  "Youtube"
end

#thumbnailObject



22
23
24
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 22

def thumbnail
  @details.thumbnails.first.url
end

#titleObject



18
19
20
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 18

def title
  @details.title
end