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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d045861cc1212a62f8a57905620fdc0a7d584f87
4
- data.tar.gz: 4c63d356bc7cd103036e640fbff331d5ae12f81f
3
+ metadata.gz: 5005d34671834c8dcf242d8ba818ed91a471135b
4
+ data.tar.gz: 5ab598fb0d78946dbba1fd320fc4d25424dad736
5
5
  SHA512:
6
- metadata.gz: 95796161c24f03581c78a6ba35afe53a75fb3942d1f9cf6deaaa4599f30725431dc67291f512e4b6e06aea300cc3fff017ff1d52a9a230a6dbd40c01bf33254b
7
- data.tar.gz: 35fc63fb67428dfe1560a9aff203b42795bae7a5e923a448dfde50f9437d0d2285499f34d4a2df838b1be92aa10c4668f527944c8d6b895ef989a2b09582d35e
6
+ metadata.gz: eaf37bd28dd6bbfe3527c5036317ea1142be438f2a311e65bb408f45bf275bf1869dc14b38522f6a823ea432ede619fc4e38181121799d6b5dfccc909172c77a
7
+ data.tar.gz: d4c7c308dadef7284062965c7d23eda52934d5493c2a6f9fff36df53345712ca611715abf30ade2114817da0d0caae5ec14faef1807f2c72bed255f7b9068eb9
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - ruby-head
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
 
@@ -1,11 +1 @@
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 = 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
@@ -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 =~ /\?.+&/
@@ -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
  {
@@ -1,3 +1,3 @@
1
1
  module YtUtil
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -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"
@@ -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.3
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-23 00:00:00.000000000 Z
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.3.0
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