yt-annotations 1.4.2 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e90f02ea969bbc11df732a40a5e2f943b24507f1
4
- data.tar.gz: 05bbc8a4ba7fb944e4e77cd211406cdd4fa07b3c
3
+ metadata.gz: b130653190cc8af5a6d295992c1cccb9808479a8
4
+ data.tar.gz: cab1d2dc04906c8eb8dd614f784042bd292c3dc4
5
5
  SHA512:
6
- metadata.gz: 8a20ea07b37fb8e6a6545dc49233084907f368fbb01265b1f95bedb86e046fa438f370cda210f8e0e22c663e757731d269e52232804c9bd0fc601eeeda7b13c6
7
- data.tar.gz: 2d3675386a5c15030081f27b4f4d27dfddce214166a10f397e74cf17f3b54f5637625dd04ab0a722182c9e0628102c37cbfd13d4e59c9f84f3cdd9835dd40199
6
+ metadata.gz: a4323711e52413a2684b820f16335c37f4072a0b124b210c81e0b4bfe6e541b6c75c80979fc185719244d3061a74450c7ab6cda7041c0c687889dc8ca180130b
7
+ data.tar.gz: 4c2033365f7ac3c806e769dfaa9ca12e793f4b8e68590b011e4e5011a04039c5c5f0ebec712942becded609ce427b5381c5c6d037c6c2513629be94575ebd372
@@ -6,6 +6,16 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 2.0.0 - 2018.02.08
10
+
11
+ **How to upgrade**
12
+
13
+ If your code calls `Yt::Annotation::Featured` object, you should not use it because it is removed.
14
+
15
+ * [REMOVAL] Remove Yt::Annotation::Featured annotation because YouTube removed it (as of 12-14-2017).
16
+ https://developers.google.com/youtube/v3/revision_history?id=november-27-2017
17
+ * [BUGFIX] Do not raise errors from end screens with different URL format
18
+ * [ENHANCEMENT] Fetch 'promotion' type annotation without errors.
9
19
 
10
20
  ## 1.4.2 - 2017.05.24
11
21
 
@@ -16,11 +16,7 @@ module Yt
16
16
  private
17
17
 
18
18
  def text_in(json)
19
- if json['title']['runs'].nil?
20
- json['title']['simpleText']
21
- else
22
- json['title']['runs'][0]['text']
23
- end
19
+ json['title']['simpleText']
24
20
  end
25
21
 
26
22
  def ends_at_in(json)
@@ -32,13 +28,21 @@ module Yt
32
28
  when 'WEBSITE'
33
29
  json['endpoint']['urlEndpoint']['url']
34
30
  when 'PLAYLIST'
35
- "https://www.youtube.com/watch?v=" +
36
- json['endpoint']['watchEndpoint']['videoId'] +
37
- "&list=" +
38
- json['endpoint']['watchEndpoint']['playlistId']
31
+ if json['endpoint']['watchEndpoint']
32
+ "https://www.youtube.com/watch?v=" +
33
+ json['endpoint']['watchEndpoint']['videoId'] +
34
+ "&list=" +
35
+ json['endpoint']['watchEndpoint']['playlistId']
36
+ else
37
+ "https://www.youtube.com" + json['endpoint']['urlEndpoint']['url']
38
+ end
39
39
  when 'VIDEO'
40
- "https://www.youtube.com/watch?v=" +
41
- json['endpoint']['watchEndpoint']['videoId']
40
+ if json['endpoint']['watchEndpoint']
41
+ "https://www.youtube.com/watch?v=" +
42
+ json['endpoint']['watchEndpoint']['videoId']
43
+ else
44
+ "https://www.youtube.com" + json['endpoint']['urlEndpoint']['url']
45
+ end
42
46
  when 'CHANNEL'
43
47
  if json['isSubscribe']
44
48
  "https://www.youtube.com/channel/" +
@@ -1,13 +1,13 @@
1
1
  require 'yt/annotations/branding'
2
2
  require 'yt/annotations/card'
3
3
  require 'yt/annotations/end_screen'
4
- require 'yt/annotations/featured'
5
4
  require 'yt/annotations/label'
6
5
  require 'yt/annotations/note'
7
6
  require 'yt/annotations/speech'
8
7
  require 'yt/annotations/spotlight'
9
8
  require 'yt/annotations/title'
10
9
  require 'yt/annotations/pause'
10
+ require 'yt/annotations/promotion'
11
11
 
12
12
  # An object-oriented Ruby client for YouTube.
13
13
  # @see http://www.rubydoc.info/gems/yt/
@@ -64,8 +64,8 @@ module Yt
64
64
  when 'title' then Annotations::Title
65
65
  else case data['type']
66
66
  when 'card' then Annotations::Card
67
- when 'promotion' then Annotations::Featured
68
67
  when 'pause' then Annotations::Pause
68
+ when 'promotion' then Annotations::Promotion
69
69
  end
70
70
  end
71
71
  end
@@ -35,7 +35,6 @@ module Yt
35
35
  when '5' then :subscribe
36
36
  when '6' then :website
37
37
  when '8' then :crowdfunding
38
- when '12' then :website
39
38
  end
40
39
  {url: url['value'], new_window: new_window, type: type}
41
40
  end
@@ -0,0 +1,30 @@
1
+ require 'yt/annotations/base'
2
+
3
+ module Yt
4
+ module Annotations
5
+ # A Promotion annotation. The CTA overlay is used more for paid campaigns
6
+ # because the video has to be attached to an adsense account to be used.
7
+ class Promotion < Base
8
+ # @param [Hash] data the Hash representation of the XML data returned by
9
+ # YouTube for each annotation of a video.
10
+ def initialize(data = {})
11
+ json = JSON.parse data['data']
12
+ @text = text_in json
13
+ @starts_at = json['start_ms'].to_i / 1000.0
14
+ @ends_at = json['end_ms'].to_i / 1000.0
15
+ @link = to_link data.fetch('action', {})['url'], data
16
+ end
17
+
18
+ private
19
+
20
+ def text_in(json)
21
+ json.values_at('text_line_1', 'text_line_2').join(': ')
22
+ end
23
+
24
+ def to_link(url, data)
25
+ new_window = url['target'] == 'new'
26
+ {url: url['value'], new_window: new_window, type: :website}
27
+ end
28
+ end
29
+ end
30
+ end
@@ -3,6 +3,6 @@ module Yt
3
3
  module Annotations
4
4
  # @return [String] the SemVer-compatible gem version.
5
5
  # @see http://semver.org
6
- VERSION = '1.4.2'
6
+ VERSION = '2.0.0'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt-annotations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-05-24 00:00:00.000000000 Z
12
+ date: 2018-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -140,11 +140,11 @@ files:
140
140
  - lib/yt/annotations/branding.rb
141
141
  - lib/yt/annotations/card.rb
142
142
  - lib/yt/annotations/end_screen.rb
143
- - lib/yt/annotations/featured.rb
144
143
  - lib/yt/annotations/for.rb
145
144
  - lib/yt/annotations/label.rb
146
145
  - lib/yt/annotations/note.rb
147
146
  - lib/yt/annotations/pause.rb
147
+ - lib/yt/annotations/promotion.rb
148
148
  - lib/yt/annotations/speech.rb
149
149
  - lib/yt/annotations/spotlight.rb
150
150
  - lib/yt/annotations/title.rb
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  requirements: []
172
172
  rubyforge_project:
173
- rubygems_version: 2.6.12
173
+ rubygems_version: 2.6.13
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Fetch annotations and cards from YouTube videos.
@@ -1,32 +0,0 @@
1
- require 'yt/annotations/card'
2
-
3
- module Yt
4
- module Annotations
5
- # A Featured annotation is similar to a card, except that it displays in
6
- # the bottom-left corner and only shows if no cards are present.
7
- class Featured < Card
8
- private
9
- def text_in(json)
10
- json.values_at('text_line_1', 'text_line_2').join(': ')
11
- end
12
-
13
- def ends_at_in(data)
14
- data['end_ms'] / 1000.0
15
- end
16
-
17
- def to_link(data, json)
18
- return unless url = data.fetch('action', {})['url']
19
- new_window = url['target'] != 'current'
20
- {url: url['value'], new_window: new_window, type: link_type(json)}
21
- end
22
-
23
- def link_type(json)
24
- if json['playlist_length']
25
- :playlist
26
- elsif json['video_duration']
27
- :video
28
- end
29
- end
30
- end
31
- end
32
- end