onebox 2.2.15 → 2.2.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onebox/engine/youtube_onebox.rb +11 -5
- data/lib/onebox/helpers.rb +3 -21
- data/lib/onebox/version.rb +1 -1
- data/onebox.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a892a3207f5adc40ff6c9924e52cfaa41e332c0890dfb52df2a15476900ec9a
|
4
|
+
data.tar.gz: 9fee19ab2aafa30845f6a44852e5ee6822fd702b762597740dee28c6136374ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dae1b6efe6dede26280478b904c9fa7fb128bdddc42f7b751b8acbaa80cbd1ba2b7717093105c12cef376fc754faf53f0fc5989fb94c9927925369c4f9527f7b
|
7
|
+
data.tar.gz: e5243223f4206de9b7bba0af587512dd786515f28687a5939b0cabfa71d91bc8742f0d75cbaffc272e8a6c00cae26feeca0999ebb7d611a650be2149ca718a99
|
@@ -89,25 +89,31 @@ module Onebox
|
|
89
89
|
|
90
90
|
def video_id
|
91
91
|
@video_id ||= begin
|
92
|
+
id = nil
|
93
|
+
|
92
94
|
# http://youtu.be/afyK1HSFfgw
|
93
95
|
if uri.host["youtu.be"]
|
94
96
|
id = uri.path[/\/([\w\-]+)/, 1]
|
95
|
-
return id if id
|
96
97
|
end
|
97
98
|
|
98
99
|
# https://www.youtube.com/embed/vsF0K3Ou1v0
|
99
100
|
if uri.path["/embed/"]
|
100
|
-
id
|
101
|
-
return id if id
|
101
|
+
id ||= uri.path[/\/embed\/([\w\-]+)/, 1]
|
102
102
|
end
|
103
103
|
|
104
104
|
# https://www.youtube.com/watch?v=Z0UISCEe52Y
|
105
|
-
params['v']
|
105
|
+
id ||= params['v']
|
106
|
+
|
107
|
+
sanitize_yt_id(id)
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
109
111
|
def list_id
|
110
|
-
@list_id ||= params['list']
|
112
|
+
@list_id ||= sanitize_yt_id(params['list'])
|
113
|
+
end
|
114
|
+
|
115
|
+
def sanitize_yt_id(raw)
|
116
|
+
raw&.match?(/\A[\w-]+\z/) ? raw : nil
|
111
117
|
end
|
112
118
|
|
113
119
|
def embed_params
|
data/lib/onebox/helpers.rb
CHANGED
@@ -26,23 +26,7 @@ module Onebox
|
|
26
26
|
|
27
27
|
def self.fetch_html_doc(url, headers = nil, body_cacher = nil)
|
28
28
|
response = (fetch_response(url, headers: headers, body_cacher: body_cacher) rescue nil)
|
29
|
-
|
30
|
-
uri = Addressable::URI.parse(url)
|
31
|
-
|
32
|
-
ignore_canonical_tag = doc.at('meta[property="og:ignore_canonical"]')
|
33
|
-
should_ignore_canonical = IGNORE_CANONICAL_DOMAINS.map { |hostname| uri.hostname.match?(hostname) }.any?
|
34
|
-
|
35
|
-
unless (ignore_canonical_tag && ignore_canonical_tag['content'].to_s == 'true') || should_ignore_canonical
|
36
|
-
# prefer canonical link
|
37
|
-
canonical_link = doc.at('//link[@rel="canonical"]/@href')
|
38
|
-
canonical_uri = Addressable::URI.parse(canonical_link)
|
39
|
-
if canonical_link && "#{canonical_uri.host}#{canonical_uri.path}" != "#{uri.host}#{uri.path}"
|
40
|
-
response = (fetch_response(canonical_uri.to_s, headers: headers, body_cacher: body_cacher) rescue nil)
|
41
|
-
doc = Nokogiri::HTML(response) if response
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
doc
|
29
|
+
Nokogiri::HTML(response)
|
46
30
|
end
|
47
31
|
|
48
32
|
def self.fetch_response(location, redirect_limit: 5, domain: nil, headers: nil, body_cacher: nil)
|
@@ -63,8 +47,7 @@ module Onebox
|
|
63
47
|
end
|
64
48
|
|
65
49
|
result = StringIO.new
|
66
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.normalized_scheme == 'https') do |http|
|
67
|
-
http.open_timeout = Onebox.options.connect_timeout
|
50
|
+
Net::HTTP.start(uri.host, uri.port, open_timeout: Onebox.options.connect_timeout, use_ssl: uri.normalized_scheme == 'https') do |http|
|
68
51
|
http.read_timeout = Onebox.options.timeout
|
69
52
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # Work around path building bugs
|
70
53
|
|
@@ -118,8 +101,7 @@ module Onebox
|
|
118
101
|
def self.fetch_content_length(location)
|
119
102
|
uri = URI(location)
|
120
103
|
|
121
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.is_a?(URI::HTTPS)) do |http|
|
122
|
-
http.open_timeout = Onebox.options.connect_timeout
|
104
|
+
Net::HTTP.start(uri.host, uri.port, open_timeout: Onebox.options.connect_timeout, use_ssl: uri.is_a?(URI::HTTPS)) do |http|
|
123
105
|
http.read_timeout = Onebox.options.timeout
|
124
106
|
if uri.is_a?(URI::HTTPS)
|
125
107
|
http.use_ssl = true
|
data/lib/onebox/version.rb
CHANGED
data/onebox.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.files = `git ls-files`.split($/).reject { |s| s =~ /^(spec|web)/ }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_runtime_dependency 'addressable', '~> 2.
|
23
|
+
spec.add_runtime_dependency 'addressable', '~> 2.8.0'
|
24
24
|
spec.add_runtime_dependency 'multi_json', '~> 1.11'
|
25
25
|
spec.add_runtime_dependency 'mustache'
|
26
26
|
spec.add_runtime_dependency 'nokogiri', '~> 1.7'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joanna Zeta
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-07-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 2.
|
21
|
+
version: 2.8.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 2.
|
28
|
+
version: 2.8.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: multi_json
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|