yt-audit 0.1.5 → 0.2.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: 8594dc0bf20e108d230961aad4e689b71876b03f
4
- data.tar.gz: 3878206cdf83f73895f035ff08077030e425faae
3
+ metadata.gz: 7da22a57ea6de80903cdfaedc43242975109e22b
4
+ data.tar.gz: 3e77764bc854359f62880bc4576a7ac86e667ac9
5
5
  SHA512:
6
- metadata.gz: c63cbc249217242755ae6b86a8dfba002c0106531e5377643476755808794933b1ef925b6c3d5ce43b561d7a29a992bfcee5d3670c00027acd4c644443e460b8
7
- data.tar.gz: 0f3c9ae069730d1f232431cd66540c75f55367a85846c6bad898ef9801b1828b4074ef3c6de3990c84870f61e28754a9f15c23637f9c54aade640049d0887c87
6
+ metadata.gz: 999786ef7ebdccbcbafe39c075105db541b5f6292022b2505d2e7df6fbde93dbfbcef176529de0b425f4b01b6ed8526fbe535142deab875b2ae1cfb6f7a4d42d
7
+ data.tar.gz: b0219b654d9e6a59bcec46a554690d1e7ce433b88f9374724ed45b9aa672564ab6ae59ce54630f955ad69e1ee72776915d8aac2c4275da5c418cd927030f2f9d
data/CHANGELOG.md CHANGED
@@ -6,6 +6,19 @@ 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
+ ## 0.2.0 - 2016.02.18
10
+
11
+ **How to upgrade**
12
+
13
+ If your code calls any of `has_end_cards?`, `has_link_to_own_channel?`, `has_subscribe_annotations?`, `has_brand_anchoring?`, or `has_info_cards?` method with a video id, they are removed. Instead, call `run` method from a `Yt::Audit` instance to get information of a channel.
14
+
15
+ * [FEATURE] Add `run` method to audit a channel and count how many videos have each audit subject out of its recent 10 videos.
16
+ * [REMOVAL] Remove `has_end_cards?`
17
+ * [REMOVAL] Remove `has_link_to_own_channel?`
18
+ * [REMOVAL] Remove `has_subscribe_annotations?`
19
+ * [REMOVAL] Remove `has_brand_anchoring?`
20
+ * [REMOVAL] Remove `has_info_cards?`
21
+
9
22
  ## 0.1.5 - 2016.02.17
10
23
 
11
24
  * [BUGFIX] Fix `has_end_cards?` for cases when Float `ends_at` is
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Yt::Audit
2
2
 
3
- Welcome! This is a Ruby library you can audit a YouTube video.
3
+ Welcome! This is a Ruby library you can audit a YouTube channel.
4
4
 
5
5
  The **source code** is available on [GitHub](https://github.com/Fullscreen/yt-audit) and the **documentation** on [RubyDoc](http://www.rubydoc.info/github/fullscreen/yt-audit/master/Yt/Audit).
6
6
 
@@ -16,7 +16,7 @@ The **source code** is available on [GitHub](https://github.com/Fullscreen/yt-au
16
16
 
17
17
  $ bin/setup
18
18
 
19
- $ YT_API_KEY="123456789012345678901234567890" rake
19
+ $ YT_API_KEY="123456789012345678901234567890123456789" rake
20
20
  $ open coverage/index.html
21
21
 
22
22
  $ yardoc
@@ -24,15 +24,26 @@ The **source code** is available on [GitHub](https://github.com/Fullscreen/yt-au
24
24
 
25
25
  ## Usage
26
26
 
27
+ `run` method returns an array of objects. It uses channel title as brand name, and 10 recent videos of channel, currently.
28
+
29
+ ```ruby
30
+ audit = Yt::Audit.new(channel_id: 'UCPCk_8dtVyR1lLHMBEILW4g')
31
+ # => #<Yt::Audit:0x007f94ec8050b0 @channel_id="UCPCk_8dtVyR1lLHMBEILW4g">
32
+ audit.run
33
+ # => [#<Yt::VideoAudit::InfoCard:0x007f94ec8c6f30 @videos=[...]>, #<Yt::VideoAudit::BrandAnchoring...>, #<Yt::VideoAudit::SubscribeAnnotation...>, #<Yt::VideoAudit::YoutubeAssociation...>, #<Yt::VideoAudit::EndCard...>]
34
+ ```
35
+
36
+ You can call four available methods `total_count`, `valid_count`, `title`, and `description` from each `Yt::VideoAudit` object.
37
+
27
38
  ```ruby
28
- Yt::Audit.has_info_cards?('rF711XAtrVg')
29
- # => true
30
- Yt::Audit.has_brand_anchoring?('rF711XAtrVg', 'Budweiser')
31
- # => true
32
- Yt::Audit.has_subscribe_annotations?('rF711XAtrVg')
33
- # => false
34
- Yt::Audit.has_link_to_own_channel?('rF711XAtrVg')
35
- # => false
36
- Yt::Audit.has_end_cards?('rF711XAtrVg')
37
- # => false
39
+ video_audit = audit.run[0]
40
+ # => #<Yt::VideoAudit::InfoCard:0x007f94ec979ab8 @videos=[...]>
41
+ video_audit.total_count
42
+ # => 10
43
+ video_audit.valid_count
44
+ # => 10
45
+ video_audit.title
46
+ # => "Info Cards"
47
+ video_audit.description
48
+ # => "The number of videos with an info card"
38
49
  ```
data/bin/yt-audit ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'yt/audit'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'yt/audit'
8
+ end
9
+
10
+ channel_id = ARGV[0] || 'UCKM-eG7PBcw3flaBvd0q2TQ'
11
+ audit = Yt::Audit.new(channel_id: channel_id)
12
+ puts "Channel: https://www.youtube.com/channel/#{channel_id}"
13
+ audit.run.each do |video_audit|
14
+ puts
15
+ puts "#{video_audit.description}"
16
+ puts "#{video_audit.title}: #{video_audit.valid_count} out of #{video_audit.total_count}"
17
+ end
18
+
data/lib/yt/audit.rb CHANGED
@@ -1,56 +1,35 @@
1
1
  require 'yt'
2
2
  require 'yt/annotations'
3
+ require 'yt/video_audit/info_card'
4
+ require 'yt/video_audit/brand_anchoring'
5
+ require 'yt/video_audit/subscribe_annotation'
6
+ require 'yt/video_audit/youtube_association'
7
+ require 'yt/video_audit/end_card'
3
8
 
4
9
  module Yt
5
- module Audit
6
- # Audit any info card of a video
7
- # @param [String] video_id the video to audit.
8
- # @return [Boolean] if the video has any info card.
9
- def self.has_info_cards?(video_id)
10
- Yt::Annotations.for(video_id).any? do |annotation|
11
- annotation.is_a? Yt::Annotations::Card
12
- end
10
+ class Audit
11
+ def initialize(channel_id:)
12
+ @channel_id = channel_id
13
13
  end
14
14
 
15
- # Audit brand anchoring of a video
16
- # @param [String] video_id the video to audit.
17
- # @param [String] brand name of the video to audit.
18
- # @return [Boolean] if the video title includes brand name.
19
- def self.has_brand_anchoring?(video_id, brand)
20
- video_title = Yt::Video.new(id: video_id).title
21
- !!video_title[/#{brand}/i]
15
+ def run
16
+ [
17
+ Yt::VideoAudit::InfoCard.new(videos: videos),
18
+ Yt::VideoAudit::BrandAnchoring.new(videos: videos, brand: channel.title),
19
+ Yt::VideoAudit::SubscribeAnnotation.new(videos: videos),
20
+ Yt::VideoAudit::YoutubeAssociation.new(videos: videos),
21
+ Yt::VideoAudit::EndCard.new(videos: videos)
22
+ ]
22
23
  end
23
24
 
24
- # Audit any subscribe annotation of a video
25
- # @param [String] video_id the video to audit.
26
- # @return [Boolean] if the video has any link to subscribe in the annotations.
27
- def self.has_subscribe_annotations?(video_id)
28
- Yt::Annotations.for(video_id).any? do |annotation|
29
- annotation.link && annotation.link[:type] == :subscribe
30
- end
31
- end
25
+ private
32
26
 
33
- # Audit youtube association of a video
34
- # @param [String] video_id the video to audit.
35
- # @return [Boolean] if the video description has link to its own channel.
36
- def self.has_link_to_own_channel?(video_id)
37
- video = Yt::Video.new(id: video_id)
38
- video.description.split(' ')
39
- .select {|word| Yt::URL.new(word).kind == :channel }
40
- .any? {|link| Yt::Channel.new(url: link).id == video.channel_id }
27
+ def videos
28
+ @videos ||= channel.videos.first 10
41
29
  end
42
30
 
43
- # Audit end cards of a video
44
- # @param [String] video_id of the video to audit.
45
- # @return [Boolean] if the video has any annotation, other than info cards,
46
- # with a link in it, at the end of video, stays for more than 5 seconds.
47
- def self.has_end_cards?(video_id)
48
- video_duration = Yt::Video.new(id: video_id).duration
49
- Yt::Annotations.for(video_id).any? do |annotation|
50
- !annotation.is_a?(Yt::Annotations::Card) && annotation.link &&
51
- (annotation.ends_at.floor..annotation.ends_at.ceil).include?(video_duration) &&
52
- video_duration - annotation.starts_at > 5
53
- end
31
+ def channel
32
+ @channel ||= Yt::Channel.new id: @channel_id
54
33
  end
55
34
  end
56
35
  end
@@ -1,5 +1,5 @@
1
1
  module Yt
2
- module Audit
3
- VERSION = "0.1.5"
2
+ class Audit
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,19 @@
1
+ module Yt
2
+ module VideoAudit
3
+ class Base
4
+ def initialize(options = {})
5
+ @videos = options[:videos]
6
+ end
7
+
8
+ # @return [Fixnum] number of all given videos.
9
+ def total_count
10
+ @videos.size
11
+ end
12
+
13
+ # @return [Fixnum] number of videos satisfy given condition.
14
+ def valid_count
15
+ @videos.count {|video| valid? video}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ require 'yt/video_audit/base'
2
+
3
+ module Yt
4
+ module VideoAudit
5
+ # Count how many subject videos include its brand name in the title.
6
+ class BrandAnchoring < Base
7
+ def initialize(options = {})
8
+ super
9
+ @brand = options[:brand]
10
+ end
11
+
12
+ def title
13
+ 'Brand Anchoring'
14
+ end
15
+
16
+ def description
17
+ 'The number of videos with the brand name in the title'
18
+ end
19
+
20
+ private
21
+
22
+ def valid?(video)
23
+ !!video.title[/#{@brand}/i]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ require 'yt/video_audit/base'
2
+
3
+ module Yt
4
+ module VideoAudit
5
+ # Count how many subject videos have any end card. An end card
6
+ # can be described as an annotation, not an info card, with a link in it,
7
+ # at the end of video, stays for more than 5 seconds.
8
+ class EndCard < Base
9
+ def title
10
+ 'Possible End Card Annotations'
11
+ end
12
+
13
+ def description
14
+ 'The number of videos with a link annotation'\
15
+ ' longer than 5 seconds, not an info card, at the end of its duration'
16
+ end
17
+
18
+ private
19
+
20
+ def valid?(video)
21
+ Yt::Annotations.for(video.id).any? do |annotation|
22
+ !annotation.is_a?(Yt::Annotations::Card) && annotation.link &&
23
+ (annotation.ends_at.floor..annotation.ends_at.ceil).include?(video.duration) &&
24
+ video.duration - annotation.starts_at > 5
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ require 'yt/video_audit/base'
2
+
3
+ module Yt
4
+ module VideoAudit
5
+ # Count how many subject videos have an info card.
6
+ class InfoCard < Base
7
+ def title
8
+ 'Info Cards'
9
+ end
10
+
11
+ def description
12
+ 'The number of videos with an info card'
13
+ end
14
+
15
+ private
16
+
17
+ def valid?(video)
18
+ Yt::Annotations.for(video.id).any? do |annotation|
19
+ annotation.is_a? Yt::Annotations::Card
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'yt/video_audit/base'
2
+
3
+ module Yt
4
+ module VideoAudit
5
+ # Count how many subject videos have an annotation
6
+ # with a subscribe link.
7
+ class SubscribeAnnotation < Base
8
+ def title
9
+ 'Subscribe Annotations'
10
+ end
11
+
12
+ def description
13
+ 'The number of videos with a link to subscribe in its annotations'
14
+ end
15
+
16
+ private
17
+
18
+ def valid?(video)
19
+ Yt::Annotations.for(video.id).any? do |annotation|
20
+ annotation.link && annotation.link[:type] == :subscribe
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'yt/video_audit/base'
2
+
3
+ module Yt
4
+ module VideoAudit
5
+ # Count how many videos have video description includes
6
+ # a link to its own channel.
7
+ class YoutubeAssociation < Base
8
+ def title
9
+ 'YouTube Association'
10
+ end
11
+
12
+ def description
13
+ 'The number of videos with description has a link to its own channel'
14
+ end
15
+
16
+ private
17
+
18
+ def valid?(video)
19
+ video.description.split(' ')
20
+ .select {|word| Yt::URL.new(word).kind == :channel }
21
+ .any? {|link| Yt::Channel.new(url: link).id == video.channel_id }
22
+ end
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt-audit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kang-Kyu Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yt
@@ -126,8 +126,15 @@ files:
126
126
  - Rakefile
127
127
  - bin/console
128
128
  - bin/setup
129
+ - bin/yt-audit
129
130
  - lib/yt/audit.rb
130
131
  - lib/yt/audit/version.rb
132
+ - lib/yt/video_audit/base.rb
133
+ - lib/yt/video_audit/brand_anchoring.rb
134
+ - lib/yt/video_audit/end_card.rb
135
+ - lib/yt/video_audit/info_card.rb
136
+ - lib/yt/video_audit/subscribe_annotation.rb
137
+ - lib/yt/video_audit/youtube_association.rb
131
138
  - yt-audit.gemspec
132
139
  homepage: https://github.com/fullscreen/yt-audit
133
140
  licenses: