video_info 2.3.3 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/video_info.rb +5 -1
- data/lib/video_info/provider.rb +16 -10
- data/lib/video_info/providers/dailymotion.rb +2 -4
- data/lib/video_info/providers/vimeo.rb +1 -3
- data/lib/video_info/providers/vimeoplaylist.rb +0 -2
- data/lib/video_info/providers/vkontakte.rb +10 -13
- data/lib/video_info/providers/wistia.rb +63 -0
- data/lib/video_info/providers/youtube.rb +6 -4
- data/lib/video_info/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/_available_/with_This_video_does_not_exist_or_has_been_deleted_/_available_/.yml +11 -7
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/_available_/with_valid_video/_available_/.yml +9 -5
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_date/.yml +12 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_description/.yml +12 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_duration/.yml +12 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_keywords/.yml +12 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail_large/.yml +12 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail_medium/.yml +12 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail_small/.yml +12 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_title/.yml +12 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_view_count/.yml +12 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_password_required_video/_available_/.yml +5 -5
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_this_video_does_not_exist_video/_available_/.yml +4 -4
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_valid_video/_available_/.yml +6 -6
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_date/.yml +10 -10
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_description/.yml +11 -11
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_duration/.yml +10 -10
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_height/.yml +13 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_keywords/.yml +12 -12
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_thumbnail_large/.yml +10 -10
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_thumbnail_medium/.yml +10 -10
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_thumbnail_small/.yml +13 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_title/.yml +10 -10
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_view_count/.yml +12 -12
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_width/.yml +12 -12
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/_available_/with_invalid_playlist/_available_/.yml +4 -4
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/_available_/with_valid_playlist/_available_/.yml +4 -4
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_description/.yml +8 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_thumbnail_large/.yml +9 -9
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_thumbnail_medium/.yml +9 -9
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_thumbnail_small/.yml +8 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_title/.yml +8 -8
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_videos/.yml +27 -27
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/_available_/with_invalid_video/_available_/.yml +3 -3
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/_available_/with_valid_video/_available_/.yml +1084 -1058
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video-54799401_165822734/_title/.yml +1383 -1272
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/_description/.yml +1085 -1059
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/_duration/.yml +1085 -1059
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/_embed_code/.yml +1084 -1058
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/_embed_url/.yml +1085 -1059
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/_height/.yml +1085 -1059
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/_keywords/.yml +1085 -1059
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/_title/.yml +1085 -1059
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/_view_count/.yml +1085 -1059
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/_width/.yml +1084 -1058
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/_available_/with_invalid_video/_available_/.yml +65 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/_available_/with_valid_video/_available_/.yml +67 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_duration/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_height/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_thumbnail_large/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_thumbnail_medium/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_thumbnail_small/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_title/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_width/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_duration/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_height/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail_large/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail_medium/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail_small/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_title/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_width/.yml +73 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_valid_video/_available_/.yml +4 -4
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_video_is_unavailable_video/_available_/.yml +4 -4
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_video_no_longer_available_due_to_a_copyright_claim_video/_available_/.yml +4 -4
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_date/.yml +6 -6
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_description/.yml +6 -6
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_duration/.yml +6 -6
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_keywords/.yml +6 -6
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_thumbnail_large/.yml +6 -6
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_thumbnail_medium/.yml +6 -6
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_thumbnail_small/.yml +6 -6
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_title/.yml +11 -9
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_view_count/.yml +6 -6
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/_available_/with_invalid_playlist/_available_/.yml +4 -4
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/_available_/with_valid_playlist/_available_/.yml +5 -5
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL0E8117603D70E10A_in_embed_path/_videos/.yml +5 -5
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_description/.yml +10 -10
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_large/.yml +13 -15
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_medium/.yml +10 -10
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_small/.yml +10 -10
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_title/.yml +10 -10
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_videos/.yml +11 -11
- data/spec/lib/video_info/providers/wistia_spec.rb +168 -0
- data/video_info.gemspec +1 -1
- metadata +37 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f40dace9501dc0754efd519f98cf23d6eb037281
|
4
|
+
data.tar.gz: d486727f7fc75c2246d80686d9ccf44c1f8aa15b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faad587f1bfea1c7a37a9d134521b13e3ba7bfd892eda1e6dce7ab3a5b44510f3f7770957206a9139105fa77f3c664daef9134f52e1148a094b13e638b935d5d
|
7
|
+
data.tar.gz: f0d1f569b0ddafab94d51b0ebef7f0e8a4ec0f1f47cbde0f1fead7a68ee9ceb052b7908c65f053679959e274d72868d63be79a5c0062bbfbb790ded3efab8db3
|
data/README.md
CHANGED
@@ -48,6 +48,20 @@ video = VideoInfo.new("http://vimeo.com/898029")
|
|
48
48
|
# video.embed_url => "http://player.vimeo.com/video/898029"
|
49
49
|
# video.embed_code => "'<iframe src="//player.vimeo.com/video/898029?title=0&byline=0&portrait=0&autoplay=0" frameborder="0"></iframe>'"
|
50
50
|
|
51
|
+
video = VideoInfo.new("http://fast.wistia.com/embed/medias/pxonqr42is")
|
52
|
+
# video.available? => true
|
53
|
+
# video.provider => "Wistia"
|
54
|
+
# video.video_id => "pxonqr42is"
|
55
|
+
# video.title => "Understanding Analytics"
|
56
|
+
# video.duration => 250 (in seconds)
|
57
|
+
# video.width => 960
|
58
|
+
# video.height => 568
|
59
|
+
# video.thumbnail_small => "https://embed-ssl.wistia.com/deliveries/0fccbdc60ade35723f79f1c002bc61b135b610fa.jpg?image_crop_resized=960x540"
|
60
|
+
# video.thumbnail_medium => "https://embed-ssl.wistia.com/deliveries/0fccbdc60ade35723f79f1c002bc61b135b610fa.jpg?image_crop_resized=960x540"
|
61
|
+
# video.thumbnail_large => "https://embed-ssl.wistia.com/deliveries/0fccbdc60ade35723f79f1c002bc61b135b610fa.jpg?image_crop_resized=960x540"
|
62
|
+
# video.embed_url => "//fast.wistia.net/embed/iframe/pxonqr42is"
|
63
|
+
# video.embed_code => "'<iframe src="//fast.wistia.net/embed/iframe/pxonqr42is" frameborder="0"></iframe>'"
|
64
|
+
|
51
65
|
video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
|
52
66
|
# video.available? => true
|
53
67
|
# video.video_id => "mZqGqE0D0n4"
|
data/lib/video_info.rb
CHANGED
@@ -7,7 +7,11 @@ class VideoInfo
|
|
7
7
|
class UrlError < StandardError; end
|
8
8
|
extend Forwardable
|
9
9
|
|
10
|
-
PROVIDERS = %w[
|
10
|
+
PROVIDERS = %w[
|
11
|
+
Dailymotion Vkontakte Wistia
|
12
|
+
Vimeo VimeoPlaylist
|
13
|
+
Youtube YoutubePlaylist
|
14
|
+
]
|
11
15
|
PROVIDERS.each { |p| require "video_info/providers/#{p.downcase}" }
|
12
16
|
|
13
17
|
def_delegators :@provider, :provider, :video_id, :video_owner, :url, :data
|
data/lib/video_info/provider.rb
CHANGED
@@ -13,13 +13,17 @@ class VideoInfo
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.usable?(url)
|
16
|
-
raise NotImplementedError.new(
|
16
|
+
raise NotImplementedError.new(
|
17
|
+
'Provider class must implement .usable? public method'
|
18
|
+
)
|
17
19
|
end
|
18
20
|
|
19
21
|
def embed_code(options = {})
|
20
22
|
iframe_attributes = options.fetch(:iframe_attributes, {})
|
21
23
|
iframe_attrs = ["src=\"#{_embed_url(options)}\"", "frameborder=\"0\""]
|
22
|
-
iframe_attrs << _hash_to_attributes(
|
24
|
+
iframe_attrs << _hash_to_attributes(
|
25
|
+
_default_iframe_attributes.merge(iframe_attributes)
|
26
|
+
)
|
23
27
|
|
24
28
|
"<iframe #{iframe_attrs.reject(&:empty?).join(" ")}></iframe>"
|
25
29
|
end
|
@@ -28,7 +32,6 @@ class VideoInfo
|
|
28
32
|
@data ||= _set_data_from_api
|
29
33
|
end
|
30
34
|
|
31
|
-
|
32
35
|
def available?
|
33
36
|
!%w[403 404].include?(_response_code)
|
34
37
|
end
|
@@ -37,14 +40,13 @@ class VideoInfo
|
|
37
40
|
|
38
41
|
def _response_code
|
39
42
|
response = nil
|
40
|
-
Net::HTTP.start(_api_base, 80) {|http|
|
41
|
-
response = http.head(_api_path)
|
42
|
-
}
|
43
|
+
Net::HTTP.start(_api_base, 80) { |http| response = http.head(_api_path) }
|
43
44
|
response.code
|
44
45
|
end
|
45
46
|
|
46
47
|
def _clean_options(options)
|
47
|
-
options =
|
48
|
+
options =
|
49
|
+
{ 'User-Agent' => "VideoInfo/#{VideoInfo::VERSION}" }.merge(options)
|
48
50
|
options.dup.each do |key, value|
|
49
51
|
if _not_openuri_option_symbol?(key)
|
50
52
|
options[_http_header_field(key)] = value
|
@@ -79,11 +81,15 @@ class VideoInfo
|
|
79
81
|
end
|
80
82
|
|
81
83
|
def _url_regex
|
82
|
-
raise NotImplementedError.new(
|
84
|
+
raise NotImplementedError.new(
|
85
|
+
'Provider class must implement #_url_regex private method'
|
86
|
+
)
|
83
87
|
end
|
84
88
|
|
85
89
|
def _api_url
|
86
|
-
raise NotImplementedError.new(
|
90
|
+
raise NotImplementedError.new(
|
91
|
+
'Provider class must implement #_api_url private method'
|
92
|
+
)
|
87
93
|
end
|
88
94
|
|
89
95
|
def _embed_url(options)
|
@@ -97,7 +103,7 @@ class VideoInfo
|
|
97
103
|
|
98
104
|
def _hash_to_attributes(hash)
|
99
105
|
return unless hash.is_a?(Hash)
|
100
|
-
hash.map{|k,v| "#{k}=\"#{v}\""}.join(' ')
|
106
|
+
hash.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
|
101
107
|
end
|
102
108
|
|
103
109
|
def _hash_to_params(hash)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class VideoInfo
|
2
2
|
module Providers
|
3
3
|
class Dailymotion < Provider
|
4
|
-
|
5
4
|
def self.usable?(url)
|
6
5
|
url =~ /(dai(?:\.ly|lymotion\.com))/
|
7
6
|
end
|
@@ -50,9 +49,9 @@ class VideoInfo
|
|
50
49
|
|
51
50
|
def _response_code
|
52
51
|
response = nil
|
53
|
-
Net::HTTP.start(_api_base, 443, use_ssl: true)
|
52
|
+
Net::HTTP.start(_api_base, 443, use_ssl: true) do |http|
|
54
53
|
response = http.get(_api_path)
|
55
|
-
|
54
|
+
end
|
56
55
|
response.code
|
57
56
|
end
|
58
57
|
|
@@ -79,7 +78,6 @@ class VideoInfo
|
|
79
78
|
def _default_url_attributes
|
80
79
|
{ autoplay: 0 }
|
81
80
|
end
|
82
|
-
|
83
81
|
end
|
84
82
|
end
|
85
83
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class VideoInfo
|
2
2
|
module Providers
|
3
3
|
class Vimeo < Provider
|
4
|
-
|
5
4
|
def self.usable?(url)
|
6
5
|
url =~ /(vimeo\.com\/(?!album|hubnut\/album).*)/
|
7
6
|
end
|
@@ -45,7 +44,7 @@ class VideoInfo
|
|
45
44
|
end
|
46
45
|
|
47
46
|
def _api_base
|
48
|
-
|
47
|
+
'vimeo.com'
|
49
48
|
end
|
50
49
|
|
51
50
|
def _api_path
|
@@ -66,7 +65,6 @@ class VideoInfo
|
|
66
65
|
portrait: 0,
|
67
66
|
autoplay: 0 }
|
68
67
|
end
|
69
|
-
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
@@ -16,7 +16,7 @@ class VideoInfo
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def description
|
19
|
-
content = data[/<meta name="description" content="(.*)" \/>/,1]
|
19
|
+
content = data[/<meta name="description" content="(.*)" \/>/, 1]
|
20
20
|
HTMLEntities.new.decode(content)
|
21
21
|
end
|
22
22
|
alias_method :keywords, :description
|
@@ -34,11 +34,11 @@ class VideoInfo
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def title
|
37
|
-
data[/<title>(.*)<\/title>/,1].gsub(
|
37
|
+
data[/<title>(.*)<\/title>/, 1].gsub(' | ВКонтакте', '')
|
38
38
|
end
|
39
39
|
|
40
40
|
def view_count
|
41
|
-
data[/mv_num_views\\">.*?(\d+)/,1].to_i
|
41
|
+
data[/mv_num_views\\">.*?(\d+)/, 1].to_i
|
42
42
|
end
|
43
43
|
|
44
44
|
def embed_url
|
@@ -46,7 +46,7 @@ class VideoInfo
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def duration
|
49
|
-
data[/"duration":(\d+)/,1].to_i
|
49
|
+
data[/"duration":(\d+)/, 1].to_i
|
50
50
|
end
|
51
51
|
|
52
52
|
private
|
@@ -56,28 +56,26 @@ class VideoInfo
|
|
56
56
|
if RUBY_VERSION.to_i < 2
|
57
57
|
Iconv.iconv('utf-8', 'cp1251', uri.read)[0]
|
58
58
|
else
|
59
|
-
uri.read.encode(
|
59
|
+
uri.read.encode('UTF-8')
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
def _response_code
|
64
64
|
response = nil
|
65
|
-
Net::HTTP.start(_api_base, 80) {|http|
|
66
|
-
response = http.get(_api_path)
|
67
|
-
}
|
65
|
+
Net::HTTP.start(_api_base, 80) { |http| response = http.get(_api_path) }
|
68
66
|
response.code
|
69
67
|
end
|
70
68
|
|
71
69
|
def _api_base
|
72
|
-
URI
|
70
|
+
URI.parse(url).host
|
73
71
|
end
|
74
72
|
|
75
73
|
def _api_path
|
76
|
-
URI
|
74
|
+
URI.parse(url).path
|
77
75
|
end
|
78
76
|
|
79
77
|
def _data_hash
|
80
|
-
data[/hash2\\":\\"(\w+)/,1]
|
78
|
+
data[/hash2\\":\\"(\w+)/, 1]
|
81
79
|
end
|
82
80
|
|
83
81
|
def _set_video_id_from_url
|
@@ -89,13 +87,12 @@ class VideoInfo
|
|
89
87
|
end
|
90
88
|
|
91
89
|
def _default_iframe_attributes
|
92
|
-
{ allowfullscreen:
|
90
|
+
{ allowfullscreen: 'allowfullscreen' }
|
93
91
|
end
|
94
92
|
|
95
93
|
def _default_url_attributes
|
96
94
|
{}
|
97
95
|
end
|
98
|
-
|
99
96
|
end
|
100
97
|
end
|
101
98
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class VideoInfo
|
2
|
+
module Providers
|
3
|
+
class Wistia < Provider
|
4
|
+
def self.usable?(url)
|
5
|
+
url =~ /(.*)(wistia.com|wistia.net|wi.st)/
|
6
|
+
end
|
7
|
+
|
8
|
+
def provider
|
9
|
+
'Wistia'
|
10
|
+
end
|
11
|
+
|
12
|
+
%w[title duration width height].each do |method|
|
13
|
+
define_method(method) { data[method] }
|
14
|
+
end
|
15
|
+
|
16
|
+
%w[description keywords view_count date].each do |method|
|
17
|
+
define_method(method) { nil }
|
18
|
+
end
|
19
|
+
|
20
|
+
def embed_url
|
21
|
+
"//fast.wistia.net/embed/iframe/#{video_id}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def thumbnail_small
|
25
|
+
data['thumbnail_url']
|
26
|
+
end
|
27
|
+
|
28
|
+
def thumbnail_medium
|
29
|
+
data['thumbnail_url']
|
30
|
+
end
|
31
|
+
|
32
|
+
def thumbnail_large
|
33
|
+
data['thumbnail_url']
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def _url_regex
|
39
|
+
/(?:.*)(?:wistia.com|wi.st|wistia.net)\/(?:embed\/)?(?:medias\/)?(?:iframe\/)?(.+)/
|
40
|
+
end
|
41
|
+
|
42
|
+
def _api_base
|
43
|
+
'fast.wistia.com'
|
44
|
+
end
|
45
|
+
|
46
|
+
def _api_path
|
47
|
+
"/oembed?url=http%3A%2F%2Fhome.wistia.com%2Fmedias%2F#{video_id}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def _api_url
|
51
|
+
"http://#{_api_base}#{_api_path}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def _default_iframe_attributes
|
55
|
+
{}
|
56
|
+
end
|
57
|
+
|
58
|
+
def _default_url_attributes
|
59
|
+
{}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class VideoInfo
|
2
2
|
module Providers
|
3
3
|
class Youtube < Provider
|
4
|
-
|
5
4
|
def self.usable?(url)
|
6
5
|
url =~ /(youtube\.com\/(?!playlist|embed\/videoseries).*)|(youtu\.be)/
|
7
6
|
end
|
@@ -47,7 +46,11 @@ class VideoInfo
|
|
47
46
|
end
|
48
47
|
|
49
48
|
def view_count
|
50
|
-
|
49
|
+
if _video_entry['yt$statistics']
|
50
|
+
_video_entry['yt$statistics']['viewCount'].to_i
|
51
|
+
else
|
52
|
+
0
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
53
56
|
private
|
@@ -69,7 +72,7 @@ class VideoInfo
|
|
69
72
|
end
|
70
73
|
|
71
74
|
def _default_iframe_attributes
|
72
|
-
{ allowfullscreen:
|
75
|
+
{ allowfullscreen: 'allowfullscreen' }
|
73
76
|
end
|
74
77
|
|
75
78
|
def _default_url_attributes
|
@@ -87,7 +90,6 @@ class VideoInfo
|
|
87
90
|
def _video_thumbnail(id)
|
88
91
|
_video_entry['media$group']['media$thumbnail'][id]['url']
|
89
92
|
end
|
90
|
-
|
91
93
|
end
|
92
94
|
end
|
93
95
|
end
|
data/lib/video_info/version.rb
CHANGED
@@ -21,28 +21,32 @@ http_interactions:
|
|
21
21
|
Server:
|
22
22
|
- DMS/1.0.42
|
23
23
|
X-Dm-Backnode:
|
24
|
-
- web-
|
24
|
+
- web-051.adm.dailymotion.com:80
|
25
25
|
Vary:
|
26
26
|
- Authorization,Accept-Encoding
|
27
27
|
Cache-Control:
|
28
28
|
- private, max-age=900
|
29
29
|
Content-Type:
|
30
|
-
- application/json
|
30
|
+
- application/json; charset=UTF-8
|
31
31
|
P3p:
|
32
32
|
- policyref="http://www.dailymotion.com/w3c/p3p.xml", CP="IDC DSP CURa ADMa
|
33
33
|
DEVa TAIa OUR BUS IND UNI COM NAV INT"
|
34
34
|
Date:
|
35
|
-
-
|
35
|
+
- Tue, 09 Dec 2014 19:27:23 GMT
|
36
36
|
X-Dm-Lb:
|
37
37
|
- 195.8.215.129
|
38
38
|
Access-Control-Allow-Origin:
|
39
39
|
- "*"
|
40
40
|
Etag:
|
41
|
-
- W/"
|
41
|
+
- W/"bQdj-tf3xQT_eEdX1mjrEQ"
|
42
42
|
X-Response-Time:
|
43
|
-
- 0.
|
43
|
+
- 0.056163 seconds
|
44
44
|
Last-Modified:
|
45
|
-
-
|
45
|
+
- Thu, 27 Nov 2014 15:31:39 GMT
|
46
|
+
Access-Control-Allow-Headers:
|
47
|
+
- Authorization
|
48
|
+
Access-Control-Allow-Methods:
|
49
|
+
- GET, POST, DELETE
|
46
50
|
X-Dm-Page:
|
47
51
|
- ch-fr.rest.rest_api
|
48
52
|
Content-Length:
|
@@ -52,5 +56,5 @@ http_interactions:
|
|
52
56
|
string: '{"error":{"code":404,"message":"This video does not exist or has been
|
53
57
|
deleted.","type":"not_found"}}'
|
54
58
|
http_version:
|
55
|
-
recorded_at:
|
59
|
+
recorded_at: Tue, 09 Dec 2014 19:27:23 GMT
|
56
60
|
recorded_with: VCR 2.9.3
|
@@ -21,18 +21,18 @@ http_interactions:
|
|
21
21
|
Server:
|
22
22
|
- DMS/1.0.42
|
23
23
|
X-Dm-Backnode:
|
24
|
-
- web-
|
24
|
+
- web-042.adm.dailymotion.com:80
|
25
25
|
Vary:
|
26
26
|
- Authorization,Accept-Encoding
|
27
27
|
Cache-Control:
|
28
28
|
- private, max-age=900
|
29
29
|
Content-Type:
|
30
|
-
- application/json
|
30
|
+
- application/json; charset=UTF-8
|
31
31
|
P3p:
|
32
32
|
- policyref="http://www.dailymotion.com/w3c/p3p.xml", CP="IDC DSP CURa ADMa
|
33
33
|
DEVa TAIa OUR BUS IND UNI COM NAV INT"
|
34
34
|
Date:
|
35
|
-
-
|
35
|
+
- Tue, 09 Dec 2014 19:27:23 GMT
|
36
36
|
X-Dm-Lb:
|
37
37
|
- 195.8.215.129
|
38
38
|
Access-Control-Allow-Origin:
|
@@ -40,9 +40,13 @@ http_interactions:
|
|
40
40
|
Etag:
|
41
41
|
- W/"O1DJzTYSf9K1Wvn1OkaB4Q"
|
42
42
|
X-Response-Time:
|
43
|
-
- 0.
|
43
|
+
- 0.055371 seconds
|
44
44
|
Last-Modified:
|
45
45
|
- Sat, 06 Jul 2013 19:32:30 GMT
|
46
|
+
Access-Control-Allow-Headers:
|
47
|
+
- Authorization
|
48
|
+
Access-Control-Allow-Methods:
|
49
|
+
- GET, POST, DELETE
|
46
50
|
X-Dm-Page:
|
47
51
|
- ch-fr.rest.rest_api
|
48
52
|
Content-Length:
|
@@ -51,5 +55,5 @@ http_interactions:
|
|
51
55
|
encoding: UTF-8
|
52
56
|
string: '{"id":"x7lni3","title":"Mario Kart (R\u00e9mi Gaillard)","channel":"fun","owner":"x4r137"}'
|
53
57
|
http_version:
|
54
|
-
recorded_at:
|
58
|
+
recorded_at: Tue, 09 Dec 2014 19:27:23 GMT
|
55
59
|
recorded_with: VCR 2.9.3
|