yt_util 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yt_util/google_plus.rb +14 -0
- data/lib/yt_util/scrape.rb +9 -3
- data/lib/yt_util/url.rb +5 -0
- data/lib/yt_util/version.rb +1 -1
- data/lib/yt_util.rb +1 -0
- metadata +17 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 059abccfce7627fa2a506baccb0d2f62f70a80a2
|
4
|
+
data.tar.gz: 31ff588d17835b0f6cb87bc23362892964ce4676
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b977c8c126e499ccd1d4a3f4e79e9c1dcf5f915e2f2582dbb2e842b00be1e016f522c0da1e6087ddf1bc906d31b178ee4bf11074b46f8ac83737bea558fc91f
|
7
|
+
data.tar.gz: 9bad9170264b3077a6ba5e77f86db694bbed07744b51bddf1c828447a495f3fe7d3ee921ef9c820f583f8512aaf9c7c1179ea03b6db00e03eaebccd9cd01d063
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module YtUtil
|
2
|
+
module GooglePlus
|
3
|
+
def self.get_username(youtube_username)
|
4
|
+
google_plus_link = YtUtil::Scrape.user_stats(youtube_username)[:link]
|
5
|
+
return nil if google_plus_link.nil?
|
6
|
+
google_plus_link = google_plus_link.match(/\?q=(.+)&/)[1] if google_plus_link =~ /\?.+&/
|
7
|
+
result = YtUtil::URL.request(google_plus_link)
|
8
|
+
result = result.css('a').map {|i|
|
9
|
+
i["href"].match(/https:\/\/plus.google.com\/%2B(.+)\?/).try(:[],-1)
|
10
|
+
}.compact.first
|
11
|
+
result ? "+".concat(result.to_s) : nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/yt_util/scrape.rb
CHANGED
@@ -38,29 +38,32 @@ module YtUtil
|
|
38
38
|
|
39
39
|
private
|
40
40
|
def self.request(web_request)
|
41
|
-
|
42
|
-
Nokogiri::HTML(open(web_request))
|
41
|
+
YtUtil::URL.request(web_request)
|
43
42
|
end
|
43
|
+
private_class_method :request
|
44
44
|
|
45
45
|
def self.request_query(search, filters = "")
|
46
46
|
web_request = "https://www.youtube.com/results?search_query=#{Addressable::URI.parse(search).normalize + filters}"
|
47
47
|
request(web_request)
|
48
48
|
end
|
49
|
+
private_class_method :request_query
|
49
50
|
|
50
51
|
def self.request_video_stats(video_code)
|
51
52
|
web_request = "https://www.youtube.com/watch?v=#{video_code}"
|
52
53
|
request(web_request)
|
53
54
|
end
|
55
|
+
private_class_method :request_video_stats
|
54
56
|
|
55
57
|
def self.request_user_stats(username)
|
56
58
|
web_request = "https://www.youtube.com/user/#{username}/about"
|
57
59
|
request(web_request)
|
58
60
|
end
|
61
|
+
private_class_method :request_user_stats
|
59
62
|
|
60
63
|
def self.parse_query(query_result)
|
61
64
|
query_result.css("ol.item-section > li")[1..-1].map do |result|
|
62
65
|
{
|
63
|
-
title: try {result.css("div:nth-child(1)").css("div:nth-child(2)").css("h3").text},
|
66
|
+
title: try {result.css("div:nth-child(1)").css("div:nth-child(2)").css("h3").text.match(/(.+) - Duration/).try(:[],1)},
|
64
67
|
video: try {result.css('a').map { |i| i.attributes["href"]}.try(:[],0).try(:value).try(:match,/\?v=(.{11})/).try(:[],1)},
|
65
68
|
views: try {result.css('li').select {|i| i.try(:text) =~ /^[\d,]{1,} views/ }.first.try(:text).try(:split).try(:first).try(:gsub,",","_").to_i},
|
66
69
|
new: try {!!result.css("div:nth-child(1)").css("div:nth-child(2)").css("div:nth-child(4)").css("ul:nth-child(1)").text["New"]},
|
@@ -70,6 +73,7 @@ module YtUtil
|
|
70
73
|
}
|
71
74
|
end
|
72
75
|
end
|
76
|
+
private_class_method :parse_query
|
73
77
|
|
74
78
|
def self.parse_video_page(video_code, query_result)
|
75
79
|
{
|
@@ -84,6 +88,7 @@ module YtUtil
|
|
84
88
|
license: try {query_result.css('li.watch-meta-item:nth-child(2)').text.gsub("\n", '').strip.tap {|i| i.replace i[i.index(' ').to_i..-1].strip}}
|
85
89
|
}
|
86
90
|
end
|
91
|
+
private_class_method :parse_video_page
|
87
92
|
|
88
93
|
def self.parse_user(query_result)
|
89
94
|
views_n_subs = try {query_result.css('.about-stats').
|
@@ -99,6 +104,7 @@ module YtUtil
|
|
99
104
|
joined: try {query_result.css('.about-stats').css('.joined-date').text.strip}
|
100
105
|
}
|
101
106
|
end
|
107
|
+
private_class_method :parse_user
|
102
108
|
|
103
109
|
end
|
104
110
|
end
|
data/lib/yt_util/url.rb
CHANGED
@@ -50,5 +50,10 @@ module YtUtil
|
|
50
50
|
"https://www.youtube.com/watch?v=#{video_code}".<<(parameters.gsub("?","&"))
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
def self.request(web_request)
|
55
|
+
try { Mechanize.new.tap { |i| i.follow_meta_refresh = true }.get(web_request).parser } ||
|
56
|
+
Nokogiri::HTML(open(web_request))
|
57
|
+
end
|
53
58
|
end
|
54
59
|
end
|
data/lib/yt_util/version.rb
CHANGED
data/lib/yt_util.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
@@ -14,70 +14,70 @@ dependencies:
|
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: nokogiri
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.6'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mechanize
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.7'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.7'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: addressable
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '2.3'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.3'
|
83
83
|
description: A toolbox for Youtube.
|
@@ -87,14 +87,15 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
-
|
91
|
-
-
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
92
|
- Gemfile
|
93
93
|
- Gemfile.lock
|
94
94
|
- LICENSE.txt
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- lib/yt_util.rb
|
98
|
+
- lib/yt_util/google_plus.rb
|
98
99
|
- lib/yt_util/scrape.rb
|
99
100
|
- lib/yt_util/try.rb
|
100
101
|
- lib/yt_util/url.rb
|
@@ -111,17 +112,17 @@ require_paths:
|
|
111
112
|
- lib
|
112
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
114
|
requirements:
|
114
|
-
- -
|
115
|
+
- - ~>
|
115
116
|
- !ruby/object:Gem::Version
|
116
117
|
version: '2.0'
|
117
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
119
|
requirements:
|
119
|
-
- -
|
120
|
+
- - '>='
|
120
121
|
- !ruby/object:Gem::Version
|
121
122
|
version: '0'
|
122
123
|
requirements: []
|
123
124
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.3
|
125
|
+
rubygems_version: 2.4.3
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Youtube Utility.
|