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 +4 -4
- data/.travis.yml +9 -0
- data/Gemfile +1 -11
- data/LICENSE +2 -1
- data/README.md +45 -11
- data/YPBT.gemspec +1 -1
- data/bin/YPBT +2 -19
- data/lib/YPBT/author.rb +1 -1
- data/lib/YPBT/runner.rb +37 -0
- data/lib/YPBT/version.rb +1 -1
- data/lib/YPBT/video.rb +13 -2
- data/lib/YPBT/youtube_api.rb +7 -2
- data/spec/fixtures/cassettes/youtube_api.yml +513 -1121
- data/spec/spec_helper.rb +3 -0
- data/spec/video_spec.rb +8 -3
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61ca8e47aa6832f4964feb5183284194e1eb1ba3
|
4
|
+
data.tar.gz: 031b9c6f56a7e5c12b9083ac7e8037e04f66a9aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dad8c87e97632e19d7af64ea144e8ddb39d946eed78f968f8ea087cf18e49af0f006ae1b000c5d3b9a7bf7c08980f09d2853a44ddd91b6e084ce600a510abae0
|
7
|
+
data.tar.gz: 3f8942eeb84ade640a7c48b1cdc6627cee180c67be553cff9ec24d752051192f2b8a8d4984d479be9fd307ede7c94ec2ac43af09ce6f95b553be8f634a5d2925
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
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
|
+
[](https://badge.fury.io/rb/YPBT)
|
3
|
+
[](https://travis-ci.org/RubyStarts3/YPBT)
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
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
|
data/lib/YPBT/runner.rb
ADDED
@@ -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
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)
|
data/lib/YPBT/youtube_api.rb
CHANGED
@@ -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
|