link_preview 0.3.0.pre.1 → 0.3.0.pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/link_preview/content.rb +3 -1
- data/lib/link_preview/parser.rb +49 -13
- data/lib/link_preview/version.rb +1 -1
- data/spec/files/requests/kalture_html5.yml +24 -20
- data/spec/link_preview_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35f267fb3916535449cc2d8432cfccff9f3f484b
|
4
|
+
data.tar.gz: 1544498d1364a48834d3d512b33e2a8df42315f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aed599b2dec22f70af8a9ae6540de40f2e5d7739bbddf03c41737551b4db82c7ec2ee109dad7dd195f002c10d3b39091fdd3a3b13da4cab20713d377f749dea1
|
7
|
+
data.tar.gz: bc31ed8c7469d32dbbd616822e9dde0144b5deb6fc0e4dd29bfc77fbfa2d6b630dd8fe06e4ddef4fc6cee9ad50049fdb5b544e38f4ef66cf20652313e7c8dd73
|
data/lib/link_preview/content.rb
CHANGED
@@ -312,8 +312,10 @@ module LinkPreview
|
|
312
312
|
|
313
313
|
def content_html_video
|
314
314
|
return unless content_url.present?
|
315
|
+
width_attribute = %(width="#{content_width_scaled}") if content_width_scaled > 0
|
316
|
+
height_attribute = %(height="#{content_height_scaled}") if content_height_scaled > 0
|
315
317
|
<<-EOF.strip.gsub(/\s+/, ' ').gsub(/>\s+</, '><')
|
316
|
-
<video
|
318
|
+
<video #{width_attribute} #{height_attribute} controls>
|
317
319
|
<source src="#{content_url}"
|
318
320
|
type="#{content_type}" />
|
319
321
|
</video>
|
data/lib/link_preview/parser.rb
CHANGED
@@ -83,23 +83,27 @@ module LinkPreview
|
|
83
83
|
enum_oembed_link(doc) do |link_rel|
|
84
84
|
discovered_uris << LinkPreview::URI.parse(link_rel, @options)
|
85
85
|
end
|
86
|
+
|
87
|
+
opengraph_image_array_first_elem = find_meta_property_array(doc, 'og:image').first
|
88
|
+
opengraph_video_array_first_elem = find_meta_property_array(doc, 'og:video').first
|
89
|
+
|
86
90
|
{
|
87
91
|
opengraph: {
|
88
92
|
title: find_meta_property(doc, 'og:title'),
|
89
93
|
description: find_meta_property(doc, 'og:description'),
|
90
|
-
image_secure_url:
|
91
|
-
image:
|
92
|
-
image_url:
|
94
|
+
image_secure_url: opengraph_image_array_first_elem['og:image:secure_url'],
|
95
|
+
image: opengraph_image_array_first_elem['og:image'],
|
96
|
+
image_url: opengraph_image_array_first_elem['og:image:url'],
|
93
97
|
tag: find_meta_property(doc, 'og:tag'),
|
94
98
|
url: find_meta_property(doc, 'og:url'),
|
95
99
|
type: find_meta_property(doc, 'og:type'),
|
96
100
|
site_name: find_meta_property(doc, 'og:site_name'),
|
97
|
-
video_secure_url:
|
98
|
-
video:
|
99
|
-
video_url:
|
100
|
-
video_type:
|
101
|
-
video_width:
|
102
|
-
video_height:
|
101
|
+
video_secure_url: opengraph_video_array_first_elem['og:video:secure_url'],
|
102
|
+
video: opengraph_video_array_first_elem['og:video'],
|
103
|
+
video_url: opengraph_video_array_first_elem['og:video:url'],
|
104
|
+
video_type: opengraph_video_array_first_elem['og:video:type'],
|
105
|
+
video_width: opengraph_video_array_first_elem['og:video:width'],
|
106
|
+
video_height: opengraph_video_array_first_elem['og:video:height']
|
103
107
|
},
|
104
108
|
html: {
|
105
109
|
title: find_title(doc),
|
@@ -159,7 +163,7 @@ module LinkPreview
|
|
159
163
|
Enumerator.new do |e|
|
160
164
|
doc.search('head/meta').each do |node|
|
161
165
|
next unless matching_meta_pair?(node, key, value)
|
162
|
-
e.yield node.attributes['content'].value
|
166
|
+
e.yield OpenStruct.new(key: node.attributes['property'].value, value: node.attributes['content'].value)
|
163
167
|
end
|
164
168
|
end
|
165
169
|
end
|
@@ -168,10 +172,19 @@ module LinkPreview
|
|
168
172
|
return false unless valid_meta_node?(node)
|
169
173
|
return false unless node.attributes[key]
|
170
174
|
return false unless node.attributes[key].value
|
171
|
-
return false unless node
|
175
|
+
return false unless matching_meta_value?(node, key, value)
|
172
176
|
true
|
173
177
|
end
|
174
178
|
|
179
|
+
def matching_meta_value?(node, key, value)
|
180
|
+
case value
|
181
|
+
when String
|
182
|
+
node.attributes[key].value.casecmp(value.downcase).zero?
|
183
|
+
when Regexp
|
184
|
+
node.attributes[key].value =~ value
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
175
188
|
def valid_meta_node?(node)
|
176
189
|
return false unless node
|
177
190
|
return false unless node.respond_to?(:attributes)
|
@@ -181,11 +194,34 @@ module LinkPreview
|
|
181
194
|
end
|
182
195
|
|
183
196
|
def find_meta_description(doc)
|
184
|
-
|
197
|
+
Enumerator.new do |e|
|
198
|
+
doc.search('head/meta[name=description]').each do |node|
|
199
|
+
next unless matching_meta_pair?(node, 'name', 'description')
|
200
|
+
e.yield node.attributes['content'].value
|
201
|
+
end
|
202
|
+
end.first
|
185
203
|
end
|
186
204
|
|
187
205
|
def find_meta_property(doc, property)
|
188
|
-
enum_meta_pair(doc, 'property', property).
|
206
|
+
enum_meta_pair(doc, 'property', property).first.try(:value)
|
207
|
+
end
|
208
|
+
|
209
|
+
def find_meta_property_array(doc, property)
|
210
|
+
[].tap do |property_array|
|
211
|
+
property_group = {}
|
212
|
+
enum_meta_pair(doc, 'property', /\A#{Regexp.escape(property)}/).each do |pair|
|
213
|
+
if property_array_delimiter?(property, pair) && property_group.any?
|
214
|
+
property_array.push(property_group.dup)
|
215
|
+
property_group.clear
|
216
|
+
end
|
217
|
+
property_group.merge!(pair.key => pair.value)
|
218
|
+
end
|
219
|
+
property_array.push(property_group)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def property_array_delimiter?(property, pair)
|
224
|
+
pair.key == property || pair.key == "#{property}:url"
|
189
225
|
end
|
190
226
|
end
|
191
227
|
end
|
data/lib/link_preview/version.rb
CHANGED
@@ -20,10 +20,12 @@ http_interactions:
|
|
20
20
|
headers:
|
21
21
|
Server:
|
22
22
|
- Apache/2.4.7 (Ubuntu)
|
23
|
+
Etag:
|
24
|
+
- '"2419-52c939f3d9ad5"'
|
25
|
+
X-N:
|
26
|
+
- S
|
23
27
|
Last-Modified:
|
24
28
|
- Thu, 25 Feb 2016 08:03:46 GMT
|
25
|
-
Etag:
|
26
|
-
- '"2419-52c939f3d9ad5-gzip"'
|
27
29
|
Access-Control-Allow-Origin:
|
28
30
|
- "*"
|
29
31
|
Content-Type:
|
@@ -31,11 +33,11 @@ http_interactions:
|
|
31
33
|
Vary:
|
32
34
|
- Accept-Encoding
|
33
35
|
Cache-Control:
|
34
|
-
- max-age=
|
36
|
+
- max-age=148
|
35
37
|
Expires:
|
36
|
-
-
|
38
|
+
- Fri, 26 Feb 2016 01:43:39 GMT
|
37
39
|
Date:
|
38
|
-
-
|
40
|
+
- Fri, 26 Feb 2016 01:41:11 GMT
|
39
41
|
Content-Length:
|
40
42
|
- '9241'
|
41
43
|
Connection:
|
@@ -250,7 +252,7 @@ http_interactions:
|
|
250
252
|
dCZxdW90OyBjb250ZW50PSZxdW90OzM3MCZxdW90OyAvJmd0OwkKPC9wcmU+
|
251
253
|
CjwvYm9keT4KPC9odG1sPg==
|
252
254
|
http_version:
|
253
|
-
recorded_at:
|
255
|
+
recorded_at: Fri, 26 Feb 2016 01:41:11 GMT
|
254
256
|
- request:
|
255
257
|
method: get
|
256
258
|
uri: http://cdnbakmi.kaltura.com/p/243342/sp/24334200/thumbnail/entry_id/1_sf5ovm7u/version/100003/width/400
|
@@ -271,38 +273,40 @@ http_interactions:
|
|
271
273
|
headers:
|
272
274
|
Server:
|
273
275
|
- nginx/1.8.0
|
276
|
+
Vary:
|
277
|
+
- Accept-Encoding
|
278
|
+
X-Vod-Me:
|
279
|
+
- pa-front-origin102
|
280
|
+
X-Vod-Session:
|
281
|
+
- '380955972'
|
282
|
+
Last-Modified:
|
283
|
+
- Sun, 19 Nov 2000 08:52:00 GMT
|
284
|
+
Etag:
|
285
|
+
- '"11092ea89-1e4f-0"'
|
274
286
|
Content-Type:
|
275
287
|
- image/jpeg
|
276
288
|
Content-Length:
|
277
289
|
- '7759'
|
278
290
|
X-Me:
|
279
|
-
- pa-front-
|
291
|
+
- pa-front-thumb1
|
280
292
|
X-Kaltura-Session:
|
281
|
-
- '
|
293
|
+
- '991505528'
|
282
294
|
Pragma:
|
283
295
|
- ''
|
284
296
|
X-Kaltura:
|
285
297
|
- cached-thumb-exists,19a8ef605b30ba4ada8be6b8a425ea6e
|
286
|
-
Last-Modified:
|
287
|
-
- Sun, 19 Nov 2000 08:52:00 GMT
|
288
298
|
Accept-Ranges:
|
289
299
|
- bytes
|
290
300
|
Access-Control-Allow-Origin:
|
291
301
|
- "*"
|
292
302
|
X-Kaltura-Sendfile:
|
293
303
|
- ''
|
294
|
-
Etag:
|
295
|
-
- '"11092ea89-1e4f-0"'
|
296
|
-
X-Vod-Me:
|
297
|
-
- pa-front-origin104
|
298
|
-
X-Vod-Session:
|
299
|
-
- '2120171211'
|
300
304
|
Cache-Control:
|
301
|
-
- public, max-age=
|
305
|
+
- public, max-age=488
|
302
306
|
Expires:
|
303
|
-
-
|
307
|
+
- Fri, 26 Feb 2016 01:49:19 GMT
|
304
308
|
Date:
|
305
|
-
-
|
309
|
+
- Fri, 26 Feb 2016 01:41:11 GMT
|
306
310
|
Connection:
|
307
311
|
- keep-alive
|
308
312
|
body:
|
@@ -482,5 +486,5 @@ http_interactions:
|
|
482
486
|
chCCPWlQhCCOxQhCCD2qp3IQgqqFCEFHblQoQgW5JchCBTkp25CECXpTt6EI
|
483
487
|
FpbtyEIKlVduQhBUb1JQhB//2Q==
|
484
488
|
http_version:
|
485
|
-
recorded_at:
|
489
|
+
recorded_at: Fri, 26 Feb 2016 01:41:11 GMT
|
486
490
|
recorded_with: VCR 3.0.1
|
data/spec/link_preview_spec.rb
CHANGED
@@ -745,9 +745,9 @@ describe LinkPreview do
|
|
745
745
|
description: %(Kaltura Player: Share plugin demonstrates the ease of which social share can be configured with the kaltura player toolkit.),
|
746
746
|
type: 'video',
|
747
747
|
thumbnail_url: 'http://cdnbakmi.kaltura.com/p/243342/sp/24334200/thumbnail/entry_id/1_sf5ovm7u/version/100003/width/400',
|
748
|
-
html: %(<video
|
749
|
-
width:
|
750
|
-
height:
|
748
|
+
html: %(<video controls><source src="https://cdnapisec.kaltura.com/p/243342/sp/24334200/playManifest/entryId/1_sf5ovm7u/flavorId/1_d2uwy7vv/format/url/protocol/http/a.mp4" type="video/mp4" /></video>),
|
749
|
+
width: 0,
|
750
|
+
height: 0
|
751
751
|
}
|
752
752
|
end
|
753
753
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link_preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0.pre.
|
4
|
+
version: 0.3.0.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Andrews
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-oembed
|