yt_util 0.1.3 → 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 +5 -5
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +39 -5
- data/README.md +3 -0
- data/Rakefile +5 -0
- data/lib/yt_util/channel/url.rb +13 -0
- data/lib/yt_util/channel.rb +1 -11
- data/lib/yt_util/google_plus.rb +2 -0
- data/lib/yt_util/scrape.rb +1 -1
- data/lib/yt_util/version.rb +1 -1
- data/spec/lib/yt_util/channel/url_spec.rb +14 -0
- data/spec/lib/yt_util/google_plus_spec.rb +13 -0
- data/spec/lib/yt_util/scrape_spec.rb +47 -0
- data/spec/lib/yt_util/url_spec.rb +33 -0
- data/spec/lib/yt_util_spec.rb +1 -0
- data/spec/spec_helper.rb +4 -0
- data/yt_util.gemspec +2 -1
- metadata +30 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 88ef617fd29e453071379fe7bef5dfbad76f2d325ec262de051512e37122e38a
|
4
|
+
data.tar.gz: 3ff229d4327c149755524dfca81225d8693854500d9a5f5b83ba7d8ba43ef6e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4abf3e1493f7903c529943652b10f82005b81da6c062646649b699c758150c00669edba7969c4626ec64d6737ad128f131ac17c8ee1d233e147f6884d3fd17a
|
7
|
+
data.tar.gz: 488ee7b8860c79bac4e15fb04d081328cb5ae4e0dadee43195ac8255385b8ec7c0ee55c383a6558c990234274610877690e51455bb14ab340bd1bb9452774f36
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
yt_util (0.
|
5
|
-
addressable (~> 2.3
|
6
|
-
mechanize (~> 2.7
|
7
|
-
nokogiri (~> 1.6
|
4
|
+
yt_util (0.1.4)
|
5
|
+
addressable (~> 2.3)
|
6
|
+
mechanize (~> 2.7)
|
7
|
+
nokogiri (~> 1.6)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
addressable (2.3.6)
|
13
|
-
|
13
|
+
coveralls (0.7.2)
|
14
|
+
multi_json (~> 1.3)
|
15
|
+
rest-client (= 1.6.7)
|
16
|
+
simplecov (>= 0.7)
|
17
|
+
term-ansicolor (= 1.2.2)
|
18
|
+
thor (= 0.18.1)
|
19
|
+
diff-lcs (1.2.5)
|
20
|
+
docile (1.1.5)
|
21
|
+
domain_name (0.5.22)
|
14
22
|
unf (>= 0.0.5, < 1.0.0)
|
15
23
|
http-cookie (1.0.2)
|
16
24
|
domain_name (~> 0.5)
|
@@ -25,12 +33,36 @@ GEM
|
|
25
33
|
webrobots (>= 0.0.9, < 0.2)
|
26
34
|
mime-types (2.4.3)
|
27
35
|
mini_portile (0.6.1)
|
36
|
+
multi_json (1.10.1)
|
28
37
|
net-http-digest_auth (1.4)
|
29
38
|
net-http-persistent (2.9.4)
|
30
39
|
nokogiri (1.6.5)
|
31
40
|
mini_portile (~> 0.6.0)
|
32
41
|
ntlm-http (0.1.1)
|
33
42
|
rake (10.4.2)
|
43
|
+
rest-client (1.6.7)
|
44
|
+
mime-types (>= 1.16)
|
45
|
+
rspec (3.1.0)
|
46
|
+
rspec-core (~> 3.1.0)
|
47
|
+
rspec-expectations (~> 3.1.0)
|
48
|
+
rspec-mocks (~> 3.1.0)
|
49
|
+
rspec-core (3.1.7)
|
50
|
+
rspec-support (~> 3.1.0)
|
51
|
+
rspec-expectations (3.1.2)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.1.0)
|
54
|
+
rspec-mocks (3.1.3)
|
55
|
+
rspec-support (~> 3.1.0)
|
56
|
+
rspec-support (3.1.2)
|
57
|
+
simplecov (0.9.1)
|
58
|
+
docile (~> 1.1.0)
|
59
|
+
multi_json (~> 1.0)
|
60
|
+
simplecov-html (~> 0.8.0)
|
61
|
+
simplecov-html (0.8.0)
|
62
|
+
term-ansicolor (1.2.2)
|
63
|
+
tins (~> 0.8)
|
64
|
+
thor (0.18.1)
|
65
|
+
tins (0.13.2)
|
34
66
|
unf (0.1.4)
|
35
67
|
unf_ext
|
36
68
|
unf_ext (0.0.6)
|
@@ -41,5 +73,7 @@ PLATFORMS
|
|
41
73
|
|
42
74
|
DEPENDENCIES
|
43
75
|
bundler (~> 1.6)
|
76
|
+
coveralls
|
44
77
|
rake (~> 10.0)
|
78
|
+
rspec (~> 3.1)
|
45
79
|
yt_util!
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Youtube Utility
|
2
2
|
[](http://badge.fury.io/rb/yt_util)
|
3
|
+
[](https://travis-ci.org/danielpclark/yt_util)
|
4
|
+
[](https://coveralls.io/r/danielpclark/yt_util?branch=master)
|
3
5
|
|
4
6
|
General purpose toolbox for working with Youtube.
|
5
7
|
|
@@ -26,6 +28,7 @@ YtUtil::Scrape.user_stats(username = nil, &qry)
|
|
26
28
|
YtUtil::URL.generate(video_code, options = {})
|
27
29
|
YtUtil::URL.request(web_request)
|
28
30
|
YtUtil::GooglePlus.get_username(youtube_username)
|
31
|
+
YtUtil::Channel::URL.play_all(username)
|
29
32
|
```
|
30
33
|
|
31
34
|
## NOTE
|
data/Rakefile
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
module YtUtil
|
2
|
+
module Channel
|
3
|
+
module URL
|
4
|
+
def self.play_all(username)
|
5
|
+
result = YtUtil::URL.request("https://www.youtube.com/user/#{username}")
|
6
|
+
result = result.css('a.play-all-icon-btn').first
|
7
|
+
return nil unless result
|
8
|
+
result = try { result.attributes["href"].value }
|
9
|
+
result ? "https://www.youtube.com".concat(result) : nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/yt_util/channel.rb
CHANGED
@@ -1,11 +1 @@
|
|
1
|
-
|
2
|
-
module Channel
|
3
|
-
module URL
|
4
|
-
def self.play_all(username)
|
5
|
-
result = YtUtil::URL.request("https://www.youtube.com/user/#{username}")
|
6
|
-
result = try { result.css('a.play-all-icon-btn').first.attributes["href"].value }
|
7
|
-
result ? "https://www.youtube.com".concat(result) : nil
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
require "yt_util/channel/url"
|
data/lib/yt_util/google_plus.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module YtUtil
|
2
2
|
module GooglePlus
|
3
3
|
def self.get_username(youtube_username)
|
4
|
+
return nil unless youtube_username.is_a? String
|
5
|
+
return nil if youtube_username.empty?
|
4
6
|
google_plus_link = YtUtil::Scrape.user_stats(youtube_username)[:link]
|
5
7
|
return nil if google_plus_link.nil?
|
6
8
|
google_plus_link = google_plus_link.match(/\?q=(.+)&/)[1] if google_plus_link =~ /\?.+&/
|
data/lib/yt_util/scrape.rb
CHANGED
@@ -93,7 +93,7 @@ module YtUtil
|
|
93
93
|
def self.parse_user(query_result)
|
94
94
|
views_n_subs = try {query_result.css('.about-stats').
|
95
95
|
css('li').take(2).map{|i| i = i.text.strip; {
|
96
|
-
i.match(/[a-z]+/)[0] => i.match(/[\d,]+/)[0]}
|
96
|
+
i.match(/[a-z]+/)[0] => i.match(/[\d,]+/)[0].gsub(",","").to_i}
|
97
97
|
}.inject(:update)}
|
98
98
|
|
99
99
|
{
|
data/lib/yt_util/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
describe YtUtil::Channel::URL, "#play_all" do
|
2
|
+
|
3
|
+
context "with pewdiepie username" do
|
4
|
+
before{ @req = YtUtil::Channel::URL.play_all('pewdiepie') }
|
5
|
+
subject { @req }
|
6
|
+
it { expect(@req).to eq("https://www.youtube.com/watch?v=iZSB-UfrmPs&list=UU-lHJZR3Gqxm24_Vd_AJ5Yw") }
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with user without feature" do
|
10
|
+
before{ @req = YtUtil::Channel::URL.play_all('dockerrun') }
|
11
|
+
subject { @req }
|
12
|
+
it { expect(@req).to be_nil }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe YtUtil::GooglePlus, "#get_username" do
|
2
|
+
|
3
|
+
context "with docker username" do
|
4
|
+
before{ @req = YtUtil::GooglePlus.get_username('dockerrun') }
|
5
|
+
subject { @req }
|
6
|
+
it { expect(@req).to eq("+DockerIo") }
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with invalid input" do
|
10
|
+
specify { expect(YtUtil::GooglePlus.get_username('')).to be_nil }
|
11
|
+
specify { expect { YtUtil::GooglePlus.get_username('!@#$%^&*(~!@#$%') }.to raise_error(Mechanize::ResponseCodeError, /404/) }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
describe YtUtil::Scrape, "#query" do
|
2
|
+
|
3
|
+
context "with doctor who" do
|
4
|
+
before{ @req = YtUtil::Scrape.query('doctor who').first }
|
5
|
+
subject { @req }
|
6
|
+
it { expect(@req).to be_kind_of Hash }
|
7
|
+
it { expect(@req[:title]).to be_kind_of String }
|
8
|
+
it { expect(@req[:video]).to be_kind_of String }
|
9
|
+
it { expect(@req[:views]).to be_kind_of Integer }
|
10
|
+
it { expect(@req[:new]).to satisfy {|v| v == true or v == false} }
|
11
|
+
it { expect(@req[:hd]).to satisfy {|v| v == true or v == false} }
|
12
|
+
it { expect(@req[:description]).to be_kind_of String }
|
13
|
+
it { expect(@req[:length]).to be_kind_of String }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe YtUtil::Scrape, "#video_stats" do
|
18
|
+
context "with duck song" do
|
19
|
+
before{ @req = YtUtil::Scrape.video_stats('MtN1YnoL46Q') }
|
20
|
+
subject { @req }
|
21
|
+
it { expect(@req).to be_kind_of Hash }
|
22
|
+
it { expect(@req[:video]).to be_kind_of String }
|
23
|
+
it { expect(@req[:video].length).to eq(11) }
|
24
|
+
it { expect(@req[:user_name]).to be_kind_of String }
|
25
|
+
it { expect(@req[:description]).to be_kind_of String }
|
26
|
+
it { expect(@req[:category]).to be_kind_of String }
|
27
|
+
it { expect(@req[:views]).to be_kind_of Integer }
|
28
|
+
it { expect(@req[:likes]).to be_kind_of Integer }
|
29
|
+
it { expect(@req[:dislikes]).to be_kind_of Integer }
|
30
|
+
it { expect(@req[:published]).to be_kind_of String }
|
31
|
+
it { expect(@req[:license]).to be_kind_of String }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe YtUtil::Scrape, "#user_stats" do
|
36
|
+
context "with docker username" do
|
37
|
+
before{ @req = YtUtil::Scrape.user_stats('dockerrun') }
|
38
|
+
subject { @req }
|
39
|
+
it { expect(@req).to be_kind_of Hash }
|
40
|
+
it { expect(@req[:image]).to be_kind_of String }
|
41
|
+
it { expect(@req[:description]).to be_kind_of String }
|
42
|
+
it { expect(@req[:link]).to be_kind_of String }
|
43
|
+
it { expect(@req[:views]).to be_kind_of Integer }
|
44
|
+
it { expect(@req[:subscribers]).to be_kind_of Integer }
|
45
|
+
it { expect(@req[:joined]).to be_kind_of String }
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
describe YtUtil::URL, "#generate" do
|
2
|
+
|
3
|
+
context "with no parameters" do
|
4
|
+
before{ @req = YtUtil::URL.generate('12345678901') }
|
5
|
+
subject { @req }
|
6
|
+
it { expect(@req).to eq("https://www.youtube.com/watch?v=12345678901") }
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with embed parameter" do
|
10
|
+
before{ @req = YtUtil::URL.generate('12345678901', {embed: true}) }
|
11
|
+
subject { @req }
|
12
|
+
it { expect(@req).to eq("//www.youtube.com/embed/12345678901") }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with :short url parameter" do
|
16
|
+
before{ @req = YtUtil::URL.generate('12345678901', {short: true}) }
|
17
|
+
subject { @req }
|
18
|
+
it { expect(@req).to eq("http://youtu.be/12345678901") }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe YtUtil::URL, "#request" do
|
23
|
+
|
24
|
+
context "with a valid url" do
|
25
|
+
before{ @req = YtUtil::URL.request('https://www.google.com') }
|
26
|
+
subject { @req }
|
27
|
+
it { expect(@req).to respond_to :css }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with an invalid url" do
|
31
|
+
specify { expect {YtUtil::URL.request('')}.to raise_error(ArgumentError) }
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "spec_helper"
|
data/spec/spec_helper.rb
CHANGED
@@ -14,6 +14,10 @@
|
|
14
14
|
# users commonly want.
|
15
15
|
#
|
16
16
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
require 'yt_util'
|
18
|
+
require 'coveralls'
|
19
|
+
Coveralls.wear!
|
20
|
+
|
17
21
|
RSpec.configure do |config|
|
18
22
|
# The settings below are suggested to provide a good initial experience
|
19
23
|
# with RSpec, but feel free to customize to your heart's content.
|
data/yt_util.gemspec
CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = '
|
21
|
+
spec.required_ruby_version = '> 2.0'
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
24
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
26
|
spec.add_runtime_dependency "nokogiri", "~> 1.6"
|
26
27
|
spec.add_runtime_dependency "mechanize", "~> 2.7"
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yt_util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-24 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bundler
|
@@ -24,6 +23,20 @@ dependencies:
|
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '1.6'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.1'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.1'
|
27
40
|
- !ruby/object:Gem::Dependency
|
28
41
|
name: rake
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,6 +102,7 @@ extra_rdoc_files: []
|
|
89
102
|
files:
|
90
103
|
- ".gitignore"
|
91
104
|
- ".rspec"
|
105
|
+
- ".travis.yml"
|
92
106
|
- Gemfile
|
93
107
|
- Gemfile.lock
|
94
108
|
- LICENSE.txt
|
@@ -96,24 +110,29 @@ files:
|
|
96
110
|
- Rakefile
|
97
111
|
- lib/yt_util.rb
|
98
112
|
- lib/yt_util/channel.rb
|
113
|
+
- lib/yt_util/channel/url.rb
|
99
114
|
- lib/yt_util/google_plus.rb
|
100
115
|
- lib/yt_util/scrape.rb
|
101
116
|
- lib/yt_util/try.rb
|
102
117
|
- lib/yt_util/url.rb
|
103
118
|
- lib/yt_util/version.rb
|
119
|
+
- spec/lib/yt_util/channel/url_spec.rb
|
120
|
+
- spec/lib/yt_util/google_plus_spec.rb
|
121
|
+
- spec/lib/yt_util/scrape_spec.rb
|
122
|
+
- spec/lib/yt_util/url_spec.rb
|
123
|
+
- spec/lib/yt_util_spec.rb
|
104
124
|
- spec/spec_helper.rb
|
105
125
|
- yt_util.gemspec
|
106
126
|
homepage: http://github.com/danielpclark/yt_util
|
107
127
|
licenses:
|
108
128
|
- MIT
|
109
129
|
metadata: {}
|
110
|
-
post_install_message:
|
111
130
|
rdoc_options: []
|
112
131
|
require_paths:
|
113
132
|
- lib
|
114
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
115
134
|
requirements:
|
116
|
-
- - "
|
135
|
+
- - ">"
|
117
136
|
- !ruby/object:Gem::Version
|
118
137
|
version: '2.0'
|
119
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -122,10 +141,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
141
|
- !ruby/object:Gem::Version
|
123
142
|
version: '0'
|
124
143
|
requirements: []
|
125
|
-
|
126
|
-
rubygems_version: 2.3.0
|
127
|
-
signing_key:
|
144
|
+
rubygems_version: 3.6.2
|
128
145
|
specification_version: 4
|
129
146
|
summary: Youtube Utility.
|
130
147
|
test_files:
|
148
|
+
- spec/lib/yt_util/channel/url_spec.rb
|
149
|
+
- spec/lib/yt_util/google_plus_spec.rb
|
150
|
+
- spec/lib/yt_util/scrape_spec.rb
|
151
|
+
- spec/lib/yt_util/url_spec.rb
|
152
|
+
- spec/lib/yt_util_spec.rb
|
131
153
|
- spec/spec_helper.rb
|