YPBT 0.1.4 → 0.1.5

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: efa96df6ef895c6f7666e5dd9e641d4ac271521e
4
- data.tar.gz: fc3c537161216660c1b60389fcb2c1beeae1b5ab
3
+ metadata.gz: 61ca8e47aa6832f4964feb5183284194e1eb1ba3
4
+ data.tar.gz: 031b9c6f56a7e5c12b9083ac7e8037e04f66a9aa
5
5
  SHA512:
6
- metadata.gz: 71d3ad3d07a30b13bf2fb8782a00a17ef604d6b53d6e0a6fbfb24d4e0c4b51836ee781c470ef67462ce9772fbb8ed06471aee9ba9f4a71d412b283d59cbc87a2
7
- data.tar.gz: d9b29bda32feb134b6cbaaf09dee19d546a9fa5ffdf3865a91a1e7c85b609c6d74750d59fef1340c544836c695a8c8fa700b41691edb54d0bc961807eeeb38fc
6
+ metadata.gz: dad8c87e97632e19d7af64ea144e8ddb39d946eed78f968f8ea087cf18e49af0f006ae1b000c5d3b9a7bf7c08980f09d2853a44ddd91b6e084ce600a510abae0
7
+ data.tar.gz: 3f8942eeb84ade640a7c48b1cdc6627cee180c67be553cff9ec24d752051192f2b8a8d4984d479be9fd307ede7c94ec2ac43af09ce6f95b553be8f634a5d2925
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2
5
+ - 2.1
6
+ branches:
7
+ only:
8
+ - master
9
+ script: bundle exec rake spec
data/Gemfile CHANGED
@@ -1,14 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  source 'https://rubygems.org'
3
- gem 'http'
4
3
 
5
- gem 'minitest'
6
- gem 'minitest-rg'
7
- gem 'rake'
8
- gem 'vcr'
9
- gem 'webmock'
10
- gem 'simplecov'
11
-
12
- gem 'flog'
13
- gem 'flay'
14
- gem 'rubocop'
4
+ gemspec
data/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  MIT LICENSE
2
2
 
3
- Copyright (c)
3
+ Copyright (c) Yi-Min <b37582000@gmail.com>, Yuan-Yu <tearsgundam@gmail.com>,
4
+ Kun-Lin <orange6318@hotmail.com>
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,13 +1,47 @@
1
1
  # Youtube Progress Bar Tagger
2
+ [![Gem Version](https://badge.fury.io/rb/YPBT.svg)](https://badge.fury.io/rb/YPBT)
3
+ [![Build Status](https://travis-ci.org/RubyStarts3/YPBT.svg?branch=master)](https://travis-ci.org/RubyStarts3/YPBT)
2
4
 
3
- ## Youtube data_api exploration
4
- ### Quick Start
5
- Export your [Youtube api key](https://console.developers.google.com/apis/credentials)
6
-
7
- export YOUTUBE_API_KEY='Your_Youtube_API_Key'
8
- Install essential gem
9
-
10
- bundle install
11
- Then do a basic test for our module
12
-
13
- rake spec
5
+ Youtube Progress Bar Tagger (YPBT) is a gem that tracks the comments following a youtube movie and captures the time points of popularity.
6
+
7
+ ## Installation
8
+
9
+ If you are working on a project, add this to your Gemfile: `gem 'YPBT'`
10
+
11
+ For ad hoc installation from command line:
12
+
13
+ `$ gem install YPBT`
14
+
15
+ ## Quick Start
16
+ Export your [Youtube api key](https://console.developers.google.com/apis/credentials)
17
+ ```
18
+   $ export YOUTUBE_API_KEY='Your_Youtube_API_Key'
19
+ ```
20
+ Install essential gem
21
+ ```
22
+ $ bundle install
23
+ ```
24
+ Then do a basic test for our module
25
+ ```
26
+   $ rake spec
27
+ ```
28
+ Now, try to extract data from YouTube's video
29
+ => `https://www.youtube.com/watch?v=[video_id]`
30
+ ```
31
+ $ YPBT [video_id]
32
+ ```
33
+ ## Usage
34
+ ```ruby
35
+ video = YoutubeVideo::Video.find(
36
+ video_id: video_id
37
+ )
38
+
39
+ puts video.title
40
+
41
+ video.commentthreads.each. do |comment|
42
+ puts comment.author.author_name
43
+ puts comment.text_display
44
+ puts comment.author.like_count if comment.author.like_count
45
+ puts comment.author.author_channel_url
46
+ end
47
+ ```
data/YPBT.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = YoutubeVideo::VERSION
8
8
 
9
9
  s.summary = 'Gets comment from public Youtube videos'
10
- s.description = 'Youtube Progress Bar Tagger '\
10
+ s.description = 'Youtube Progress Bar Tagger'\
11
11
  'extracts comment threads, comments, and '\
12
12
  'comment of author from Youtube videos'
13
13
  s.authors = ['Yi-Min'], ['Yuan-Yu'], ['Kun-Lin']
data/bin/YPBT CHANGED
@@ -2,23 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w(.. lib))
4
4
  require 'YPBT'
5
+ require_relative '../lib/YPBT/runner.rb'
5
6
 
6
- video_id = ARGV[0]
7
- unless video_id
8
- puts 'USAGE: YPBT [video_id]'
9
- exit(1)
10
- end
11
-
12
- video = YoutubeVideo::Video.find(video_id: video_id)
13
- puts video.title
14
-
15
- puts Array.new(video.title.length) { '-' }.join
16
- video.commentthreads.first(3).each.with_index do |comment, index|
17
- print "#{index + 1}. "
18
- puts comment.author.author_name + ':'
19
- puts comment.text_display
20
- print 'LIKE: '
21
- puts comment.author.like_count if comment.author.like_count
22
- puts "AuthorChannelUrl: #{comment.author.author_channel_url}"
23
- puts
24
- end
7
+ puts YoutubeVideo::Runner.run!(ARGV)
data/lib/YPBT/author.rb CHANGED
@@ -9,7 +9,7 @@ module YoutubeVideo
9
9
  @author_name = data[0]['snippet']['authorDisplayName']
10
10
  @author_image_url = data[0]['snippet']['authorProfileImageUrl']
11
11
  @author_channel_url = data[0]['snippet']['authorChannelUrl']
12
- @like_count = data[0]['snippet']['likeCount']
12
+ @like_count = data[0]['snippet']['likeCount'].to_i
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YoutubeVideo
4
+ # Executable code for file(s) in bin/ folder
5
+ class Runner
6
+ def self.run!(args)
7
+ video_id = args[0] || ENV['YT_VIDEO_ID']
8
+ unless video_id
9
+ puts 'USAGE: YPBT [video_id]'
10
+ exit(1)
11
+ end
12
+
13
+ video = YoutubeVideo::Video.find(video_id: video_id)
14
+
15
+ output_info(video)
16
+ end
17
+
18
+ def self.output_info(video)
19
+ title = video.title
20
+ separator = Array.new(video.title.length) { '-' }.join
21
+ video_info =
22
+ video.commentthreads.first(3).map.with_index do |comment, index|
23
+ comment_info(comment, index)
24
+ end.join
25
+
26
+ [title, separator, video_info].join("\n")
27
+ end
28
+
29
+ def self.comment_info(comment, index)
30
+ "#{index + 1}:\n"\
31
+ " Autor: #{comment.author.author_name}\n"\
32
+ " Comment: #{comment.text_display}\n"\
33
+ " LIKE: #{comment.author.like_count}\n"\
34
+ " AuthorChannelUrl: #{comment.author.author_channel_url}\n"
35
+ end
36
+ end
37
+ end
data/lib/YPBT/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YoutubeVideo
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
data/lib/YPBT/video.rb CHANGED
@@ -5,11 +5,17 @@ require_relative 'youtube_api'
5
5
  module YoutubeVideo
6
6
  # Main class to setup a Video
7
7
  class Video
8
- attr_reader :title
8
+ attr_reader :title, :description, :dislike_count, :like_count,
9
+ :comment_count, :view_count
9
10
 
10
11
  def initialize(data:)
11
- @title = data['snippet']['title']
12
12
  @id = data['id']
13
+ @title = data['snippet']['title']
14
+ @description = data['snippet']['description']
15
+ @dislike_count = data['statistics']['dislikeCount'].to_i
16
+ @like_count = data['statistics']['likeCount'].to_i
17
+ @comment_count = data['statistics']['commentCount'].to_i
18
+ @view_count = data['statistics']['viewCount'].to_i
13
19
  end
14
20
 
15
21
  def commentthreads
@@ -22,6 +28,11 @@ module YoutubeVideo
22
28
  end
23
29
  end
24
30
 
31
+ def embed_url
32
+ return @embed_url if @embed_url
33
+ @embed_url = "https://www.youtube.com/embed/#{@id}"
34
+ end
35
+
25
36
  def self.find(video_id:)
26
37
  video_data = YoutubeVideo::YtApi.video_info(video_id)
27
38
  new(data: video_data)
@@ -16,12 +16,17 @@ module YoutubeVideo
16
16
  @api_key = ENV['YOUTUBE_API_KEY']
17
17
  end
18
18
 
19
+ def self.config=(credentials)
20
+ @config ? @config.update(credentials) : @config = credentials
21
+ end
22
+
19
23
  def self.video_info(video_id)
20
- field = 'items(id,snippet(channelId,description,publishedAt,title))'
24
+ field = 'items(id,snippet(channelId,description,publishedAt,title),'\
25
+ 'statistics)'
21
26
  video_response = HTTP.get(yt_resource_url('videos'),
22
27
  params: { id: video_id,
23
28
  key: api_key,
24
- part: 'snippet',
29
+ part: 'snippet,statistics',
25
30
  fields: field })
26
31
  JSON.parse(video_response.to_s)['items'].first
27
32
  end