youtube_parser 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f903b865d02d0e7cd331a737f268a5203669cdce1b1b64ce39c31ea82f941385
4
- data.tar.gz: e363de69b04ce8a78f172b71dd5e9c2c033bebae040dc7e8100b8278a6f42a51
3
+ metadata.gz: 6e7896f15e739e7d88e6de6acf67f07bc543897deffebe0c4e723a3746d84e32
4
+ data.tar.gz: bff5544c0e250bd76c9265f74eaee6d743423c7748030415d0983175b3c263ab
5
5
  SHA512:
6
- metadata.gz: e0860723613a734b3e84efeea7315fa59b8a778517f421c365af4381e8120f37d059529656a717339be14f491eb3b85991a8d23432f772529a95fadd19cf9c77
7
- data.tar.gz: 7690928cbbbed44014abea0ed85743f5614b58d64143800efa76b614e9f6963f2d55d1599b9e7008676caf75cedabd9544edaa630dc35857491449e79f793bb3
6
+ metadata.gz: 7b6ae178f21036ff1f620982349975cd88973aa51443a59caf8efa81a0da5a4b1bbd135f00c383f0e3c672a1edd63c74d12219c346f364066bbc952f8f59a525
7
+ data.tar.gz: 2b30490336766753b5b18aa7f0bdc5f61eea7ac6dd13c97777466c2ec5f2f25c8df3bde616152243811882b8c2c656625a50c68989cb80f51c41ff1a2939428e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- youtube_parser (0.1.7)
4
+ youtube_parser (0.1.8)
5
5
  activesupport
6
6
  faraday
7
7
  oj
@@ -41,11 +41,11 @@ module YoutubeParser
41
41
  end
42
42
 
43
43
  def tags
44
- section.dig(*keys.keywords)
44
+ json.dig(*keys.keywords).to_s.split('"').select(&:present?)
45
45
  end
46
46
 
47
47
  def avatar_url
48
- results = section.dig(*keys.avatar) || section.dig(*keys.meta_avatar)
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
- statistics :followers_count
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,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YoutubeParser
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
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.7
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-04 00:00:00.000000000 Z
11
+ date: 2020-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler