video_info 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -2
  3. data/lib/video_info.rb +1 -1
  4. data/lib/video_info/providers/vimeo.rb +9 -9
  5. data/lib/video_info/providers/vimeoplaylist.rb +64 -0
  6. data/lib/video_info/version.rb +1 -1
  7. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/_available_/with_invalid_playlist/available_/.yml +152 -0
  8. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/_available_/with_valid_playlist/available_/.yml +105 -0
  9. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/date/.yml +75 -0
  10. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/description/.yml +164 -0
  11. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/duration/.yml +75 -0
  12. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/height/.yml +71 -0
  13. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/keywords/.yml +75 -0
  14. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/thumbnail_large/.yml +168 -0
  15. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/thumbnail_medium/.yml +164 -0
  16. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/thumbnail_small/.yml +168 -0
  17. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/title/.yml +166 -0
  18. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/videos/.yml +202 -0
  19. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/view_count/.yml +71 -0
  20. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_2755718/width/.yml +71 -0
  21. data/spec/lib/video_info/providers/vimeo_playlist_spec.rb +78 -0
  22. data/spec/lib/video_info/providers/vimeo_spec.rb +10 -0
  23. metadata +33 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ddcd66b117bba40d3caaabd137a7f9fa2abb3eb
4
- data.tar.gz: fc14527e675c4815cc266fa5220b34dbbde8310d
3
+ metadata.gz: 2fd291c67498dd89547251a472b9e458f7ac3277
4
+ data.tar.gz: 6a4bab53f9e27cdac0dccca1df65f7be4a9823c8
5
5
  SHA512:
6
- metadata.gz: 0931fcb59e451f781bbe58d30a0b590f8bd4c673968b361d0023dc2696e911d1aa5bd586f0e2032f9a9f54e7d09620e752addd8dcd7c94bb32fd8cd186fdb6d8
7
- data.tar.gz: 504a3ea41e0b4ad6f084cb642bec105406cb0d0197d6ccb10337536e473b934dd99ecb26e8b9b0ff9c246158626c5375b497fc3f8152d8e99cfd70ccc25b364a
6
+ metadata.gz: eb12467cb8f6244bc9ff5a968ac3f844a10944412d30bb00e4ba10410019f2d8a276cfa6b96098cb244f350d77fa00fb73af9fc66f146f2f66010ec6397c8a62
7
+ data.tar.gz: d3a72a5fd3b05cd20a13d8e16345635a9ab3f8390ed51b6dada347d92363bab66712907c851a62b6b2f1ebc14c1ad92c6b83b43bb8b87e063b789afa451b6de7
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/video_info.png)](http://badge.fury.io/rb/video_info) [![Build Status](https://travis-ci.org/thibaudgg/video_info.png?branch=master)](https://travis-ci.org/thibaudgg/video_info) [![Dependency Status](https://gemnasium.com/thibaudgg/video_info.png)](https://gemnasium.com/thibaudgg/video_info) [![Code Climate](https://codeclimate.com/github/thibaudgg/video_info.png)](https://codeclimate.com/github/thibaudgg/video_info) [![Coverage Status](https://coveralls.io/repos/thibaudgg/video_info/badge.png?branch=master)](https://coveralls.io/r/thibaudgg/video_info)
4
4
 
5
- Simple Ruby Gem to get video info from Dailymotion, Vimeo, VK and YouTube (with playlist support).
5
+ Simple Ruby Gem to get video info from Dailymotion, Vimeo (with playlist support), VK and YouTube (with playlist support).
6
6
 
7
7
  Tested against Ruby 1.9.3, 2.0.0, 2.1.0 and the latest versions of JRuby & Rubinius.
8
8
 
@@ -71,8 +71,20 @@ playlist = VideoInfo.new("http://www.youtube.com/playlist?p=PL9hW1uS6HUftLdHI6RI
71
71
  # playlist.thumbnail_medium => "http://i.ytimg.com/vi/8b0aEoxqqC0/mqdefault.jpg"
72
72
  # playlist.thumbnail_large => "http://i.ytimg.com/vi/8b0aEoxqqC0/hqdefault.jpg"
73
73
  # playlist.embed_url => "http://www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr"
74
- # playlist.embed_code => "'<iframe src="http://www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"
74
+ # playlist.embed_code => "<iframe src="http://www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr" frameborder="0" allowfullscreen="allowfullscreen"></iframe>"
75
75
  # playlist.videos => [VideoInfo.new('http://www.youtube.com/watch?v=_Bt3-WsHfB0'), VideoInfo.new('http://www.youtube.com/watch?v=9g2U12SsRns'), VideoInfo.new('http://www.youtube.com/watch?v=8b0aEoxqqC0'), VideoInfo.new('http://www.youtube.com/watch?v=6c3mHikRz0I'), VideoInfo.new('http://www.youtube.com/watch?v=OQVHWsTHcoc')]
76
+
77
+ playlist = VideoInfo.new("http://vimeo.com/album/2755718")
78
+ # playlist.available? => true
79
+ # playlist.playlist_id => "2755718"
80
+ # playlist.provider => "Vimeo"
81
+ # playlist.title => "The Century Of Self"
82
+ # playlist.thumbnail_small => "http://b.vimeocdn.com/ts/443/595/443595474_100.jpg"
83
+ # playlist.thumbnail_medium => "http://b.vimeocdn.com/ts/443/595/443595474_200.jpg"
84
+ # playlist.thumbnail_large => "http://b.vimeocdn.com/ts/443/595/443595474_640.jpg"
85
+ # playlist.embed_url => "player.vimeo.com/hubnut/album/2755718"
86
+ # playlist.embed_code => "<iframe src="http://player.vimeo.com/hubnut/album/2755718?autoplay=0&byline=0&portrait=0&title=0" frameborder="0"></iframe>"
87
+ # playlist.videos => [VideoInfo.new('http://vimeo.com/67977038'), VideoInfo.new('http://vimeo.com/68843810'), VideoInfo.new('http://vimeo.com/69949597'), VideoInfo.new('http://vimeo.com/70388245')]
76
88
  ```
77
89
 
78
90
  Options
data/lib/video_info.rb CHANGED
@@ -7,7 +7,7 @@ class VideoInfo
7
7
  class UrlError < StandardError; end
8
8
  extend Forwardable
9
9
 
10
- PROVIDERS = %w[Vimeo Vkontakte Youtube YoutubePlaylist Dailymotion]
10
+ PROVIDERS = %w[Vimeo VimeoPlaylist Vkontakte Youtube YoutubePlaylist Dailymotion]
11
11
  PROVIDERS.each { |p| require "video_info/providers/#{p.downcase}" }
12
12
 
13
13
  def_delegators :@provider, :provider, :video_id, :video_owner, :url, :data
@@ -3,7 +3,7 @@ class VideoInfo
3
3
  class Vimeo < Provider
4
4
 
5
5
  def self.usable?(url)
6
- url =~ /vimeo\.com/
6
+ url =~ /(vimeo\.com\/(?!album|hubnut\/album).*)/
7
7
  end
8
8
 
9
9
  def provider
@@ -11,15 +11,15 @@ class VideoInfo
11
11
  end
12
12
 
13
13
  %w[title description thumbnail_small thumbnail_medium thumbnail_large].each do |method|
14
- define_method(method) { video[method] }
14
+ define_method(method) { _video[method] }
15
15
  end
16
16
 
17
17
  %w[duration width height].each do |method|
18
- define_method(method) { video[method].to_i }
18
+ define_method(method) { _video[method].to_i }
19
19
  end
20
20
 
21
21
  def keywords
22
- video['tags']
22
+ _video['tags']
23
23
  end
24
24
 
25
25
  def embed_url
@@ -27,19 +27,19 @@ class VideoInfo
27
27
  end
28
28
 
29
29
  def date
30
- Time.parse(video['upload_date'], Time.now.utc).utc
30
+ Time.parse(_video['upload_date'], Time.now.utc).utc
31
31
  end
32
32
 
33
33
  def view_count
34
- video['stats_number_of_plays'].to_i
34
+ _video['stats_number_of_plays'].to_i
35
35
  end
36
36
 
37
- def video
37
+ private
38
+
39
+ def _video
38
40
  data && data.first
39
41
  end
40
42
 
41
- private
42
-
43
43
  def _url_regex
44
44
  /.*\.com\/(?:(?:groups\/[^\/]+\/videos\/)|(?:video\/))?([0-9]+).*$/i
45
45
  end
@@ -0,0 +1,64 @@
1
+ class VideoInfo
2
+ module Providers
3
+ class VimeoPlaylist < Vimeo
4
+
5
+ alias_method :playlist_id, :video_id
6
+
7
+ def self.usable?(url)
8
+ url =~ /((vimeo\.com)\/album)|((vimeo\.com)\/hubnut\/album)/
9
+ end
10
+
11
+ def videos
12
+ _playlist_video_ids.map do |entry_id|
13
+ VideoInfo.new("http://vimeo.com/#{entry_id}")
14
+ end
15
+ end
16
+
17
+ def embed_url
18
+ "player.vimeo.com/hubnut/album/#{playlist_id}"
19
+ end
20
+
21
+ %w[width height date keywords duration view_count].each do |method|
22
+ define_method(method) { nil }
23
+ end
24
+
25
+ private
26
+
27
+ def _video
28
+ data
29
+ end
30
+
31
+ def _url_regex
32
+ /vimeo.com\/album\/([0-9]*)|vimeo.com\/hubnut\/album\/([0-9]*)/
33
+ end
34
+
35
+ def _api_path
36
+ "/api/v2/album/#{video_id}/info.json"
37
+ end
38
+
39
+ def _api_videos_path
40
+ "/api/v2/album/#{video_id}/videos.json"
41
+ end
42
+
43
+ def _api_videos_url
44
+ "http://#{_api_base}#{_api_videos_path}"
45
+ end
46
+
47
+ def _data_videos
48
+ @data_videos ||= _set_videos_from_api
49
+ end
50
+
51
+ def _set_videos_from_api
52
+ uri = open(_api_videos_url, options)
53
+ MultiJson.load(uri.read)
54
+ end
55
+
56
+ def _playlist_video_ids
57
+ _data_videos.map do |entry|
58
+ entry['id']
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -1,3 +1,3 @@
1
1
  class VideoInfo
2
- VERSION = '2.2.2'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -0,0 +1,152 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: head
5
+ uri: http://vimeo.com/api/v2/video/2755718.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Fri, 28 Feb 2014 23:49:05 GMT
21
+ Server:
22
+ - Apache
23
+ Access-Control-Allow-Origin:
24
+ - '*'
25
+ X-Ratelimit-Limit:
26
+ - '3600'
27
+ X-Ratelimit-Remaining:
28
+ - '3595'
29
+ X-Ratelimit-Reset:
30
+ - '1393634120'
31
+ Cache-Control:
32
+ - max-age=60
33
+ Expires:
34
+ - Fri, 28 Feb 2014 23:50:05 GMT
35
+ Last-Modified:
36
+ - Fri, 21 Feb 2014 06:05:40 GMT
37
+ Etag:
38
+ - '"0ad6ab03cab8ef64f7f7261e3c1b374c"'
39
+ X-Ua-Compatible:
40
+ - IE=edge
41
+ X-Dns-Prefetch-Control:
42
+ - 'on'
43
+ Vary:
44
+ - Accept-Encoding
45
+ Cneonction:
46
+ - close
47
+ Content-Type:
48
+ - application/json
49
+ body:
50
+ encoding: UTF-8
51
+ string: ''
52
+ http_version:
53
+ recorded_at: Fri, 28 Feb 2014 23:49:07 GMT
54
+ - request:
55
+ method: head
56
+ uri: http://vimeo.com/api/v2/album/2755718/info.json
57
+ body:
58
+ encoding: US-ASCII
59
+ string: ''
60
+ headers:
61
+ Accept:
62
+ - '*/*'
63
+ User-Agent:
64
+ - Ruby
65
+ response:
66
+ status:
67
+ code: 200
68
+ message: OK
69
+ headers:
70
+ Date:
71
+ - Fri, 28 Feb 2014 23:53:57 GMT
72
+ Server:
73
+ - Apache
74
+ Access-Control-Allow-Origin:
75
+ - '*'
76
+ X-Ratelimit-Limit:
77
+ - '3600'
78
+ X-Ratelimit-Remaining:
79
+ - '3593'
80
+ X-Ratelimit-Reset:
81
+ - '1393634120'
82
+ Cache-Control:
83
+ - max-age=60
84
+ Expires:
85
+ - Fri, 28 Feb 2014 23:54:57 GMT
86
+ Last-Modified:
87
+ - Fri, 28 Feb 2014 23:19:45 GMT
88
+ Etag:
89
+ - '"066770d7b5e5c4a8ac2e5d2178671420"'
90
+ X-Ua-Compatible:
91
+ - IE=edge
92
+ X-Dns-Prefetch-Control:
93
+ - 'on'
94
+ Vary:
95
+ - Accept-Encoding
96
+ Cneonction:
97
+ - close
98
+ Content-Type:
99
+ - application/json
100
+ body:
101
+ encoding: UTF-8
102
+ string: ''
103
+ http_version:
104
+ recorded_at: Fri, 28 Feb 2014 23:53:59 GMT
105
+ - request:
106
+ method: head
107
+ uri: http://vimeo.com/api/v2/album/2/info.json
108
+ body:
109
+ encoding: US-ASCII
110
+ string: ''
111
+ headers:
112
+ Accept:
113
+ - '*/*'
114
+ User-Agent:
115
+ - Ruby
116
+ response:
117
+ status:
118
+ code: 404
119
+ message: Not Found
120
+ headers:
121
+ Date:
122
+ - Fri, 28 Feb 2014 23:56:09 GMT
123
+ Server:
124
+ - Apache
125
+ Access-Control-Allow-Origin:
126
+ - '*'
127
+ X-Ratelimit-Limit:
128
+ - '3600'
129
+ X-Ratelimit-Remaining:
130
+ - '3592'
131
+ X-Ratelimit-Reset:
132
+ - '1393634120'
133
+ Cache-Control:
134
+ - max-age=300, must-revalidate
135
+ Expires:
136
+ - Sat, 01 Mar 2014 00:01:09 GMT
137
+ X-Ua-Compatible:
138
+ - IE=edge
139
+ X-Dns-Prefetch-Control:
140
+ - 'on'
141
+ Vary:
142
+ - Accept-Encoding
143
+ Nncoection:
144
+ - close
145
+ Content-Type:
146
+ - text/html; charset=UTF-8
147
+ body:
148
+ encoding: UTF-8
149
+ string: ''
150
+ http_version:
151
+ recorded_at: Fri, 28 Feb 2014 23:56:11 GMT
152
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,105 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: head
5
+ uri: http://vimeo.com/api/v2/video/2755718.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Fri, 28 Feb 2014 23:49:05 GMT
21
+ Server:
22
+ - Apache
23
+ Access-Control-Allow-Origin:
24
+ - '*'
25
+ X-Ratelimit-Limit:
26
+ - '3600'
27
+ X-Ratelimit-Remaining:
28
+ - '3596'
29
+ X-Ratelimit-Reset:
30
+ - '1393634120'
31
+ Cache-Control:
32
+ - max-age=60
33
+ Expires:
34
+ - Fri, 28 Feb 2014 23:50:05 GMT
35
+ Last-Modified:
36
+ - Fri, 21 Feb 2014 06:05:40 GMT
37
+ Etag:
38
+ - '"0ad6ab03cab8ef64f7f7261e3c1b374c"'
39
+ X-Ua-Compatible:
40
+ - IE=edge
41
+ X-Dns-Prefetch-Control:
42
+ - 'on'
43
+ Vary:
44
+ - Accept-Encoding
45
+ Cneonction:
46
+ - close
47
+ Content-Type:
48
+ - application/json
49
+ body:
50
+ encoding: UTF-8
51
+ string: ''
52
+ http_version:
53
+ recorded_at: Fri, 28 Feb 2014 23:49:07 GMT
54
+ - request:
55
+ method: head
56
+ uri: http://vimeo.com/api/v2/album/2755718/info.json
57
+ body:
58
+ encoding: US-ASCII
59
+ string: ''
60
+ headers:
61
+ Accept:
62
+ - '*/*'
63
+ User-Agent:
64
+ - Ruby
65
+ response:
66
+ status:
67
+ code: 200
68
+ message: OK
69
+ headers:
70
+ Date:
71
+ - Fri, 28 Feb 2014 23:53:56 GMT
72
+ Server:
73
+ - Apache
74
+ Access-Control-Allow-Origin:
75
+ - '*'
76
+ X-Ratelimit-Limit:
77
+ - '3600'
78
+ X-Ratelimit-Remaining:
79
+ - '3594'
80
+ X-Ratelimit-Reset:
81
+ - '1393634120'
82
+ Cache-Control:
83
+ - max-age=60
84
+ Expires:
85
+ - Fri, 28 Feb 2014 23:54:56 GMT
86
+ Last-Modified:
87
+ - Fri, 28 Feb 2014 23:19:45 GMT
88
+ Etag:
89
+ - '"066770d7b5e5c4a8ac2e5d2178671420"'
90
+ X-Ua-Compatible:
91
+ - IE=edge
92
+ X-Dns-Prefetch-Control:
93
+ - 'on'
94
+ Vary:
95
+ - Accept-Encoding
96
+ Cneonction:
97
+ - close
98
+ Content-Type:
99
+ - application/json
100
+ body:
101
+ encoding: UTF-8
102
+ string: ''
103
+ http_version:
104
+ recorded_at: Fri, 28 Feb 2014 23:53:59 GMT
105
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,75 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://vimeo.com/api/v2/album/2755718/info.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - VideoInfo/2.2.2
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Age:
22
+ - '2'
23
+ Date:
24
+ - Sat, 01 Mar 2014 00:10:32 GMT
25
+ Expires:
26
+ - Sat, 01 Mar 2014 00:11:32 GMT
27
+ Connection:
28
+ - Keep-Alive
29
+ Via:
30
+ - 1.1 varnish
31
+ - dnet-dca
32
+ Etag:
33
+ - '"f9075c16b5f1158ce5ea0e7c4f82dad0"'
34
+ Server:
35
+ - Apache
36
+ Access-Control-Allow-Origin:
37
+ - '*'
38
+ X-Ratelimit-Limit:
39
+ - '3600'
40
+ X-Ratelimit-Remaining:
41
+ - '3597'
42
+ X-Ratelimit-Reset:
43
+ - '1393634121'
44
+ Last-Modified:
45
+ - Sat, 01 Mar 2014 00:07:48 GMT
46
+ X-Ua-Compatible:
47
+ - IE=edge
48
+ X-Dns-Prefetch-Control:
49
+ - 'on'
50
+ Vary:
51
+ - Accept-Encoding
52
+ Content-Type:
53
+ - application/json
54
+ Content-Length:
55
+ - '349'
56
+ Accept-Ranges:
57
+ - bytes
58
+ X-Varnish:
59
+ - '1775345710'
60
+ X-Varnish-Cache:
61
+ - '0'
62
+ Nncoection:
63
+ - close
64
+ X-Vserver:
65
+ - 10.90.128.196
66
+ body:
67
+ encoding: UTF-8
68
+ string: '{"id":2755718,"created_on":"2014-02-28 18:18:21","last_modified":"2014-02-28
69
+ 19:07:48","title":"The Century Of Self","description":"The Century of the
70
+ Self is an award-winning British television documentary series by Adam Curtis,
71
+ released in 2002.","url":"http:\/\/vimeo.com\/album\/2755718","thumbnail_small":"http:\/\/b.vimeocdn.com\/ts\/443\/595\/443595474_100.jpg","thumbnail_medium":"http:\/\/b.vimeocdn.com\/ts\/443\/595\/443595474_200.jpg","thumbnail_large":"http:\/\/b.vimeocdn.com\/ts\/443\/595\/443595474_640.jpg","total_videos":4,"user_id":2618747,"user_display_name":"Karl
72
+ Entwistle","user_url":"http:\/\/vimeo.com\/user2618747"}'
73
+ http_version:
74
+ recorded_at: Sat, 01 Mar 2014 00:10:35 GMT
75
+ recorded_with: VCR 2.8.0