video_info 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,44 +1,44 @@
1
- = VideoInfo
2
-
3
- Small Ruby Gem to get video info from youtube and vimeo url.
4
- Tested on Ruby 1.8.6, 1.8.7 & 1.9.2
5
-
6
- == Install
7
-
8
- gem install video_info
9
-
10
- == Usage
11
-
12
- video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
13
-
14
- video.id => "mZqGqE0D0n4"
15
- video.provider => "YouTube"
16
- video.title => "Cherry Bloom - King Of The Knife"
17
- video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
18
- video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
19
- video.duration => 175 (in seconds)
20
- video.date => Sat Apr 12 22:25:35 UTC 2008
21
- video.thumbnail_small => "http://i.ytimg.com/vi/mZqGqE0D0n4/2.jpg"
22
- video.thumbnail_large => "http://i.ytimg.com/vi/mZqGqE0D0n4/0.jpg"
23
-
24
- video = VideoInfo.new("http://vimeo.com/898029")
25
-
26
- video.id => "898029"
27
- video.provider => "Vimeo"
28
- video.title => "Cherry Bloom - King Of The Knife"
29
- video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
30
- video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
31
- video.duration => 175 (in seconds)
32
- video.date => Mon Apr 14 13:10:39 +0200 2008
33
- video.width => 640
34
- video.height => 360
35
- video.thumbnail_small => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_100.jpg"
36
- video.thumbnail_large => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_640.jpg"
37
-
38
- video = VideoInfo.new("http://badurl.com/898029")
39
-
40
- video.valid? => false
41
-
42
- == Author
43
-
44
- Thibaud Guillaume-Gentil
1
+ = VideoInfo
2
+
3
+ Small Ruby Gem to get video info from youtube and vimeo url.
4
+ Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
5
+
6
+ == Install
7
+
8
+ gem install video_info
9
+
10
+ == Usage
11
+
12
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
13
+
14
+ video.video_id => "mZqGqE0D0n4"
15
+ video.provider => "YouTube"
16
+ video.title => "Cherry Bloom - King Of The Knife"
17
+ video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
18
+ video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
19
+ video.duration => 175 (in seconds)
20
+ video.date => Sat Apr 12 22:25:35 UTC 2008
21
+ video.thumbnail_small => "http://i.ytimg.com/vi/mZqGqE0D0n4/2.jpg"
22
+ video.thumbnail_large => "http://i.ytimg.com/vi/mZqGqE0D0n4/0.jpg"
23
+
24
+ video = VideoInfo.new("http://vimeo.com/898029")
25
+
26
+ video.video_id => "898029"
27
+ video.provider => "Vimeo"
28
+ video.title => "Cherry Bloom - King Of The Knife"
29
+ video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
30
+ video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
31
+ video.duration => 175 (in seconds)
32
+ video.date => Mon Apr 14 13:10:39 +0200 2008
33
+ video.width => 640
34
+ video.height => 360
35
+ video.thumbnail_small => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_100.jpg"
36
+ video.thumbnail_large => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_640.jpg"
37
+
38
+ video = VideoInfo.new("http://badurl.com/898029")
39
+
40
+ video.valid? => false
41
+
42
+ == Author
43
+
44
+ Thibaud Guillaume-Gentil
@@ -1,37 +1,47 @@
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 = url.gsub(/.*v=([^&]+).*$/i, '\1')
12
- get_info unless @video_id == url
13
- end
14
-
15
- private
16
-
17
- def get_info
18
- doc = Hpricot(open("http://gdata.youtube.com/feeds/api/videos/#{@video_id}"))
19
- @provider = "YouTube"
20
- @url = "http://www.youtube.com/watch?v=#{@video_id}"
21
- @title = doc.search("media:title").inner_text
22
- @description = doc.search("media:description").inner_text
23
- @keywords = doc.search("media:keywords").inner_text
24
- @duration = doc.search("yt:duration").first[:seconds].to_i
25
- @date = Time.parse(doc.search("published").inner_text, Time.now.utc)
26
- @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]
27
- @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]
28
- # when your video still has no view, yt:statistics is not returned by Youtube
29
- # see: https://github.com/thibaudgg/video_info/issues#issue/2
30
- if doc.search("yt:statistics").first
31
- @view_count = doc.search("yt:statistics").first[:viewcount].to_i
32
- else
33
- @view_count = 0
34
- end
35
- end
36
-
37
- end
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
data/lib/video_info.rb CHANGED
@@ -1,23 +1,25 @@
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
- end
13
- end
14
-
15
- def valid?
16
- @video != nil && !["", nil].include?(title)
17
- end
18
-
19
- def method_missing(sym, *args, &block)
20
- @video.send sym, *args, &block
21
- end
22
-
23
- end
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,3 +1,3 @@
1
1
  module VideoInfoVersion
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
metadata CHANGED
@@ -1,160 +1,118 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: video_info
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 5
10
- version: 0.2.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.6
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Thibaud Guillaume-Gentil
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-04-17 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: bundler
12
+ date: 2011-10-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hpricot
16
+ requirement: &70127803224080 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.4
22
+ type: :runtime
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: *70127803224080
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &70127803223600 !ruby/object:Gem::Requirement
25
28
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
33
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rspec
37
34
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: *70127803223600
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70127803222800 !ruby/object:Gem::Requirement
39
39
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 31
44
- segments:
45
- - 2
46
- - 4
47
- - 0
48
- version: 2.4.0
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 2.7.0
49
44
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: guard-rspec
53
45
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
46
+ version_requirements: *70127803222800
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard-rspec
49
+ requirement: &70127803222080 !ruby/object:Gem::Requirement
55
50
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
63
55
  type: :development
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: webmock
67
56
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
57
+ version_requirements: *70127803222080
58
+ - !ruby/object:Gem::Dependency
59
+ name: webmock
60
+ requirement: &70127803220980 !ruby/object:Gem::Requirement
69
61
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
77
66
  type: :development
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: vcr
81
67
  prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
68
+ version_requirements: *70127803220980
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: &70127803208580 !ruby/object:Gem::Requirement
83
72
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
91
77
  type: :development
92
- version_requirements: *id005
93
- - !ruby/object:Gem::Dependency
94
- name: hpricot
95
78
  prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- hash: 55
102
- segments:
103
- - 0
104
- - 8
105
- - 4
106
- version: 0.8.4
107
- type: :runtime
108
- version_requirements: *id006
79
+ version_requirements: *70127803208580
109
80
  description: Get video info from youtube and vimeo url.
110
- email:
81
+ email:
111
82
  - thibaud@thibaud.me
112
83
  executables: []
113
-
114
84
  extensions: []
115
-
116
85
  extra_rdoc_files: []
117
-
118
- files:
86
+ files:
119
87
  - lib/provider/vimeo.rb
120
88
  - lib/provider/youtube.rb
121
89
  - lib/video_info/version.rb
122
90
  - lib/video_info.rb
123
91
  - LICENSE
124
92
  - README.rdoc
125
- has_rdoc: true
126
93
  homepage: http://rubygems.org/gems/video_info
127
94
  licenses: []
128
-
129
95
  post_install_message:
130
96
  rdoc_options: []
131
-
132
- require_paths:
97
+ require_paths:
133
98
  - lib
134
- required_ruby_version: !ruby/object:Gem::Requirement
99
+ required_ruby_version: !ruby/object:Gem::Requirement
135
100
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- hash: 3
140
- segments:
141
- - 0
142
- version: "0"
143
- required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
106
  none: false
145
- requirements:
146
- - - ">="
147
- - !ruby/object:Gem::Version
148
- hash: 3
149
- segments:
150
- - 0
151
- version: "0"
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
152
111
  requirements: []
153
-
154
112
  rubyforge_project: video_info
155
- rubygems_version: 1.3.7
113
+ rubygems_version: 1.8.9
156
114
  signing_key:
157
115
  specification_version: 3
158
116
  summary: Vimeo & Youtube parser
159
117
  test_files: []
160
-
118
+ has_rdoc: