onebox 1.8.69 → 1.8.70

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
  SHA256:
3
- metadata.gz: 98a0701ca393ddadda7d9d38abcd9d99b2d9fbdfec7a18643b106adfddf45ad7
4
- data.tar.gz: 699090849c9ac55d0362b3785f8d4a447c509bd7a47cc4d2ee6ae79ee0f869db
3
+ metadata.gz: 99bd6b866e7a0fb25a4d4571d9a5b0f77ab1ef6c191e0e1dd10572a315466d8f
4
+ data.tar.gz: ea87f0ca618a4d00924a52ed32efe00c922ec8e13d52b443ea230425573754f0
5
5
  SHA512:
6
- metadata.gz: 3f474fc31092624d6d00062167334fcf2a61fb85b2da6075d73ed74ef34ffbc9561fd74d1d2b467410cec9c72c16f1fad863320646980422da544c40c2c16b67
7
- data.tar.gz: 204da8eaac3fa2fef4fdbb39b0b470807eba0c2fa969bcd4d9168739e07fc5ff2e5d9c868632621ff7bdd879c9a0c6d3adeeb2af935e2d996aff4e137723386c
6
+ metadata.gz: 4a72e75cf77b783ba9c787d8e2f6c95d13d9a0b842ec88e80d6080ef290bb24ee5464d55549c5ba0e4cbfb3d0fd93e12a33eab1e9ff868ee3f0181444db732fc
7
+ data.tar.gz: 550c34c0dc9fba9ca6b03100721beb1b3b6a5b643fa43d515b947d6cc75f0f46deb3d9a409b4a90cccdaef0e6369feb673eab583575f4b5d497eec695a4045b3
@@ -12,10 +12,6 @@ module Onebox
12
12
  1
13
13
  end
14
14
 
15
- def url
16
- "https://gfycat.com/cajax/get/#{match[:name]}"
17
- end
18
-
19
15
  def to_html
20
16
  <<-HTML
21
17
  <aside class="onebox gfycat">
@@ -32,14 +28,14 @@ module Onebox
32
28
  </h4>
33
29
 
34
30
  <div class="video">
35
- <video controls loop #{data[:autoplay]} muted poster="#{data[:posterUrl]}" style="--aspect-ratio: #{data[:width]}/#{data[:height]}">
31
+ <video controls loop muted poster="#{data[:posterUrl]}" style="--aspect-ratio: #{data[:width]}/#{data[:height]}">
36
32
  <source id="webmSource" src="#{data[:webmUrl]}" type="video/webm">
37
33
  <source id="mp4Source" src="#{data[:mp4Url]}" type="video/mp4">
38
34
  <img title="Sorry, your browser doesn't support HTML5 video." src="#{data[:posterUrl]}">
39
35
  </video>
40
36
  </div>
41
37
  <p>
42
- <span class="label1">#{data[:tags]}</span>
38
+ <span class="label1">#{data[:keywords]}</span>
43
39
  </p>
44
40
 
45
41
  </article>
@@ -51,7 +47,7 @@ module Onebox
51
47
  <<-HTML
52
48
  <a href="#{data[:url]}">
53
49
  <img src="#{data[:posterUrl]}" width="#{data[:width]}" height="#{data[:height]}"><br/>
54
- #{data[:gfyName]}
50
+ #{data[:name]}
55
51
  </a>
56
52
  HTML
57
53
  end
@@ -62,27 +58,53 @@ module Onebox
62
58
  @match ||= @url.match(/^https?:\/\/gfycat\.com\/(gifs\/detail\/)?(?<name>.+)/)
63
59
  end
64
60
 
61
+ def nokogiri_page
62
+ @nokogiri_page ||= begin
63
+ response = Onebox::Helpers.fetch_response(url, 10) rescue nil
64
+ Nokogiri::HTML(response)
65
+ end
66
+ end
67
+
68
+ def get_og_data
69
+ og_data = {}
70
+
71
+ if json_string = nokogiri_page.at_css('script[type="application/ld+json"]')&.text
72
+ og_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(json_string))
73
+ end
74
+
75
+ og_data
76
+ end
77
+
65
78
  def data
79
+ og_data = get_og_data
66
80
 
67
- total_tags = [raw['gfyItem']['tags'], raw['gfyItem']['userTags']].flatten.compact
68
- tag_links = total_tags.map { |t| "<a href='https://gfycat.com/gifs/search/#{t}'>##{t}</a>" }.join(' ') if total_tags
69
- autoplay = raw['gfyItem']['webmSize'].to_i < 10485760 ? 'autoplay' : ''
70
-
71
- {
72
- name: raw['gfyItem']['gfyName'],
73
- title: raw['gfyItem']['title'] || 'No Title',
74
- author: raw['gfyItem']['userName'],
75
- tags: tag_links,
76
- url: @url,
77
- posterUrl: raw['gfyItem']['posterUrl'],
78
- webmUrl: raw['gfyItem']['webmUrl'],
79
- mp4Url: raw['gfyItem']['mp4Url'],
80
- width: raw['gfyItem']['width'],
81
- height: raw['gfyItem']['height'],
82
- autoplay: autoplay
81
+ response = {
82
+ name: match[:name],
83
+ title: og_data[:headline] || 'No Title',
84
+ author: og_data[:author],
85
+ url: @url
83
86
  }
84
- end
85
87
 
88
+ keywords = og_data[:keywords]&.split(',')
89
+ if keywords
90
+ response[:keywords] = keywords.map { |t| "<a href='https://gfycat.com/gifs/search/#{t}'>##{t}</a>" }.join(' ')
91
+ end
92
+
93
+ if og_data[:video]
94
+ content_url = ::Onebox::Helpers.normalize_url_for_output(og_data[:video][:contentUrl])
95
+ video_url = Pathname.new(content_url)
96
+ response[:webmUrl] = video_url.sub_ext(".webm").to_s
97
+ response[:mp4Url] = video_url.sub_ext(".mp4").to_s
98
+
99
+ thumbnail_url = ::Onebox::Helpers.normalize_url_for_output(og_data[:video][:thumbnailUrl])
100
+ response[:posterUrl] = thumbnail_url
101
+
102
+ response[:width] = og_data[:video][:width]
103
+ response[:height] = og_data[:video][:height]
104
+ end
105
+
106
+ response
107
+ end
86
108
  end
87
109
  end
88
110
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onebox
4
- VERSION = "1.8.69"
4
+ VERSION = "1.8.70"
5
5
  end
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: 1.8.69
4
+ version: 1.8.70
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: 2018-12-13 00:00:00.000000000 Z
13
+ date: 2018-12-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -414,7 +414,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
414
414
  version: '0'
415
415
  requirements: []
416
416
  rubyforge_project:
417
- rubygems_version: 2.7.8
417
+ rubygems_version: 2.7.6
418
418
  signing_key:
419
419
  specification_version: 4
420
420
  summary: A gem for generating embeddable HTML previews from URLs.