link_preview 0.3.0.pre.1 → 0.3.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 645ac9be334767988dfec1425ef4bd3255fa461e
4
- data.tar.gz: ba9301c67a6b3dba2612fac61af20bb0fe60af39
3
+ metadata.gz: 35f267fb3916535449cc2d8432cfccff9f3f484b
4
+ data.tar.gz: 1544498d1364a48834d3d512b33e2a8df42315f4
5
5
  SHA512:
6
- metadata.gz: b2a9a28ce62df205eabced120ebf013b203deceb0baca7682de106d0ab5db23b16ec0ac5d9b50f9842d95e8b5f5e7f2eaad7a4df6c22f198945218705bd1223b
7
- data.tar.gz: 1ed6611609f62a4ad1e3a8b9820e6f7cbb98572673b6cbf4eb04d96f1b29563e732d39cf1c26a4f7c40e4b24478cfce98ec774421bfbd79587fb4c8f2152d22f
6
+ metadata.gz: aed599b2dec22f70af8a9ae6540de40f2e5d7739bbddf03c41737551b4db82c7ec2ee109dad7dd195f002c10d3b39091fdd3a3b13da4cab20713d377f749dea1
7
+ data.tar.gz: bc31ed8c7469d32dbbd616822e9dde0144b5deb6fc0e4dd29bfc77fbfa2d6b630dd8fe06e4ddef4fc6cee9ad50049fdb5b544e38f4ef66cf20652313e7c8dd73
@@ -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 width="#{content_width_scaled}" height="#{content_height_scaled}">
318
+ <video #{width_attribute} #{height_attribute} controls>
317
319
  <source src="#{content_url}"
318
320
  type="#{content_type}" />
319
321
  </video>
@@ -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: find_meta_property(doc, 'og:image:secure_url'),
91
- image: find_meta_property(doc, 'og:image'),
92
- image_url: find_meta_property(doc, 'og: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: find_meta_property(doc, 'og:video:secure_url'),
98
- video: find_meta_property(doc, 'og:video'),
99
- video_url: find_meta_property(doc, 'og:video:url'),
100
- video_type: find_meta_property(doc, 'og:video:type'),
101
- video_width: find_meta_property(doc, 'og:video:width'),
102
- video_height: find_meta_property(doc, 'og: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.attributes[key].value.casecmp(value.downcase).zero?
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
- enum_meta_pair(doc, 'name', 'description').detect(&:present?)
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).detect(&:present?)
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
@@ -19,5 +19,5 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  module LinkPreview
22
- VERSION = '0.3.0-1'.freeze
22
+ VERSION = '0.3.0-2'.freeze
23
23
  end
@@ -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=590
36
+ - max-age=148
35
37
  Expires:
36
- - Thu, 25 Feb 2016 18:54:31 GMT
38
+ - Fri, 26 Feb 2016 01:43:39 GMT
37
39
  Date:
38
- - Thu, 25 Feb 2016 18:44:41 GMT
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: Thu, 25 Feb 2016 18:44:41 GMT
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-thumb2
291
+ - pa-front-thumb1
280
292
  X-Kaltura-Session:
281
- - '890700395'
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=3526
305
+ - public, max-age=488
302
306
  Expires:
303
- - Thu, 25 Feb 2016 19:43:27 GMT
307
+ - Fri, 26 Feb 2016 01:49:19 GMT
304
308
  Date:
305
- - Thu, 25 Feb 2016 18:44:41 GMT
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: Thu, 25 Feb 2016 18:44:41 GMT
489
+ recorded_at: Fri, 26 Feb 2016 01:41:11 GMT
486
490
  recorded_with: VCR 3.0.1
@@ -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 width="560" height="395"><source src="https://cdnapisec.kaltura.com/p/243342/sp/24334200/embedIframeJs/uiconf_id/28685261/partner_id/243342?iframeembed=true&playerId=kaltura_player&entry_id=1_sf5ovm7u" type="video/mp4" /></video>),
749
- width: 560,
750
- height: 395
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.1
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-25 00:00:00.000000000 Z
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-oembed