video_info 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/providers/vimeo.rb +0 -4
- data/lib/providers/youtube.rb +0 -4
- data/lib/video_info.rb +23 -12
- data/lib/video_info/version.rb +1 -1
- metadata +2 -2
data/lib/providers/vimeo.rb
CHANGED
data/lib/providers/youtube.rb
CHANGED
data/lib/video_info.rb
CHANGED
@@ -1,11 +1,32 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'multi_json'
|
3
|
-
require 'video_info/version'
|
4
3
|
require 'providers/vimeo'
|
5
4
|
require 'providers/youtube'
|
6
5
|
|
7
6
|
module VideoInfo
|
7
|
+
|
8
8
|
def self.get(url, options = {})
|
9
|
+
options = clean_options(options)
|
10
|
+
video = get_video(url, options)
|
11
|
+
valid?(video) ? video : nil
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.get_video(url, options)
|
17
|
+
case url
|
18
|
+
when /vimeo\.com/
|
19
|
+
Vimeo.new(url, options)
|
20
|
+
when /(youtube\.com)|(youtu\.be)/
|
21
|
+
Youtube.new(url, options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.valid?(video)
|
26
|
+
!video.nil? && !video.video_id.nil? && !['', nil].include?(video.title)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.clean_options(options)
|
9
30
|
options = { "User-Agent" => "VideoInfo/#{VideoInfo::VERSION}" }.merge options
|
10
31
|
options.dup.each do |key, value|
|
11
32
|
unless OpenURI::Options.keys.include?(key) || options[:iframe_attributes]
|
@@ -15,17 +36,7 @@ module VideoInfo
|
|
15
36
|
end
|
16
37
|
end
|
17
38
|
end
|
18
|
-
|
19
|
-
case url
|
20
|
-
when /vimeo\.com/
|
21
|
-
@video = Vimeo.new(url, options)
|
22
|
-
when /(youtube\.com)|(youtu\.be)/
|
23
|
-
@video = Youtube.new(url, options)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.method_missing(sym, *args, &block)
|
28
|
-
@video.send sym, *args, &block
|
39
|
+
options
|
29
40
|
end
|
30
41
|
|
31
42
|
def self.hash_to_attributes(hash)
|
data/lib/video_info/version.rb
CHANGED
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: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|