youtube_parser 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/youtube_parser/channels/about_section.rb +27 -3
- data/lib/youtube_parser/config/keys.yml +2 -0
- data/lib/youtube_parser/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e7896f15e739e7d88e6de6acf67f07bc543897deffebe0c4e723a3746d84e32
|
4
|
+
data.tar.gz: bff5544c0e250bd76c9265f74eaee6d743423c7748030415d0983175b3c263ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b6ae178f21036ff1f620982349975cd88973aa51443a59caf8efa81a0da5a4b1bbd135f00c383f0e3c672a1edd63c74d12219c346f364066bbc952f8f59a525
|
7
|
+
data.tar.gz: 2b30490336766753b5b18aa7f0bdc5f61eea7ac6dd13c97777466c2ec5f2f25c8df3bde616152243811882b8c2c656625a50c68989cb80f51c41ff1a2939428e
|
data/Gemfile.lock
CHANGED
@@ -41,11 +41,11 @@ module YoutubeParser
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def tags
|
44
|
-
|
44
|
+
json.dig(*keys.keywords).to_s.split('"').select(&:present?)
|
45
45
|
end
|
46
46
|
|
47
47
|
def avatar_url
|
48
|
-
results =
|
48
|
+
results = json.dig(*keys.meta_avatar) || section.dig(*keys.avatar)
|
49
49
|
return if results.nil? || results.empty?
|
50
50
|
|
51
51
|
results.detect { |t| t&.dig('url') }&.dig('url')
|
@@ -59,7 +59,8 @@ module YoutubeParser
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def followers_count
|
62
|
-
|
62
|
+
count = scrape_subscribers_count
|
63
|
+
count.present? ? count : statistics(:followers_count)
|
63
64
|
end
|
64
65
|
|
65
66
|
def videos_count
|
@@ -73,6 +74,29 @@ module YoutubeParser
|
|
73
74
|
stats[indexes[title.to_sym].to_i].to_s.gsub(/\D+/, '')
|
74
75
|
end
|
75
76
|
|
77
|
+
def scrape_subscribers_count
|
78
|
+
return unless subscribers_match
|
79
|
+
|
80
|
+
number = subscribers_match[:number].gsub(',', '.').to_f
|
81
|
+
return number.to_i unless subscribers_match[:units].present?
|
82
|
+
|
83
|
+
subscribers_with_units number
|
84
|
+
end
|
85
|
+
|
86
|
+
def subscribers_with_units(number)
|
87
|
+
(number * units[subscribers_match[:units].downcase.to_sym]).to_i
|
88
|
+
end
|
89
|
+
|
90
|
+
def subscribers_match
|
91
|
+
regex = /(?<number>[\d.,]+)(?<units>\w?)/
|
92
|
+
subscribers_text = json.dig(*keys.subscribers_count_text).to_s
|
93
|
+
subscribers_text.match(regex)
|
94
|
+
end
|
95
|
+
|
96
|
+
def units
|
97
|
+
{ m: 1_000_000, k: 1_000 }
|
98
|
+
end
|
99
|
+
|
76
100
|
def section
|
77
101
|
return @section if @section
|
78
102
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
channel_url: ['navigationEndpoint', 'browseEndpoint', 'canonicalBaseUrl']
|
2
2
|
channel_title: ['title', 'simpleText']
|
3
3
|
subscribers_count: ['subscriberCountText', 'simpleText']
|
4
|
+
subscribers_count_text: ['header', 'c4TabbedHeaderRenderer',
|
5
|
+
'subscriberCountText']
|
4
6
|
section_tabs: ['contents', 'twoColumnBrowseResultsRenderer', 'tabs']
|
5
7
|
about_section_tab: ['tabRenderer', 'content', 'sectionListRenderer',
|
6
8
|
'contents', 0, 'itemSectionRenderer', 'contents', 0,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youtube_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- o.vykhor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|