video_info 1.6.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/Gemfile +1 -1
- data/README.md +11 -11
- data/Rakefile +1 -1
- data/lib/video_info.rb +30 -7
- data/lib/video_info/provider.rb +15 -8
- data/lib/video_info/providers/vimeo.rb +7 -11
- data/lib/video_info/providers/vkontakte.rb +30 -49
- data/lib/video_info/providers/youtube.rb +5 -5
- data/lib/video_info/version.rb +2 -2
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/date/.yml +14 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/description/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/duration/.yml +17 -15
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/height/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/keywords/.yml +17 -15
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/thumbnail_large/.yml +15 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/thumbnail_medium/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/thumbnail_small/.yml +15 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/title/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/view_count/.yml +17 -15
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/width/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/description/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/duration/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/embed_code/.yml +1036 -1348
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/embed_url/.yml +1036 -1348
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/height/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/keywords/.yml +1098 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/title/.yml +1036 -1348
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/view_count/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/width/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/date/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/description/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/duration/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/keywords/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/thumbnail_large/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/thumbnail_medium/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/thumbnail_small/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/title/.yml +16 -15
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/view_count/.yml +14 -13
- data/spec/lib/video_info/provider_spec.rb +29 -9
- data/spec/lib/video_info/providers/vimeo_spec.rb +11 -11
- data/spec/lib/video_info/providers/vkontakte_spec.rb +4 -3
- data/spec/lib/video_info/providers/youtube_spec.rb +19 -19
- data/spec/lib/video_info_spec.rb +23 -23
- data/spec/spec_helper.rb +8 -2
- data/video_info.gemspec +5 -2
- metadata +6 -104
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/embed_code/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/embed_url/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/provider/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/url/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/video_id/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_and_iframe_attributes/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_and_url_attributes/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_/group/_url/provider/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_/group/_url/video_id/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_text/provider/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_text/video_id/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/date/.yml +0 -1410
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/provider/.yml +0 -1410
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/url/.yml +0 -1410
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/video_id/.yml +0 -1410
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/video_owner/.yml +0 -1369
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_arbitrary_iframe_attributes/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_arbitrary_iframe_attributes/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_iframe_attributes/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_iframe_attributes/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_JM9NgvjjVng_in_youtu_be_url/provider/.yml +0 -65
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_JM9NgvjjVng_in_youtu_be_url/video_id/.yml +0 -65
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_after_params/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_after_params/url/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_after_params/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_e_path/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_e_path/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_embed_path/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_embed_path/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_path/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_path/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_user_url/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_user_url/url/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_user_url/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_Xp6CXF-Cesg/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_Xp6CXF-Cesg/video_id/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/embed_code/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/embed_url/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/height/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/url/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/video_id/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/width/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_oQ49W_xKzKA/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_oQ49W_xKzKA/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_oQ49W_xKzKA/video_id/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_url_in_text/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_url_in_text/video_id/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/without_http_or_www/provider/.yml +0 -65
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/without_http_or_www/video_id/.yml +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8574cb4c5ee1da037895282d4afeebaf4266f19b
|
4
|
+
data.tar.gz: 65a5e6e34b10aecc9ee7e95f6ef2aa873493b7f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 338de9b7de8a9cac837dff5cabd23ad9643d63d50275989dc7e0fb3077b4b79bc4dc9fcc95e1bededd1371ade6bbc5d9aaed6cb570aa3cf0d984a0c43bad1f4d
|
7
|
+
data.tar.gz: 91a541df1be27bfe9e2517368bb2255777e9d7cd3f9bcdd02177e8b4f21f42251b031cb192c6b4f047e1790f18c5c16db3e5a33dbcacbcd25f7d48ec1c4d1db6
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
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 YouTube and
|
5
|
+
Simple Ruby Gem to get video info from YouTube, Vimeo and VK url.
|
6
6
|
|
7
|
-
Tested against Ruby 1.
|
7
|
+
Tested against Ruby 1.9.3, 2.0.0 and the latest versions of JRuby & Rubinius.
|
8
8
|
|
9
9
|
Install
|
10
10
|
--------
|
@@ -17,7 +17,7 @@ Usage
|
|
17
17
|
-----
|
18
18
|
|
19
19
|
``` ruby
|
20
|
-
video = VideoInfo.
|
20
|
+
video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
|
21
21
|
# video.video_id => "mZqGqE0D0n4"
|
22
22
|
# video.provider => "YouTube"
|
23
23
|
# video.title => "Cherry Bloom - King Of The Knife"
|
@@ -30,7 +30,7 @@ video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4")
|
|
30
30
|
# video.embed_url => "http://www.youtube.com/embed/mZqGqE0D0n4"
|
31
31
|
# video.embed_code => "'<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"
|
32
32
|
|
33
|
-
video = VideoInfo.
|
33
|
+
video = VideoInfo.new("http://vimeo.com/898029")
|
34
34
|
# video.video_id => "898029"
|
35
35
|
# video.provider => "Vimeo"
|
36
36
|
# video.title => "Cherry Bloom - King Of The Knife"
|
@@ -51,16 +51,16 @@ Options
|
|
51
51
|
-------
|
52
52
|
|
53
53
|
``` ruby
|
54
|
-
video = VideoInfo.
|
55
|
-
video = VideoInfo.
|
56
|
-
video = VideoInfo.
|
54
|
+
video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", "User-Agent" => "My YouTube Mashup Robot/1.0")
|
55
|
+
video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer" => "http://my-youtube-mashup.com/")
|
56
|
+
video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer" => "http://my-youtube-mashup.com/",
|
57
57
|
"User-Agent" => "My YouTube Mashup Robot/1.0")
|
58
58
|
```
|
59
59
|
You can also use **symbols** instead of strings (any non-word (`/[^a-z]/i`) character would be converted to hyphen).
|
60
60
|
|
61
61
|
``` ruby
|
62
|
-
video = VideoInfo.
|
63
|
-
:
|
62
|
+
video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", :referer => "http://my-youtube-mashup.com/",
|
63
|
+
user_agent: "My YouTube Mashup Robot/1.0")
|
64
64
|
```
|
65
65
|
|
66
66
|
User-Agent when empty defaults to "VideoInfo/VERSION" - where version is current VideoInfo version, e.g. **"VideoInfo/0.2.7"**.
|
@@ -70,10 +70,10 @@ It supports all openURI header fields (options), for more information see: [open
|
|
70
70
|
You can also include an `iframe_attributes` or `url_attributes` hash to the `embed_code` method to include arbitrary attributes in the iframe embed code or as additional URL params:
|
71
71
|
|
72
72
|
``` ruby
|
73
|
-
VideoInfo.
|
73
|
+
VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(iframe_attributes: { width: 800, height: 600, "data-key" => "value" })
|
74
74
|
=> '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen" width="800" height="600" data-key="value"></iframe>
|
75
75
|
|
76
|
-
'VideoInfo.
|
76
|
+
'VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(url_attributes: { autoplay: 1 })
|
77
77
|
=> '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4?autoplay=1" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'
|
78
78
|
```
|
79
79
|
|
data/Rakefile
CHANGED
data/lib/video_info.rb
CHANGED
@@ -1,23 +1,46 @@
|
|
1
1
|
require 'video_info/version'
|
2
2
|
require 'video_info/provider'
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
class VideoInfo
|
6
|
+
class UrlError < StandardError; end
|
7
|
+
extend Forwardable
|
3
8
|
|
4
|
-
module VideoInfo
|
5
9
|
PROVIDERS = %w[Vimeo Vkontakte Youtube]
|
6
10
|
PROVIDERS.each { |p| require "video_info/providers/#{p.downcase}" }
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
def_delegators :@provider, :provider, :video_id, :video_owner, :url, :data
|
13
|
+
def_delegators :@provider, :title, :description, :keywords, :view_count
|
14
|
+
def_delegators :@provider, :date, :duration, :width, :height
|
15
|
+
def_delegators :@provider, :thumbnail_small, :thumbnail_medium, :thumbnail_large
|
16
|
+
def_delegators :@provider, :embed_code, :embed_url
|
17
|
+
|
18
|
+
def initialize(url, options = {})
|
19
|
+
@provider = _select_provider(url, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get(*args)
|
23
|
+
new(*args)
|
12
24
|
end
|
13
25
|
|
14
26
|
def self.usable?(url)
|
15
|
-
|
27
|
+
new(url)
|
28
|
+
true
|
29
|
+
rescue UrlError
|
30
|
+
false
|
16
31
|
end
|
17
32
|
|
18
33
|
private
|
19
34
|
|
20
|
-
def
|
35
|
+
def _select_provider(url, options)
|
36
|
+
if provider_const = _providers_const.detect { |p| p.usable?(url) }
|
37
|
+
provider_const.new(url, options)
|
38
|
+
else
|
39
|
+
raise UrlError, "Url is not usable by any Providers: #{url}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def _providers_const
|
21
44
|
PROVIDERS.map { |p| Providers.const_get(p) }
|
22
45
|
end
|
23
46
|
end
|
data/lib/video_info/provider.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require 'addressable/uri'
|
2
2
|
|
3
|
-
|
3
|
+
class VideoInfo
|
4
4
|
class Provider
|
5
|
-
attr_accessor :url, :options, :iframe_attributes, :video_id, :
|
5
|
+
attr_accessor :url, :options, :iframe_attributes, :video_id, :data
|
6
6
|
|
7
7
|
def initialize(url, options = {})
|
8
8
|
@options = _clean_options(options)
|
9
9
|
@url = url
|
10
10
|
_set_video_id_from_url
|
11
|
-
_set_info_from_api if _valid_video_id?
|
12
11
|
end
|
13
12
|
|
14
13
|
def self.usable?(url)
|
@@ -23,6 +22,10 @@ module VideoInfo
|
|
23
22
|
"<iframe #{iframe_attrs.reject(&:empty?).join(" ")}></iframe>"
|
24
23
|
end
|
25
24
|
|
25
|
+
def data
|
26
|
+
@data ||= _set_data_from_api
|
27
|
+
end
|
28
|
+
|
26
29
|
private
|
27
30
|
|
28
31
|
def _clean_options(options)
|
@@ -36,9 +39,9 @@ module VideoInfo
|
|
36
39
|
options
|
37
40
|
end
|
38
41
|
|
39
|
-
def
|
42
|
+
def _set_data_from_api
|
40
43
|
uri = open(_api_url, options)
|
41
|
-
|
44
|
+
MultiJson.load(uri.read)
|
42
45
|
end
|
43
46
|
|
44
47
|
def _not_openuri_option_symbol?(key)
|
@@ -50,7 +53,10 @@ module VideoInfo
|
|
50
53
|
end
|
51
54
|
|
52
55
|
def _set_video_id_from_url
|
53
|
-
url.gsub(_url_regex) { @video_id = $1 || $2 || $3 }
|
56
|
+
@url.gsub(_url_regex) { @video_id = $1 || $2 || $3 }
|
57
|
+
unless _valid_video_id?
|
58
|
+
raise UrlError, "Url is not valid, video_id is not found: #{url}"
|
59
|
+
end
|
54
60
|
end
|
55
61
|
|
56
62
|
def _valid_video_id?
|
@@ -66,10 +72,11 @@ module VideoInfo
|
|
66
72
|
end
|
67
73
|
|
68
74
|
def _embed_url(options)
|
75
|
+
url_scheme = options.fetch(:url_scheme, 'http')
|
69
76
|
url_attrs = options.fetch(:url_attributes, {})
|
70
77
|
url_attrs = _default_url_attributes.merge(url_attrs)
|
71
78
|
|
72
|
-
url = embed_url
|
79
|
+
url = "#{url_scheme}://#{embed_url}"
|
73
80
|
url += "?#{_hash_to_params(url_attrs)}" unless url_attrs.empty?
|
74
81
|
url
|
75
82
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'multi_json'
|
3
3
|
|
4
|
-
|
4
|
+
class VideoInfo
|
5
5
|
module Providers
|
6
6
|
class Vimeo < Provider
|
7
7
|
|
@@ -13,10 +13,6 @@ module VideoInfo
|
|
13
13
|
'Vimeo'
|
14
14
|
end
|
15
15
|
|
16
|
-
def url
|
17
|
-
video ? video['url'] : @url
|
18
|
-
end
|
19
|
-
|
20
16
|
%w[title description thumbnail_small thumbnail_medium thumbnail_large].each do |method|
|
21
17
|
define_method(method) { video[method] }
|
22
18
|
end
|
@@ -30,7 +26,7 @@ module VideoInfo
|
|
30
26
|
end
|
31
27
|
|
32
28
|
def embed_url
|
33
|
-
"
|
29
|
+
"player.vimeo.com/video/#{video_id}"
|
34
30
|
end
|
35
31
|
|
36
32
|
def date
|
@@ -42,7 +38,7 @@ module VideoInfo
|
|
42
38
|
end
|
43
39
|
|
44
40
|
def video
|
45
|
-
|
41
|
+
data && data.first
|
46
42
|
end
|
47
43
|
|
48
44
|
private
|
@@ -60,10 +56,10 @@ module VideoInfo
|
|
60
56
|
end
|
61
57
|
|
62
58
|
def _default_url_attributes
|
63
|
-
{ :
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
59
|
+
{ title: 0,
|
60
|
+
byline: 0,
|
61
|
+
portrait: 0,
|
62
|
+
autoplay: 0 }
|
67
63
|
end
|
68
64
|
|
69
65
|
end
|
@@ -8,7 +8,7 @@ if RUBY_VERSION.to_i < 2
|
|
8
8
|
require 'iconv'
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
class VideoInfo
|
12
12
|
module Providers
|
13
13
|
class Vkontakte < Provider
|
14
14
|
attr_accessor :video_owner
|
@@ -21,72 +21,53 @@ module VideoInfo
|
|
21
21
|
'Vkontakte'
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
def description
|
25
|
+
content = data[/<meta name="description" content="(.*)" \/>/,1]
|
26
|
+
HTMLEntities.new.decode(content)
|
26
27
|
end
|
28
|
+
alias_method :keywords, :description
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def embed_url
|
37
|
-
"http://vk.com/video_ext.php?oid=#{video_owner}&id=#{video_id}&hash=#{video[:hash]}"
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def _parse_hash
|
43
|
-
@html[/hash2\\":\\"(\w+)/,1]
|
30
|
+
def width
|
31
|
+
{ 240 => 320,
|
32
|
+
360 => 480,
|
33
|
+
480 => 640,
|
34
|
+
720 => 1280
|
35
|
+
}[height]
|
44
36
|
end
|
45
37
|
|
46
|
-
def
|
47
|
-
|
38
|
+
def height
|
39
|
+
data[/url(\d+)/,1].to_i
|
48
40
|
end
|
49
41
|
|
50
|
-
def
|
51
|
-
|
42
|
+
def title
|
43
|
+
data[/<title>(.*)<\/title>/,1].gsub(" | ВКонтакте", "")
|
52
44
|
end
|
53
45
|
|
54
|
-
def
|
55
|
-
|
46
|
+
def view_count
|
47
|
+
data[/mv_num_views\\">(\d+)/,1].to_i
|
56
48
|
end
|
57
49
|
|
58
|
-
def
|
59
|
-
|
50
|
+
def embed_url
|
51
|
+
"vk.com/video_ext.php?oid=#{video_owner}&id=#{video_id}&hash=#{_data_hash}"
|
60
52
|
end
|
61
53
|
|
62
|
-
def
|
63
|
-
|
64
|
-
360 => 480,
|
65
|
-
480 => 640,
|
66
|
-
720 => 1280
|
67
|
-
}[height]
|
54
|
+
def duration
|
55
|
+
data[/"duration":(\d+)/,1].to_i
|
68
56
|
end
|
69
57
|
|
70
|
-
|
71
|
-
@html[/<meta name="description" content="(.*)" \/>/,1]
|
72
|
-
end
|
58
|
+
private
|
73
59
|
|
74
|
-
def
|
60
|
+
def _set_data_from_api
|
75
61
|
uri = open(_api_url, options)
|
76
62
|
if RUBY_VERSION.to_i < 2
|
77
|
-
|
63
|
+
Iconv.iconv('utf-8', 'cp1251', uri.read)[0]
|
78
64
|
else
|
79
|
-
|
65
|
+
uri.read.encode("UTF-8")
|
80
66
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
:duration => _parse_duration,
|
86
|
-
:width => _get_width(_parse_height),
|
87
|
-
:height => _parse_height,
|
88
|
-
:description => _parse_description
|
89
|
-
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def _data_hash
|
70
|
+
data[/hash2\\":\\"(\w+)/,1]
|
90
71
|
end
|
91
72
|
|
92
73
|
def _set_video_id_from_url
|
@@ -102,7 +83,7 @@ module VideoInfo
|
|
102
83
|
end
|
103
84
|
|
104
85
|
def _default_iframe_attributes
|
105
|
-
{ :
|
86
|
+
{ allowfullscreen: "allowfullscreen" }
|
106
87
|
end
|
107
88
|
|
108
89
|
def _default_url_attributes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'multi_json'
|
3
3
|
|
4
|
-
|
4
|
+
class VideoInfo
|
5
5
|
module Providers
|
6
6
|
class Youtube < Provider
|
7
7
|
|
@@ -30,7 +30,7 @@ module VideoInfo
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def embed_url
|
33
|
-
"
|
33
|
+
"www.youtube.com/embed/#{video_id}"
|
34
34
|
end
|
35
35
|
|
36
36
|
def date
|
@@ -64,7 +64,7 @@ module VideoInfo
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def _default_iframe_attributes
|
67
|
-
{ :
|
67
|
+
{ allowfullscreen: "allowfullscreen" }
|
68
68
|
end
|
69
69
|
|
70
70
|
def _default_url_attributes
|
@@ -72,11 +72,11 @@ module VideoInfo
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def _video_entry
|
75
|
-
|
75
|
+
data['entry']
|
76
76
|
end
|
77
77
|
|
78
78
|
def _video_media_group
|
79
|
-
|
79
|
+
data['entry']['media$group']
|
80
80
|
end
|
81
81
|
|
82
82
|
def _video_thumbnail(id)
|
data/lib/video_info/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = '
|
1
|
+
class VideoInfo
|
2
|
+
VERSION = '2.0.0'
|
3
3
|
end
|
@@ -8,7 +8,7 @@ http_interactions:
|
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
10
|
User-Agent:
|
11
|
-
- VideoInfo/1.
|
11
|
+
- VideoInfo/1.6.0
|
12
12
|
Accept-Encoding:
|
13
13
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
14
|
Accept:
|
@@ -23,15 +23,15 @@ http_interactions:
|
|
23
23
|
X-Ratelimit-Limit:
|
24
24
|
- '3600'
|
25
25
|
X-Ratelimit-Remaining:
|
26
|
-
- '
|
26
|
+
- '3599'
|
27
27
|
X-Ratelimit-Reset:
|
28
|
-
- '
|
28
|
+
- '1382701011'
|
29
29
|
Expires:
|
30
|
-
-
|
30
|
+
- Fri, 25 Oct 2013 10:37:52 GMT
|
31
31
|
Last-Modified:
|
32
|
-
-
|
32
|
+
- Sun, 20 Oct 2013 01:45:34 GMT
|
33
33
|
Etag:
|
34
|
-
- '"
|
34
|
+
- '"c632ac4e6ac3e1fcd30be3046eb936b0"'
|
35
35
|
X-Dns-Prefetch-Control:
|
36
36
|
- 'on'
|
37
37
|
Vary:
|
@@ -39,15 +39,15 @@ http_interactions:
|
|
39
39
|
Content-Type:
|
40
40
|
- application/json
|
41
41
|
Content-Length:
|
42
|
-
- '
|
42
|
+
- '498'
|
43
43
|
Accept-Ranges:
|
44
44
|
- bytes
|
45
45
|
Date:
|
46
|
-
-
|
46
|
+
- Fri, 25 Oct 2013 10:36:53 GMT
|
47
47
|
X-Varnish:
|
48
|
-
-
|
48
|
+
- 1698943940 1698943341
|
49
49
|
Age:
|
50
|
-
- '
|
50
|
+
- '2'
|
51
51
|
Via:
|
52
52
|
- 1.1 varnish
|
53
53
|
X-Varnish-Cache:
|
@@ -55,15 +55,15 @@ http_interactions:
|
|
55
55
|
Connection:
|
56
56
|
- close
|
57
57
|
X-Vserver:
|
58
|
-
- 10.90.128.
|
58
|
+
- 10.90.128.197
|
59
59
|
body:
|
60
60
|
encoding: UTF-8
|
61
61
|
string: '[{"id":898029,"title":"Cherry Bloom - King Of The Knife","description":"The
|
62
62
|
first video from the upcoming album Secret Sounds, to download in-stores April
|
63
63
|
14. Checkout http:\/\/www.cherrybloom.net","url":"http:\/\/vimeo.com\/898029","upload_date":"2008-04-14
|
64
64
|
13:10:39","thumbnail_small":"http:\/\/b.vimeocdn.com\/ts\/343\/731\/34373130_100.jpg","thumbnail_medium":"http:\/\/b.vimeocdn.com\/ts\/343\/731\/34373130_200.jpg","thumbnail_large":"http:\/\/b.vimeocdn.com\/ts\/343\/731\/34373130_640.jpg","user_id":206215,"user_name":"Octave
|
65
|
-
Zangs","user_url":"http:\/\/vimeo.com\/octave","user_portrait_small":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_30.jpg","user_portrait_medium":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_75.jpg","user_portrait_large":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_100.jpg","user_portrait_huge":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_300.jpg","stats_number_of_likes":11,"stats_number_of_plays":
|
65
|
+
Zangs","user_url":"http:\/\/vimeo.com\/octave","user_portrait_small":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_30.jpg","user_portrait_medium":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_75.jpg","user_portrait_large":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_100.jpg","user_portrait_huge":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_300.jpg","stats_number_of_likes":11,"stats_number_of_plays":4557,"stats_number_of_comments":4,"duration":175,"width":640,"height":360,"tags":"cherry
|
66
66
|
bloom, secret sounds, king of the knife, rock, alternative","embed_privacy":"anywhere"}]'
|
67
67
|
http_version:
|
68
|
-
recorded_at:
|
69
|
-
recorded_with: VCR 2.
|
68
|
+
recorded_at: Fri, 25 Oct 2013 10:36:53 GMT
|
69
|
+
recorded_with: VCR 2.6.0
|