yt_util 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/README.md +1 -0
- data/lib/yt_util/channel.rb +1 -11
- data/lib/yt_util/channel/url.rb +13 -0
- 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 +2 -0
- metadata +15 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5005d34671834c8dcf242d8ba818ed91a471135b
|
4
|
+
data.tar.gz: 5ab598fb0d78946dbba1fd320fc4d25424dad736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaf37bd28dd6bbfe3527c5036317ea1142be438f2a311e65bb408f45bf275bf1869dc14b38522f6a823ea432ede619fc4e38181121799d6b5dfccc909172c77a
|
7
|
+
data.tar.gz: d4c7c308dadef7284062965c7d23eda52934d5493c2a6f9fff36df53345712ca611715abf30ade2114817da0d0caae5ec14faef1807f2c72bed255f7b9068eb9
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Youtube Utility
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/yt_util.svg)](http://badge.fury.io/rb/yt_util)
|
3
|
+
[![Build Status](https://travis-ci.org/danielpclark/yt_util.svg)](https://travis-ci.org/danielpclark/yt_util)
|
3
4
|
|
4
5
|
General purpose toolbox for working with Youtube.
|
5
6
|
|
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"
|
@@ -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/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,8 @@
|
|
14
14
|
# users commonly want.
|
15
15
|
#
|
16
16
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
require 'yt_util'
|
18
|
+
|
17
19
|
RSpec.configure do |config|
|
18
20
|
# The settings below are suggested to provide a good initial experience
|
19
21
|
# with RSpec, but feel free to customize to your heart's content.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
+
- ".travis.yml"
|
92
93
|
- Gemfile
|
93
94
|
- Gemfile.lock
|
94
95
|
- LICENSE.txt
|
@@ -96,11 +97,17 @@ files:
|
|
96
97
|
- Rakefile
|
97
98
|
- lib/yt_util.rb
|
98
99
|
- lib/yt_util/channel.rb
|
100
|
+
- lib/yt_util/channel/url.rb
|
99
101
|
- lib/yt_util/google_plus.rb
|
100
102
|
- lib/yt_util/scrape.rb
|
101
103
|
- lib/yt_util/try.rb
|
102
104
|
- lib/yt_util/url.rb
|
103
105
|
- lib/yt_util/version.rb
|
106
|
+
- spec/lib/yt_util/channel/url_spec.rb
|
107
|
+
- spec/lib/yt_util/google_plus_spec.rb
|
108
|
+
- spec/lib/yt_util/scrape_spec.rb
|
109
|
+
- spec/lib/yt_util/url_spec.rb
|
110
|
+
- spec/lib/yt_util_spec.rb
|
104
111
|
- spec/spec_helper.rb
|
105
112
|
- yt_util.gemspec
|
106
113
|
homepage: http://github.com/danielpclark/yt_util
|
@@ -123,9 +130,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
130
|
version: '0'
|
124
131
|
requirements: []
|
125
132
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
133
|
+
rubygems_version: 2.4.1
|
127
134
|
signing_key:
|
128
135
|
specification_version: 4
|
129
136
|
summary: Youtube Utility.
|
130
137
|
test_files:
|
138
|
+
- spec/lib/yt_util/channel/url_spec.rb
|
139
|
+
- spec/lib/yt_util/google_plus_spec.rb
|
140
|
+
- spec/lib/yt_util/scrape_spec.rb
|
141
|
+
- spec/lib/yt_util/url_spec.rb
|
142
|
+
- spec/lib/yt_util_spec.rb
|
131
143
|
- spec/spec_helper.rb
|