video_info 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,52 +1,73 @@
1
- VideoInfo [![Build Status](https://secure.travis-ci.org/thibaudgg/video_info.png?branch=master)](http://travis-ci.org/thibaudgg/video_info)
2
- =========
3
-
4
- Small Ruby Gem to get video info from youtube and vimeo url.
5
- Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
6
-
7
- Install
8
- --------
9
-
10
- ``` bash
11
- gem install video_info
12
- ```
13
-
14
- Usage
15
- -----
16
-
17
- ``` ruby
18
- video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
19
-
20
- # video.video_id => "mZqGqE0D0n4"
21
- # video.provider => "YouTube"
22
- # video.title => "Cherry Bloom - King Of The Knife"
23
- # video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
24
- # video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
25
- # video.duration => 175 (in seconds)
26
- # video.date => Sat Apr 12 22:25:35 UTC 2008
27
- # video.thumbnail_small => "http://i.ytimg.com/vi/mZqGqE0D0n4/2.jpg"
28
- # video.thumbnail_large => "http://i.ytimg.com/vi/mZqGqE0D0n4/0.jpg"
29
-
30
- video = VideoInfo.new("http://vimeo.com/898029")
31
-
32
- # video.video_id => "898029"
33
- # video.provider => "Vimeo"
34
- # video.title => "Cherry Bloom - King Of The Knife"
35
- # video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
36
- # video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
37
- # video.duration => 175 (in seconds)
38
- # video.date => Mon Apr 14 13:10:39 +0200 2008
39
- # video.width => 640
40
- # video.height => 360
41
- # video.thumbnail_small => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_100.jpg"
42
- # video.thumbnail_large => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_640.jpg"
43
-
44
- video = VideoInfo.new("http://badurl.com/898029")
45
-
46
- # video.valid? => false
47
- ```
48
-
49
- Author
50
- ------
51
-
52
- [Thibaud Guillaume-Gentil](https://github.com/thibaudgg) ([@thibaudgg](http://twitter.com/thibaudgg))
1
+ VideoInfo [![Build Status](https://secure.travis-ci.org/thibaudgg/video_info.png?branch=master)](http://travis-ci.org/thibaudgg/video_info)
2
+ =========
3
+
4
+ Small Ruby Gem to get video info from youtube and vimeo url.
5
+ Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
6
+
7
+ Install
8
+ --------
9
+
10
+ ``` bash
11
+ gem install video_info
12
+ ```
13
+
14
+ Usage
15
+ -----
16
+
17
+ ``` ruby
18
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
19
+
20
+ # video.video_id => "mZqGqE0D0n4"
21
+ # video.provider => "YouTube"
22
+ # video.title => "Cherry Bloom - King Of The Knife"
23
+ # video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
24
+ # video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
25
+ # video.duration => 175 (in seconds)
26
+ # video.date => Sat Apr 12 22:25:35 UTC 2008
27
+ # video.thumbnail_small => "http://i.ytimg.com/vi/mZqGqE0D0n4/2.jpg"
28
+ # video.thumbnail_large => "http://i.ytimg.com/vi/mZqGqE0D0n4/0.jpg"
29
+
30
+ video = VideoInfo.new("http://vimeo.com/898029")
31
+
32
+ # video.video_id => "898029"
33
+ # video.provider => "Vimeo"
34
+ # video.title => "Cherry Bloom - King Of The Knife"
35
+ # video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
36
+ # video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
37
+ # video.duration => 175 (in seconds)
38
+ # video.date => Mon Apr 14 13:10:39 +0200 2008
39
+ # video.width => 640
40
+ # video.height => 360
41
+ # video.thumbnail_small => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_100.jpg"
42
+ # video.thumbnail_large => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_640.jpg"
43
+
44
+ video = VideoInfo.new("http://badurl.com/898029")
45
+
46
+ # video.valid? => false
47
+ ```
48
+
49
+ Options
50
+ -------
51
+
52
+ ``` ruby
53
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", "User-Agent" => "My Youtube Mashup Robot/1.0")
54
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer" => "http://my-youtube-mashup.com/")
55
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer" => "http://my-youtube-mashup.com/",
56
+ "User-Agent" => "My Youtube Mashup Robot/1.0")
57
+ ```
58
+ You can also use **symbols** instead of strings (any non-word (`/[^a-z]/i`) character would be converted to hyphen).
59
+
60
+ ``` ruby
61
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", :referer => "http://my-youtube-mashup.com/",
62
+ :user_agent => "My Youtube Mashup Robot/1.0")
63
+ ```
64
+
65
+ User-Agent when empty defaults to "VideoInfo/VERSION" - where version is current VideoInfo version, e.g. **"VideoInfo/0.2.7"**.
66
+
67
+ 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)
68
+
69
+
70
+ Author
71
+ ------
72
+
73
+ [Thibaud Guillaume-Gentil](https://github.com/thibaudgg) ([@thibaudgg](http://twitter.com/thibaudgg))
@@ -1,33 +1,32 @@
1
- require 'hpricot'
2
- require 'open-uri'
3
-
4
- class Vimeo
5
- attr_accessor :video_id, :url, :provider, :title, :description, :keywords,
6
- :duration, :date, :width, :height,
7
- :thumbnail_small, :thumbnail_large,
8
- :view_count
9
-
10
- def initialize(url)
11
- @video_id = url.gsub(/.*\.com\/(?:groups\/[^\/]+\/videos\/)?([0-9]+).*$/i, '\1')
12
- get_info unless @video_id == url
13
- end
14
-
15
- private
16
-
17
- def get_info
18
- doc = Hpricot(open("http://vimeo.com/api/v2/video/#{@video_id}.xml"))
19
- @provider = "Vimeo"
20
- @url = doc.search("url").inner_text
21
- @title = doc.search("title").inner_text
22
- @description = doc.search("description").inner_text
23
- @keywords = doc.search("tags").inner_text
24
- @duration = doc.search("duration").inner_text.to_i # seconds
25
- @width = doc.search("width").inner_text.to_i
26
- @height = doc.search("height").inner_text.to_i
27
- @date = Time.parse(doc.search("upload_date").inner_text, Time.now.utc).utc
28
- @thumbnail_small = doc.search("thumbnail_small").inner_text
29
- @thumbnail_large = doc.search("thumbnail_large").inner_text
30
- @view_count = doc.search("stats_number_of_plays").inner_text.to_i
31
- end
32
-
1
+ class Vimeo
2
+ attr_accessor :video_id, :url, :provider, :title, :description, :keywords,
3
+ :duration, :date, :width, :height,
4
+ :thumbnail_small, :thumbnail_large,
5
+ :view_count,
6
+ :openURI_options
7
+
8
+ def initialize(url, options = {})
9
+ @openURI_options = options
10
+ @video_id = url.gsub(/.*\.com\/(?:groups\/[^\/]+\/videos\/)?([0-9]+).*$/i, '\1')
11
+ get_info unless @video_id == url
12
+ end
13
+
14
+ private
15
+
16
+ def get_info
17
+ doc = Hpricot(open("http://vimeo.com/api/v2/video/#{@video_id}.xml", @openURI_options))
18
+ @provider = "Vimeo"
19
+ @url = doc.search("url").inner_text
20
+ @title = doc.search("title").inner_text
21
+ @description = doc.search("description").inner_text
22
+ @keywords = doc.search("tags").inner_text
23
+ @duration = doc.search("duration").inner_text.to_i # seconds
24
+ @width = doc.search("width").inner_text.to_i
25
+ @height = doc.search("height").inner_text.to_i
26
+ @date = Time.parse(doc.search("upload_date").inner_text, Time.now.utc).utc
27
+ @thumbnail_small = doc.search("thumbnail_small").inner_text
28
+ @thumbnail_large = doc.search("thumbnail_large").inner_text
29
+ @view_count = doc.search("stats_number_of_plays").inner_text.to_i
30
+ end
31
+
33
32
  end
@@ -1,47 +1,46 @@
1
- require 'hpricot'
2
- require 'open-uri'
3
-
4
- class Youtube
5
- attr_accessor :video_id, :url, :provider, :title, :description, :keywords,
6
- :duration, :date, :width, :height,
7
- :thumbnail_small, :thumbnail_large,
8
- :view_count
9
-
10
- def initialize(url)
11
- video_id_for(url)
12
- get_info unless @video_id == url
13
- end
14
-
15
- def regex
16
- /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?|http:\/\/(www.)?youtu\.be\/([A-Za-z0-9._%-]*)?/
17
- end
18
-
19
- def video_id_for(url)
20
- url.gsub(regex) do
21
- @video_id = $2 || $5
22
- end
23
- end
24
-
25
- private
26
-
27
- def get_info
28
- doc = Hpricot(open("http://gdata.youtube.com/feeds/api/videos/#{@video_id}"))
29
- @provider = "YouTube"
30
- @url = "http://www.youtube.com/watch?v=#{@video_id}"
31
- @title = doc.search("media:title").inner_text
32
- @description = doc.search("media:description").inner_text
33
- @keywords = doc.search("media:keywords").inner_text
34
- @duration = doc.search("yt:duration").first[:seconds].to_i
35
- @date = Time.parse(doc.search("published").inner_text, Time.now.utc)
36
- @thumbnail_small = doc.search("media:thumbnail").min { |a,b| a[:height].to_i * a[:width].to_i <=> b[:height].to_i * b[:width].to_i }[:url]
37
- @thumbnail_large = doc.search("media:thumbnail").max { |a,b| a[:height].to_i * a[:width].to_i <=> b[:height].to_i * b[:width].to_i }[:url]
38
- # when your video still has no view, yt:statistics is not returned by Youtube
39
- # see: https://github.com/thibaudgg/video_info/issues#issue/2
40
- if doc.search("yt:statistics").first
41
- @view_count = doc.search("yt:statistics").first[:viewcount].to_i
42
- else
43
- @view_count = 0
44
- end
45
- end
46
-
47
- end
1
+ class Youtube
2
+ attr_accessor :video_id, :url, :provider, :title, :description, :keywords,
3
+ :duration, :date, :width, :height,
4
+ :thumbnail_small, :thumbnail_large,
5
+ :view_count,
6
+ :openURI_options
7
+
8
+ def initialize(url, options = {})
9
+ @openURI_options = options
10
+ video_id_for(url)
11
+ get_info unless @video_id == url
12
+ end
13
+
14
+ def regex
15
+ /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?|http:\/\/(www.)?youtu\.be\/([A-Za-z0-9._%-]*)?/
16
+ end
17
+
18
+ def video_id_for(url)
19
+ url.gsub(regex) do
20
+ @video_id = $2 || $5
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def get_info
27
+ doc = Hpricot(open("http://gdata.youtube.com/feeds/api/videos/#{@video_id}", @openURI_options))
28
+ @provider = "YouTube"
29
+ @url = "http://www.youtube.com/watch?v=#{@video_id}"
30
+ @title = doc.search("media:title").inner_text
31
+ @description = doc.search("media:description").inner_text
32
+ @keywords = doc.search("media:keywords").inner_text
33
+ @duration = doc.search("yt:duration").first[:seconds].to_i
34
+ @date = Time.parse(doc.search("published").inner_text, Time.now.utc)
35
+ @thumbnail_small = doc.search("media:thumbnail").min { |a,b| a[:height].to_i * a[:width].to_i <=> b[:height].to_i * b[:width].to_i }[:url]
36
+ @thumbnail_large = doc.search("media:thumbnail").max { |a,b| a[:height].to_i * a[:width].to_i <=> b[:height].to_i * b[:width].to_i }[:url]
37
+ # when your video still has no view, yt:statistics is not returned by Youtube
38
+ # see: https://github.com/thibaudgg/video_info/issues#issue/2
39
+ if doc.search("yt:statistics").first
40
+ @view_count = doc.search("yt:statistics").first[:viewcount].to_i
41
+ else
42
+ @view_count = 0
43
+ end
44
+ end
45
+
46
+ end
@@ -1,25 +1,39 @@
1
- require 'provider/vimeo'
2
- require 'provider/youtube'
3
-
4
- class VideoInfo
5
-
6
- def initialize(url)
7
- case url
8
- when /vimeo\.com/
9
- @video = Vimeo.new(url)
10
- when /youtube\.com/
11
- @video = Youtube.new(url)
12
- when /youtu\.be/
13
- @video = Youtube.new(url)
14
- end
15
- end
16
-
17
- def valid?
18
- @video != nil && !["", nil].include?(title)
19
- end
20
-
21
- def method_missing(sym, *args, &block)
22
- @video.send sym, *args, &block
23
- end
24
-
25
- end
1
+ require 'open-uri'
2
+ require 'hpricot'
3
+ require 'video_info/version'
4
+ require 'provider/vimeo'
5
+ require 'provider/youtube'
6
+
7
+ class VideoInfo
8
+
9
+ def initialize(url, options = {})
10
+
11
+ options = { "User-Agent" => "VideoInfo/#{VideoInfoVersion::VERSION}" }.merge options
12
+ options.dup.each do |key,value|
13
+ unless OpenURI::Options.keys.include? key
14
+ if key.is_a? Symbol
15
+ options[key.to_s.split(/[^a-z]/i).map(&:capitalize).join('-')] = value
16
+ options.delete key
17
+ end
18
+ end
19
+ end
20
+
21
+ case url
22
+ when /vimeo\.com/
23
+ @video = Vimeo.new(url, options)
24
+ when /youtube\.com/
25
+ @video = Youtube.new(url, options)
26
+ when /youtu\.be/
27
+ @video = Youtube.new(url, options)
28
+ end
29
+ end
30
+
31
+ def valid?
32
+ @video != nil && !["", nil].include?(title)
33
+ end
34
+
35
+ def method_missing(sym, *args, &block)
36
+ @video.send sym, *args, &block
37
+ end
38
+
39
+ end
@@ -1,3 +1,3 @@
1
1
  module VideoInfoVersion
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
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.2.7
4
+ version: 0.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-13 00:00:00.000000000Z
12
+ date: 2011-11-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hpricot
16
- requirement: &70190131499240 !ruby/object:Gem::Requirement
16
+ requirement: &70141481121100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.8.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70190131499240
24
+ version_requirements: *70141481121100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70190131497380 !ruby/object:Gem::Requirement
27
+ requirement: &70141481120500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70190131497380
35
+ version_requirements: *70141481120500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70190131491960 !ruby/object:Gem::Requirement
38
+ requirement: &70141481119200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.7.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70190131491960
46
+ version_requirements: *70141481119200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
- requirement: &70190131490300 !ruby/object:Gem::Requirement
49
+ requirement: &70141481118360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70190131490300
57
+ version_requirements: *70141481118360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &70190131482420 !ruby/object:Gem::Requirement
60
+ requirement: &70141481117300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70190131482420
68
+ version_requirements: *70141481117300
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: vcr
71
- requirement: &70190131475840 !ruby/object:Gem::Requirement
71
+ requirement: &70141481116600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70190131475840
79
+ version_requirements: *70141481116600
80
80
  description: Get video info from youtube and vimeo url.
81
81
  email:
82
82
  - thibaud@thibaud.me
@@ -104,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  segments:
106
106
  - 0
107
- hash: -4408431295325630864
107
+ hash: -2856754979042863161
108
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  none: false
110
110
  requirements:
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  segments:
115
115
  - 0
116
- hash: -4408431295325630864
116
+ hash: -2856754979042863161
117
117
  requirements: []
118
118
  rubyforge_project: video_info
119
119
  rubygems_version: 1.8.9