class MultimediaParadise::YoutubeEmbedder

Constants

DEFAULT_URL
#

DEFAULT_URL

#

Attributes

id[W]
#

Define four setters and getters - id, uri, provider, params.

#
params[RW]
provider[RW]
uri[RW]

Public Class Methods

new(link, run_already = true) click to toggle source
#

initialize

The first argument should be the link to youtube.

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 40
def initialize(link, run_already = true)
  reset
  set_link(link)
  case run_already
  when :dont_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

determine_params(i = @uri) click to toggle source
#

determine_params

We must be careful here - the input should be a string.

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 110
def determine_params(i = @uri)
  @params = Hash[*i.query.split('&').map {|entry|
    splitted = entry.split('=')
    splitted[0] = splitted.first.to_sym # First entry becomes a symbol
    splitted
  }.flatten]
end
determine_provider(i = @uri) click to toggle source
#

determine_provider

We determine the provider here.

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 123
def determine_provider(i = @uri)
  @provider = case i.host
              when /youtube.com/ then :youtube
              end
end
embed( dimensions = @width+'x'+@height, options = {} ) click to toggle source
#

embed

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 63
def embed(
    dimensions = @width+'x'+@height,
    options = {}
  )
  options[:load] = true if options[:load].nil?
  if dimensions.include? 'x'
    h, w = dimensions.split('x')
  else
    h = w = dimensions # Assume '50' as input actually means '50x50'.
  end
  if youtube?
    @embed = %(
      <iframe width="#{h}" height="#{w}" #{options[:load] ? 'src' : 'data-src'}="http://www.youtube.com/embed/#{id}?html5=1"
    )
    # Process the @options next.
    options.each {| key, value|
      next if key == :load
      @embed << %( data-#{key}="#{value}" )
    }
    @embed << %( frameborder="0" allowfullscreen></iframe>)
  else
    @embed << 'NOT FOUND ANYTHING.<br>'
  end
end
embed?() click to toggle source
#

embed?

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 91
def embed?
  @embed
end
Also aliased as: embedded_string?
embedded_string?()
Alias for: embed?
feedback() click to toggle source
#

feedback

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 155
def feedback
  lpad = 32
  e 'Now testing some components for '+simp(url?)+':'
  e ('The id is: ').ljust(lpad)+sfancy(id)
  e ('The provider is: ').ljust(lpad)+sfancy(provider.to_s)
  e ('The thumbnail is: ').ljust(lpad)+sfancy(thumbnail)
  e
  e 'And to embed this into your webpage, use this code here:'+N+N
  e '  '+embed
  e N+N
end
id()
Alias for: id?
id?() click to toggle source
#

id?

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 141
def id?
  params[:v] if youtube?
end
Also aliased as: id
parse_uri(i = @link) click to toggle source
#

parse_uri

This will set @uri.

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 134
def parse_uri(i = @link)
  @uri = URI(i)
end
reset() click to toggle source
#

reset

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 53
def reset
  super()
  @embed = ''
  set_width('560')
  set_height('315')
end
run() click to toggle source
#

run

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 217
def run
  parse_uri
  determine_provider
  determine_params
  embed
  return @embed
end
set_height(i) click to toggle source
#

set_height

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 180
def set_height(i)
  if i.is_a? Hash and i.has_key?(:height)
    i = i.delete :height
  end
  @height = i.to_s
end
set_width(i) click to toggle source
#

set_width

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 170
def set_width(i)
  if i.is_a? Hash and i.has_key?(:width)
    i = i.delete :width
  end
  @width = i.to_s
end
thumbnail(size = :default) click to toggle source
#

thumbnail

Give back a thumbnail of the youtube video.

Each YouTube video has 4 generated images.

They are predictably formatted as follows:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 208
def thumbnail(size = :default)
  if youtube?
    "http://img.youtube.com/vi/#{id?}/0.jpg"
  end
end
url?() click to toggle source
#

url?

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 190
def url?
  @uri.to_s
end
youtube?() click to toggle source
#

youtube?

#
# File lib/multimedia_paradise/video/youtube_embedder.rb, line 148
def youtube?
  provider == :youtube # This sets the @provider ivar.
end