onebox 2.2.12 → 2.2.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -4
- data/lib/onebox/engine.rb +7 -11
- data/lib/onebox/engine/allowlisted_generic_onebox.rb +11 -18
- data/lib/onebox/engine/amazon_onebox.rb +26 -17
- data/lib/onebox/engine/asciinema_onebox.rb +0 -1
- data/lib/onebox/engine/audioboom_onebox.rb +5 -2
- data/lib/onebox/engine/bandcamp_onebox.rb +8 -8
- data/lib/onebox/engine/cloudapp_onebox.rb +12 -12
- data/lib/onebox/engine/coub_onebox.rb +0 -1
- data/lib/onebox/engine/facebook_media_onebox.rb +8 -7
- data/lib/onebox/engine/five_hundred_px_onebox.rb +0 -1
- data/lib/onebox/engine/flickr_onebox.rb +14 -15
- data/lib/onebox/engine/gfycat_onebox.rb +26 -26
- data/lib/onebox/engine/giphy_onebox.rb +0 -1
- data/lib/onebox/engine/github_blob_onebox.rb +4 -0
- data/lib/onebox/engine/github_commit_onebox.rb +13 -16
- data/lib/onebox/engine/github_folder_onebox.rb +1 -1
- data/lib/onebox/engine/github_gist_onebox.rb +1 -2
- data/lib/onebox/engine/github_issue_onebox.rb +16 -18
- data/lib/onebox/engine/github_pullrequest_onebox.rb +7 -4
- data/lib/onebox/engine/gitlab_blob_onebox.rb +4 -0
- data/lib/onebox/engine/google_calendar_onebox.rb +1 -1
- data/lib/onebox/engine/google_docs_onebox.rb +23 -41
- data/lib/onebox/engine/google_drive_onebox.rb +7 -7
- data/lib/onebox/engine/google_maps_onebox.rb +10 -8
- data/lib/onebox/engine/google_photos_onebox.rb +18 -18
- data/lib/onebox/engine/google_play_app_onebox.rb +3 -7
- data/lib/onebox/engine/imgur_onebox.rb +2 -2
- data/lib/onebox/engine/instagram_onebox.rb +4 -5
- data/lib/onebox/engine/kaltura_onebox.rb +8 -6
- data/lib/onebox/engine/opengraph_image.rb +0 -1
- data/lib/onebox/engine/pastebin_onebox.rb +11 -15
- data/lib/onebox/engine/pdf_onebox.rb +7 -15
- data/lib/onebox/engine/pubmed_onebox.rb +17 -12
- data/lib/onebox/engine/replit_onebox.rb +0 -1
- data/lib/onebox/engine/sketchfab_onebox.rb +8 -8
- data/lib/onebox/engine/slides_onebox.rb +10 -10
- data/lib/onebox/engine/soundcloud_onebox.rb +0 -1
- data/lib/onebox/engine/stack_exchange_onebox.rb +3 -2
- data/lib/onebox/engine/standard_embed.rb +2 -5
- data/lib/onebox/engine/steam_store_onebox.rb +6 -5
- data/lib/onebox/engine/trello_onebox.rb +4 -7
- data/lib/onebox/engine/twitch_clips_onebox.rb +1 -3
- data/lib/onebox/engine/twitch_stream_onebox.rb +1 -2
- data/lib/onebox/engine/twitch_video_onebox.rb +0 -2
- data/lib/onebox/engine/typeform_onebox.rb +7 -6
- data/lib/onebox/engine/vimeo_onebox.rb +9 -7
- data/lib/onebox/engine/wikimedia_onebox.rb +1 -2
- data/lib/onebox/engine/wikipedia_onebox.rb +12 -8
- data/lib/onebox/engine/youku_onebox.rb +7 -13
- data/lib/onebox/engine/youtube_onebox.rb +14 -13
- data/lib/onebox/file_type_finder.rb +0 -1
- data/lib/onebox/helpers.rb +7 -24
- data/lib/onebox/layout.rb +2 -14
- data/lib/onebox/matcher.rb +10 -8
- data/lib/onebox/mixins/git_blob_onebox.rb +8 -8
- data/lib/onebox/mixins/github_body.rb +30 -0
- data/lib/onebox/mixins/twitch_onebox.rb +0 -1
- data/lib/onebox/open_graph.rb +4 -4
- data/lib/onebox/preview.rb +3 -4
- data/lib/onebox/version.rb +1 -1
- data/templates/_layout.mustache +6 -2
- data/templates/allowlistedgeneric.mustache +8 -9
- data/templates/amazon.mustache +5 -2
- data/templates/github/github_body.mustache +5 -0
- data/templates/githubblob.mustache +44 -34
- data/templates/githubcommit.mustache +2 -10
- data/templates/githubfolder.mustache +2 -2
- data/templates/githubgist.mustache +9 -6
- data/templates/githubissue.mustache +9 -11
- data/templates/githubpullrequest.mustache +6 -18
- data/templates/gitlabblob.mustache +11 -4
- data/templates/googledocs.mustache +2 -2
- data/templates/googledrive.mustache +2 -2
- data/templates/googleplayapp.mustache +2 -1
- data/templates/instagram.mustache +1 -1
- data/templates/pastebin.mustache +6 -2
- data/templates/pdf.mustache +6 -3
- data/templates/stackexchange.mustache +1 -0
- data/templates/twitterstatus.mustache +20 -5
- data/templates/wikimedia.mustache +2 -2
- data/templates/wikipedia.mustache +2 -2
- data/templates/xkcd.mustache +2 -2
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3244779d201e9c64cb43a00dccfa5f189078c7b6b3523b3d262248a10bb9a4e1
|
4
|
+
data.tar.gz: c54ca691f2fc452e0a3d7865a91542f7214c2a430fd4959f8c825866f5bb18c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b36800f1d49b5c3eb0c6a8a81b06bf123bc5a051851576a41c3db4ebd4335bde92b60f34d5d674a4c34305c4197d42b09420cc9ecd940c36c2fbff950022fb5
|
7
|
+
data.tar.gz: 40f6f44ff3c4f7593e473260f26effeac3047e3342aad0d3e6264f83dc0fb9d45551342a8682323f5629a4944a89d4de0178f92f526766a7edb1b5aa535c717f
|
data/.rspec
CHANGED
data/lib/onebox/engine.rb
CHANGED
@@ -28,23 +28,19 @@ module Onebox
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
attr_reader :url, :uri
|
32
|
-
attr_reader :timeout
|
31
|
+
attr_reader :url, :uri, :options, :timeout
|
33
32
|
attr :errors
|
34
33
|
|
35
34
|
DEFAULT = {}
|
36
|
-
def options
|
37
|
-
@options
|
38
|
-
end
|
39
35
|
|
40
36
|
def options=(opt)
|
41
|
-
return @options if opt.nil? #make sure options provided
|
42
|
-
opt = opt.to_h
|
37
|
+
return @options if opt.nil? # make sure options provided
|
38
|
+
opt = opt.to_h if opt.instance_of?(OpenStruct)
|
43
39
|
@options.merge!(opt)
|
44
40
|
@options
|
45
41
|
end
|
46
42
|
|
47
|
-
def initialize(
|
43
|
+
def initialize(url, timeout = nil)
|
48
44
|
@errors = {}
|
49
45
|
@options = DEFAULT
|
50
46
|
class_name = self.class.name.split("::").last.to_s
|
@@ -52,8 +48,8 @@ module Onebox
|
|
52
48
|
# Set the engine options extracted from global options.
|
53
49
|
self.options = Onebox.options[class_name] || {}
|
54
50
|
|
55
|
-
@url =
|
56
|
-
@uri = URI(
|
51
|
+
@url = url
|
52
|
+
@uri = URI(url)
|
57
53
|
if always_https?
|
58
54
|
@uri.scheme = 'https'
|
59
55
|
@url = @uri.to_s
|
@@ -136,7 +132,7 @@ module Onebox
|
|
136
132
|
end
|
137
133
|
|
138
134
|
def always_https?
|
139
|
-
@https
|
135
|
+
defined?(@https) ? @https : false
|
140
136
|
end
|
141
137
|
end
|
142
138
|
end
|
@@ -27,7 +27,6 @@ module Onebox
|
|
27
27
|
500px.com
|
28
28
|
8tracks.com
|
29
29
|
abc.net.au
|
30
|
-
about.com
|
31
30
|
answers.com
|
32
31
|
arstechnica.com
|
33
32
|
ask.com
|
@@ -36,11 +35,9 @@ module Onebox
|
|
36
35
|
bbs.boingboing.net
|
37
36
|
bestbuy.ca
|
38
37
|
bestbuy.com
|
39
|
-
blip.tv
|
40
38
|
bloomberg.com
|
41
39
|
businessinsider.com
|
42
40
|
change.org
|
43
|
-
clikthrough.com
|
44
41
|
cnet.com
|
45
42
|
cnn.com
|
46
43
|
codepen.io
|
@@ -90,7 +87,6 @@ module Onebox
|
|
90
87
|
meetup.com
|
91
88
|
mixcloud.com
|
92
89
|
mlb.com
|
93
|
-
myshopify.com
|
94
90
|
myspace.com
|
95
91
|
nba.com
|
96
92
|
npr.org
|
@@ -98,16 +94,13 @@ module Onebox
|
|
98
94
|
photobucket.com
|
99
95
|
pinterest.com
|
100
96
|
reference.com
|
101
|
-
revision3.com
|
102
97
|
rottentomatoes.com
|
103
98
|
samsung.com
|
104
|
-
screenr.com
|
105
99
|
scribd.com
|
106
100
|
slideshare.net
|
107
101
|
sourceforge.net
|
108
102
|
speakerdeck.com
|
109
103
|
spotify.com
|
110
|
-
squidoo.com
|
111
104
|
streamable.com
|
112
105
|
techcrunch.com
|
113
106
|
ted.com
|
@@ -124,7 +117,6 @@ module Onebox
|
|
124
117
|
twitpic.com
|
125
118
|
usatoday.com
|
126
119
|
viddler.com
|
127
|
-
videojug.com
|
128
120
|
vine.co
|
129
121
|
walmart.com
|
130
122
|
washingtonpost.com
|
@@ -275,7 +267,6 @@ module Onebox
|
|
275
267
|
|
276
268
|
def rewrite_https(html)
|
277
269
|
return unless html
|
278
|
-
uri = URI(@url)
|
279
270
|
if AllowlistedGenericOnebox.host_matches(uri, AllowlistedGenericOnebox.rewrites)
|
280
271
|
html = html.gsub("http://", "https://")
|
281
272
|
end
|
@@ -374,15 +365,17 @@ module Onebox
|
|
374
365
|
escaped_image_src = ::Onebox::Helpers.normalize_url_for_output(data[:image])
|
375
366
|
|
376
367
|
<<-HTML
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
368
|
+
<video
|
369
|
+
title='#{data[:title]}'
|
370
|
+
width='#{data[:video_width]}'
|
371
|
+
height='#{data[:video_height]}'
|
372
|
+
style='max-width:100%'
|
373
|
+
poster='#{escaped_image_src}'
|
374
|
+
controls=''
|
375
|
+
>
|
376
|
+
<source src='#{escaped_video_src}'>
|
377
|
+
</video>
|
378
|
+
HTML
|
386
379
|
end
|
387
380
|
|
388
381
|
def embedded_html
|
@@ -14,13 +14,13 @@ module Onebox
|
|
14
14
|
matches_regexp(/^https?:\/\/(?:www\.)?(?:smile\.)?(amazon|amzn)\.(?<tld>com|ca|de|it|es|fr|co\.jp|co\.uk|cn|in|com\.br|com\.mx|nl|pl|sa|sg|se|com\.tr|ae)\//)
|
15
15
|
|
16
16
|
def url
|
17
|
+
@raw ||= nil
|
18
|
+
|
17
19
|
# If possible, fetch the cached HTML body immediately so we can
|
18
20
|
# try to grab the canonical URL from that document,
|
19
21
|
# rather than guess at the best URL structure to use
|
20
|
-
if
|
21
|
-
|
22
|
-
@raw ||= Onebox::Helpers.fetch_html_doc(@url, http_params, body_cacher)
|
23
|
-
end
|
22
|
+
if !@raw && has_cached_body
|
23
|
+
@raw = Onebox::Helpers.fetch_html_doc(@url, http_params, body_cacher)
|
24
24
|
end
|
25
25
|
|
26
26
|
if @raw
|
@@ -29,14 +29,15 @@ module Onebox
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if match && match[:id]
|
32
|
-
|
32
|
+
id = Addressable::URI.encode_component(match[:id], Addressable::URI::CharacterClasses::PATH)
|
33
|
+
return "https://www.amazon.#{tld}/dp/#{id}"
|
33
34
|
end
|
34
35
|
|
35
36
|
@url
|
36
37
|
end
|
37
38
|
|
38
39
|
def tld
|
39
|
-
@tld
|
40
|
+
@tld ||= @@matcher.match(@url)["tld"]
|
40
41
|
end
|
41
42
|
|
42
43
|
def http_params
|
@@ -47,6 +48,12 @@ module Onebox
|
|
47
48
|
|
48
49
|
private
|
49
50
|
|
51
|
+
def has_cached_body
|
52
|
+
body_cacher&.respond_to?('cache_response_body?') &&
|
53
|
+
body_cacher.cache_response_body?(uri.to_s) &&
|
54
|
+
body_cacher.cached_response_body_exists?(uri.to_s)
|
55
|
+
end
|
56
|
+
|
50
57
|
def match
|
51
58
|
@match ||= @url.match(/(?:d|g)p\/(?:product\/|video\/detail\/)?(?<id>[A-Z0-9]+)(?:\/|\?|$)/mi)
|
52
59
|
end
|
@@ -55,9 +62,9 @@ module Onebox
|
|
55
62
|
if (main_image = raw.css("#main-image")) && main_image.any?
|
56
63
|
attributes = main_image.first.attributes
|
57
64
|
|
58
|
-
|
59
|
-
|
60
|
-
|
65
|
+
if attributes["data-a-hires"]
|
66
|
+
return attributes["data-a-hires"].to_s
|
67
|
+
elsif attributes["data-a-dynamic-image"]
|
61
68
|
return ::JSON.parse(attributes["data-a-dynamic-image"].value).keys.first
|
62
69
|
end
|
63
70
|
end
|
@@ -65,9 +72,11 @@ module Onebox
|
|
65
72
|
if (landing_image = raw.css("#landingImage")) && landing_image.any?
|
66
73
|
attributes = landing_image.first.attributes
|
67
74
|
|
68
|
-
|
69
|
-
|
70
|
-
|
75
|
+
if attributes["data-old-hires"]
|
76
|
+
return attributes["data-old-hires"].to_s
|
77
|
+
else
|
78
|
+
return landing_image.first["src"].to_s
|
79
|
+
end
|
71
80
|
end
|
72
81
|
|
73
82
|
if (ebook_image = raw.css("#ebooksImgBlkFront")) && ebook_image.any?
|
@@ -89,16 +98,16 @@ module Onebox
|
|
89
98
|
end
|
90
99
|
|
91
100
|
def multiple_authors(authors_xpath)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
101
|
+
raw
|
102
|
+
.xpath(authors_xpath)
|
103
|
+
.map { |a| a.inner_text.strip }
|
104
|
+
.join(", ")
|
96
105
|
end
|
97
106
|
|
98
107
|
def data
|
99
108
|
og = ::Onebox::OpenGraph.new(raw)
|
100
109
|
|
101
|
-
if raw.at_css('#dp.book_mobile') #printed books
|
110
|
+
if raw.at_css('#dp.book_mobile') # printed books
|
102
111
|
title = raw.at("h1#title")&.inner_text
|
103
112
|
authors = raw.at_css('#byline_secondary_view_div') ? multiple_authors("//div[@id='byline_secondary_view_div']//span[@class='a-text-bold']") : raw.at("#byline")&.inner_text
|
104
113
|
rating = raw.at("#averageCustomerReviews_feature_div .a-icon")&.inner_text || raw.at("#cmrsArcLink .a-icon")&.inner_text
|
@@ -13,14 +13,17 @@ module Onebox
|
|
13
13
|
oembed = get_oembed
|
14
14
|
|
15
15
|
<<-HTML
|
16
|
-
<img
|
16
|
+
<img
|
17
|
+
src="#{oembed.thumbnail_url}"
|
18
|
+
style="max-width: #{oembed.width}px; max-height: #{oembed.height}px;"
|
19
|
+
#{oembed.title_attr}
|
20
|
+
>
|
17
21
|
HTML
|
18
22
|
end
|
19
23
|
|
20
24
|
def to_html
|
21
25
|
get_oembed.html
|
22
26
|
end
|
23
|
-
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
@@ -20,16 +20,16 @@ module Onebox
|
|
20
20
|
escaped_src = og.video_secure_url || og.video
|
21
21
|
|
22
22
|
<<-HTML
|
23
|
-
<iframe
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
<iframe
|
24
|
+
src="#{escaped_src}"
|
25
|
+
width="#{og.video_width}"
|
26
|
+
height="#{og.video_height}"
|
27
|
+
scrolling="no"
|
28
|
+
frameborder="0"
|
29
|
+
allowfullscreen
|
30
|
+
></iframe>
|
30
31
|
HTML
|
31
32
|
end
|
32
|
-
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -25,28 +25,28 @@ module Onebox
|
|
25
25
|
|
26
26
|
def link_html(og)
|
27
27
|
<<-HTML
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
<a href='#{og.url}' target='_blank' rel='noopener'>
|
29
|
+
#{og.title}
|
30
|
+
</a>
|
31
|
+
HTML
|
32
32
|
end
|
33
33
|
|
34
34
|
def video_html(og)
|
35
35
|
direct_src = ::Onebox::Helpers.normalize_url_for_output("#{og.get(:url)}/#{og.title}")
|
36
36
|
|
37
37
|
<<-HTML
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
<video width='480' height='360' #{og.title_attr} controls loop>
|
39
|
+
<source src='#{direct_src}' type='video/mp4'>
|
40
|
+
</video>
|
41
|
+
HTML
|
42
42
|
end
|
43
43
|
|
44
44
|
def image_html(og)
|
45
45
|
<<-HTML
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
<a href='#{og.url}' target='_blank' class='onebox' rel='noopener'>
|
47
|
+
<img src='#{og.image}' #{og.title_attr} alt='CloudApp' width='480'>
|
48
|
+
</a>
|
49
|
+
HTML
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -14,13 +14,14 @@ module Onebox
|
|
14
14
|
metadata = get_twitter
|
15
15
|
if metadata.present? && metadata[:card] == "player" && metadata[:player].present?
|
16
16
|
<<-HTML
|
17
|
-
<iframe
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
<iframe
|
18
|
+
src="#{metadata[:player]}"
|
19
|
+
width="#{metadata[:player_width]}"
|
20
|
+
height="#{metadata[:player_height]}"
|
21
|
+
scrolling="no"
|
22
|
+
frameborder="0"
|
23
|
+
allowfullscreen
|
24
|
+
></iframe>
|
24
25
|
HTML
|
25
26
|
else
|
26
27
|
html = Onebox::Engine::AllowlistedGenericOnebox.new(@url, @timeout).to_html
|
@@ -25,29 +25,28 @@ module Onebox
|
|
25
25
|
album_title = "[Album] #{og.title}"
|
26
26
|
|
27
27
|
<<-HTML
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
</span>
|
28
|
+
<div class='onebox flickr-album'>
|
29
|
+
<a href='#{escaped_url}' target='_blank' rel='noopener'>
|
30
|
+
<span class='outer-box' style='max-width:#{og.image_width}px'>
|
31
|
+
<span class='inner-box'>
|
32
|
+
<span class='album-title'>#{album_title}</span>
|
34
33
|
</span>
|
35
|
-
|
36
|
-
|
37
|
-
</
|
38
|
-
|
34
|
+
</span>
|
35
|
+
<img src='#{og.secure_image_url}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
|
36
|
+
</a>
|
37
|
+
</div>
|
38
|
+
HTML
|
39
39
|
end
|
40
40
|
|
41
41
|
def image_html(og)
|
42
42
|
escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
|
43
43
|
|
44
44
|
<<-HTML
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
<a href='#{escaped_url}' target='_blank' rel='noopener' class="onebox">
|
46
|
+
<img src='#{og.secure_image_url}' #{og.title_attr} alt='Imgur' height='#{og.image_height}' width='#{og.image_width}'>
|
47
|
+
</a>
|
48
|
+
HTML
|
49
49
|
end
|
50
|
-
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
@@ -9,8 +9,8 @@ module Onebox
|
|
9
9
|
matches_regexp(/^https?:\/\/gfycat\.com\//)
|
10
10
|
always_https
|
11
11
|
|
12
|
+
# This engine should have priority over AllowlistedGenericOnebox.
|
12
13
|
def self.priority
|
13
|
-
# This engine should have priority over AllowlistedGenericOnebox.
|
14
14
|
1
|
15
15
|
end
|
16
16
|
|
@@ -21,6 +21,7 @@ module Onebox
|
|
21
21
|
<img src="https://gfycat.com/static/favicons/favicon-96x96.png" class="site-icon" width="64" height="64">
|
22
22
|
<a href="#{data[:url]}" target="_blank" rel="nofollow ugc noopener">Gfycat.com</a>
|
23
23
|
</header>
|
24
|
+
|
24
25
|
<article class="onebox-body">
|
25
26
|
<h4>
|
26
27
|
#{data[:title]} by
|
@@ -36,11 +37,12 @@ module Onebox
|
|
36
37
|
<img title="Sorry, your browser doesn't support HTML5 video." src="#{data[:posterUrl]}">
|
37
38
|
</video>
|
38
39
|
</div>
|
40
|
+
|
39
41
|
<p>
|
40
42
|
<span class="label1">#{data[:keywords]}</span>
|
41
43
|
</p>
|
42
|
-
|
43
44
|
</article>
|
45
|
+
|
44
46
|
<div style="clear: both"></div>
|
45
47
|
</aside>
|
46
48
|
HTML
|
@@ -61,52 +63,50 @@ module Onebox
|
|
61
63
|
@match ||= @url.match(/^https?:\/\/gfycat\.com\/(gifs\/detail\/)?(?<name>.+)/)
|
62
64
|
end
|
63
65
|
|
64
|
-
def
|
65
|
-
@
|
66
|
-
response = Onebox::Helpers.fetch_response(url, redirect_limit: 10) rescue nil
|
67
|
-
Nokogiri::HTML(response)
|
68
|
-
end
|
69
|
-
end
|
66
|
+
def og_data
|
67
|
+
return @og_data if defined?(@og_data)
|
70
68
|
|
71
|
-
|
72
|
-
|
69
|
+
response = Onebox::Helpers.fetch_response(url, redirect_limit: 10) rescue nil
|
70
|
+
page = Nokogiri::HTML(response)
|
71
|
+
script = page.at_css('script[type="application/ld+json"]')
|
73
72
|
|
74
|
-
if json_string =
|
75
|
-
og_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(json_string))
|
73
|
+
if json_string = script&.text
|
74
|
+
@og_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(json_string))
|
75
|
+
else
|
76
|
+
@og_data = {}
|
76
77
|
end
|
77
|
-
|
78
|
-
og_data
|
79
78
|
end
|
80
79
|
|
81
80
|
def data
|
82
|
-
|
81
|
+
return @data if defined?(@data)
|
83
82
|
|
84
|
-
|
83
|
+
@data = {
|
85
84
|
name: match[:name],
|
86
85
|
title: og_data[:headline] || 'No Title',
|
87
86
|
author: og_data[:author],
|
88
|
-
url: @url
|
87
|
+
url: @url,
|
89
88
|
}
|
90
89
|
|
91
|
-
keywords = og_data[:keywords]&.split(',')
|
92
|
-
|
93
|
-
|
90
|
+
if keywords = og_data[:keywords]&.split(',')
|
91
|
+
@data[:keywords] = keywords
|
92
|
+
.map { |keyword| "<a href='https://gfycat.com/gifs/search/#{keyword}'>##{keyword}</a>" }
|
93
|
+
.join(' ')
|
94
94
|
end
|
95
95
|
|
96
96
|
if og_data[:video]
|
97
97
|
content_url = ::Onebox::Helpers.normalize_url_for_output(og_data[:video][:contentUrl])
|
98
98
|
video_url = Pathname.new(content_url)
|
99
|
-
|
100
|
-
|
99
|
+
@data[:webmUrl] = video_url.sub_ext(".webm").to_s
|
100
|
+
@data[:mp4Url] = video_url.sub_ext(".mp4").to_s
|
101
101
|
|
102
102
|
thumbnail_url = ::Onebox::Helpers.normalize_url_for_output(og_data[:video][:thumbnailUrl])
|
103
|
-
|
103
|
+
@data[:posterUrl] = thumbnail_url
|
104
104
|
|
105
|
-
|
106
|
-
|
105
|
+
@data[:width] = og_data[:video][:width]
|
106
|
+
@data[:height] = og_data[:video][:height]
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
@data
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|