video_info 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -70,6 +70,12 @@ User-Agent when empty defaults to "VideoInfo/VERSION" - where version is current
70
70
 
71
71
  It supports all openURI header fields (options), for more information see: [openURI DOCS](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/OpenURI.html)
72
72
 
73
+ You can also include an `iframe_attributes` hash to include arbitrary attributes in the iframe embed code:
74
+
75
+ ``` ruby
76
+ VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", :iframe_attributes => { :width => 800, :height => 600, "data-key" => "value" } ).embed_code
77
+ => '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen" width="800" height="600" data-key="value"></iframe>'
78
+ ```
73
79
 
74
80
  Author
75
81
  ------
@@ -6,6 +6,7 @@ class Vimeo
6
6
  :openURI_options
7
7
 
8
8
  def initialize(url, options = {})
9
+ @iframe_attributes = VideoInfo.hash_to_attributes options.delete(:iframe_attributes) if options[:iframe_attributes]
9
10
  @openURI_options = options
10
11
  @video_id = url.gsub(/.*\.com\/(?:groups\/[^\/]+\/videos\/)?([0-9]+).*$/i, '\1')
11
12
  get_info unless @video_id == url || @video_id.nil? || @video_id.empty?
@@ -19,7 +20,7 @@ private
19
20
  @provider = "Vimeo"
20
21
  @url = doc.search("url").inner_text
21
22
  @embed_url = "http://player.vimeo.com/video/#{@video_id}"
22
- @embed_code = "<iframe src=\"#{@embed_url}?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=0\" frameborder=\"0\"></iframe>"
23
+ @embed_code = "<iframe src=\"#{@embed_url}?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=0\" frameborder=\"0\"#{@iframe_attributes}></iframe>"
23
24
  @title = doc.search("title").inner_text
24
25
  @description = doc.search("description").inner_text
25
26
  @keywords = doc.search("tags").inner_text
@@ -6,6 +6,7 @@ class Youtube
6
6
  :openURI_options
7
7
 
8
8
  def initialize(url, options = {})
9
+ @iframe_attributes = VideoInfo.hash_to_attributes options.delete(:iframe_attributes) if options[:iframe_attributes]
9
10
  @openURI_options = options
10
11
  video_id_for(url)
11
12
  get_info unless @video_id == url || @video_id.nil? || @video_id.empty?
@@ -29,7 +30,7 @@ private
29
30
  @provider = "YouTube"
30
31
  @url = "http://www.youtube.com/watch?v=#{@video_id}"
31
32
  @embed_url = "http://www.youtube.com/embed/#{@video_id}"
32
- @embed_code = "<iframe src=\"#{@embed_url}\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"></iframe>"
33
+ @embed_code = "<iframe src=\"#{@embed_url}\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"#{@iframe_attributes}></iframe>"
33
34
  @title = doc.search("media:title").inner_text
34
35
  @description = doc.search("media:description").inner_text
35
36
  @keywords = doc.search("media:keywords").inner_text
data/lib/video_info.rb CHANGED
@@ -10,7 +10,7 @@ class VideoInfo
10
10
 
11
11
  options = { "User-Agent" => "VideoInfo/#{VideoInfoVersion::VERSION}" }.merge options
12
12
  options.dup.each do |key,value|
13
- unless OpenURI::Options.keys.include? key
13
+ unless OpenURI::Options.keys.include?(key) || options[:iframe_attributes]
14
14
  if key.is_a? Symbol
15
15
  options[key.to_s.split(/[^a-z]/i).map(&:capitalize).join('-')] = value
16
16
  options.delete key
@@ -36,4 +36,9 @@ class VideoInfo
36
36
  @video.send sym, *args, &block
37
37
  end
38
38
 
39
+ def self.hash_to_attributes(hash)
40
+ s = hash.map{|k,v| "#{k}=\"#{v}\""}.join(' ')
41
+ " #{s}"
42
+ end
43
+
39
44
  end
@@ -1,3 +1,3 @@
1
1
  module VideoInfoVersion
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: video_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-30 00:00:00.000000000 Z
12
+ date: 2012-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hpricot
@@ -132,21 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  - - ! '>='
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
- segments:
136
- - 0
137
- hash: -2888328597512139102
138
135
  required_rubygems_version: !ruby/object:Gem::Requirement
139
136
  none: false
140
137
  requirements:
141
138
  - - ! '>='
142
139
  - !ruby/object:Gem::Version
143
140
  version: '0'
144
- segments:
145
- - 0
146
- hash: -2888328597512139102
147
141
  requirements: []
148
142
  rubyforge_project: video_info
149
- rubygems_version: 1.8.24
143
+ rubygems_version: 1.8.23
150
144
  signing_key:
151
145
  specification_version: 3
152
146
  summary: Vimeo & Youtube parser