video_info 0.2.11 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,22 +1,22 @@
1
1
  VideoInfo [![Build Status](https://secure.travis-ci.org/thibaudgg/video_info.png?branch=master)](http://travis-ci.org/thibaudgg/video_info)
2
2
  =========
3
-
3
+
4
4
  Small Ruby Gem to get video info from youtube and vimeo url.
5
5
  Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
6
-
6
+
7
7
  Install
8
8
  --------
9
9
 
10
10
  ``` bash
11
11
  gem install video_info
12
12
  ```
13
-
13
+
14
14
  Usage
15
15
  -----
16
-
16
+
17
17
  ``` ruby
18
18
  video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
19
-
19
+
20
20
  # video.video_id => "mZqGqE0D0n4"
21
21
  # video.provider => "YouTube"
22
22
  # video.title => "Cherry Bloom - King Of The Knife"
@@ -26,9 +26,11 @@ Usage
26
26
  # video.date => Sat Apr 12 22:25:35 UTC 2008
27
27
  # video.thumbnail_small => "http://i.ytimg.com/vi/mZqGqE0D0n4/2.jpg"
28
28
  # video.thumbnail_large => "http://i.ytimg.com/vi/mZqGqE0D0n4/0.jpg"
29
-
29
+ # video.embed_url => "http://www.youtube.com/embed/mZqGqE0D0n4"
30
+ # video.embed_code => "'<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"
31
+
30
32
  video = VideoInfo.new("http://vimeo.com/898029")
31
-
33
+
32
34
  # video.video_id => "898029"
33
35
  # video.provider => "Vimeo"
34
36
  # video.title => "Cherry Bloom - King Of The Knife"
@@ -40,9 +42,11 @@ Usage
40
42
  # video.height => 360
41
43
  # video.thumbnail_small => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_100.jpg"
42
44
  # video.thumbnail_large => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_640.jpg"
43
-
45
+ # video.embed_url => "http://player.vimeo.com/video/898029"
46
+ # video.embed_code => "'<iframe src="http://player.vimeo.com/video/898029?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=0" frameborder="0"></iframe>'"
47
+
44
48
  video = VideoInfo.new("http://badurl.com/898029")
45
-
49
+
46
50
  # video.valid? => false
47
51
  ```
48
52
 
@@ -71,3 +75,9 @@ Author
71
75
  ------
72
76
 
73
77
  [Thibaud Guillaume-Gentil](https://github.com/thibaudgg) ([@thibaudgg](http://twitter.com/thibaudgg))
78
+
79
+ Contributors
80
+ ------------
81
+
82
+ [https://github.com/thibaudgg/video_info/contributors](https://github.com/thibaudgg/video_info/contributors)
83
+
@@ -1,5 +1,5 @@
1
1
  class Vimeo
2
- attr_accessor :video_id, :url, :provider, :title, :description, :keywords,
2
+ attr_accessor :video_id, :embed_url, :embed_code, :url, :provider, :title, :description, :keywords,
3
3
  :duration, :date, :width, :height,
4
4
  :thumbnail_small, :thumbnail_large,
5
5
  :view_count,
@@ -8,25 +8,31 @@ class Vimeo
8
8
  def initialize(url, options = {})
9
9
  @openURI_options = options
10
10
  @video_id = url.gsub(/.*\.com\/(?:groups\/[^\/]+\/videos\/)?([0-9]+).*$/i, '\1')
11
- get_info unless @video_id == url
11
+ get_info unless @video_id == url || @video_id.nil? || @video_id.empty?
12
12
  end
13
13
 
14
14
  private
15
15
 
16
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
17
+ begin
18
+ doc = Hpricot(open("http://vimeo.com/api/v2/video/#{@video_id}.xml", @openURI_options))
19
+ @provider = "Vimeo"
20
+ @url = doc.search("url").inner_text
21
+ @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
+ @title = doc.search("title").inner_text
24
+ @description = doc.search("description").inner_text
25
+ @keywords = doc.search("tags").inner_text
26
+ @duration = doc.search("duration").inner_text.to_i # seconds
27
+ @width = doc.search("width").inner_text.to_i
28
+ @height = doc.search("height").inner_text.to_i
29
+ @date = Time.parse(doc.search("upload_date").inner_text, Time.now.utc).utc
30
+ @thumbnail_small = doc.search("thumbnail_small").inner_text
31
+ @thumbnail_large = doc.search("thumbnail_large").inner_text
32
+ @view_count = doc.search("stats_number_of_plays").inner_text.to_i
33
+ rescue
34
+ nil
35
+ end
30
36
  end
31
37
 
32
- end
38
+ end
@@ -1,5 +1,5 @@
1
1
  class Youtube
2
- attr_accessor :video_id, :embed_url, :url, :provider, :title, :description, :keywords,
2
+ attr_accessor :video_id, :embed_url, :embed_code, :url, :provider, :title, :description, :keywords,
3
3
  :duration, :date, :width, :height,
4
4
  :thumbnail_small, :thumbnail_large,
5
5
  :view_count,
@@ -8,7 +8,7 @@ class Youtube
8
8
  def initialize(url, options = {})
9
9
  @openURI_options = options
10
10
  video_id_for(url)
11
- get_info unless @video_id == url
11
+ get_info unless @video_id == url || @video_id.nil? || @video_id.empty?
12
12
  end
13
13
 
14
14
  def regex
@@ -24,23 +24,28 @@ class Youtube
24
24
  private
25
25
 
26
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
- @embed_url = "http://www.youtube.com/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
27
+ begin
28
+ doc = Hpricot(open("http://gdata.youtube.com/feeds/api/videos/#{@video_id}", @openURI_options))
29
+ @provider = "YouTube"
30
+ @url = "http://www.youtube.com/watch?v=#{@video_id}"
31
+ @embed_url = "http://www.youtube.com/embed/#{@video_id}"
32
+ @embed_code = "<iframe src=\"#{@embed_url}\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"></iframe>"
33
+ @title = doc.search("media:title").inner_text
34
+ @description = doc.search("media:description").inner_text
35
+ @keywords = doc.search("media:keywords").inner_text
36
+ @duration = doc.search("yt:duration").first[:seconds].to_i
37
+ @date = Time.parse(doc.search("published").inner_text, Time.now.utc)
38
+ @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]
39
+ @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]
40
+ # when your video still has no view, yt:statistics is not returned by Youtube
41
+ # see: https://github.com/thibaudgg/video_info/issues#issue/2
42
+ if doc.search("yt:statistics").first
43
+ @view_count = doc.search("yt:statistics").first[:viewcount].to_i
44
+ else
45
+ @view_count = 0
46
+ end
47
+ rescue
48
+ nil
44
49
  end
45
50
  end
46
51
 
@@ -1,3 +1,3 @@
1
1
  module VideoInfoVersion
2
- VERSION = "0.2.11"
2
+ VERSION = "0.3.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.2.11
4
+ version: 0.3.0
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: 2012-03-13 00:00:00.000000000 Z
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hpricot
16
- requirement: &70316433216660 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.8.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70316433216660
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.4
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: bundler
27
- requirement: &70316433216260 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,21 +37,31 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70316433216260
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &70316433215720 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
- - - ! '>='
51
+ - - ~>
42
52
  - !ruby/object:Gem::Version
43
- version: 2.7.0
53
+ version: '2.10'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70316433215720
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.10'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: guard-rspec
49
- requirement: &70316433215300 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70316433215300
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: webmock
60
- requirement: &70316433214840 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,18 +85,28 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70316433214840
69
- - !ruby/object:Gem::Dependency
70
- name: vcr
71
- requirement: &70316433214420 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
72
89
  none: false
73
90
  requirements:
74
91
  - - ! '>='
75
92
  - !ruby/object:Gem::Version
76
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: vcr
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.11'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70316433214420
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.11'
80
110
  description: Get video info from youtube and vimeo url.
81
111
  email:
82
112
  - thibaud@thibaud.me
@@ -102,17 +132,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
132
  - - ! '>='
103
133
  - !ruby/object:Gem::Version
104
134
  version: '0'
135
+ segments:
136
+ - 0
137
+ hash: -2888328597512139102
105
138
  required_rubygems_version: !ruby/object:Gem::Requirement
106
139
  none: false
107
140
  requirements:
108
141
  - - ! '>='
109
142
  - !ruby/object:Gem::Version
110
143
  version: '0'
144
+ segments:
145
+ - 0
146
+ hash: -2888328597512139102
111
147
  requirements: []
112
148
  rubyforge_project: video_info
113
- rubygems_version: 1.8.16
149
+ rubygems_version: 1.8.24
114
150
  signing_key:
115
151
  specification_version: 3
116
152
  summary: Vimeo & Youtube parser
117
153
  test_files: []
118
- has_rdoc: