vk_music 4.0.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +35 -0
  3. data/Gemfile.lock +30 -29
  4. data/README.md +10 -0
  5. data/Rakefile +4 -1
  6. data/lib/vk_music/audio.rb +6 -5
  7. data/lib/vk_music/client.rb +13 -7
  8. data/lib/vk_music/request/artist.rb +24 -0
  9. data/lib/vk_music/request/{audios.rb → audios_reload.rb} +0 -0
  10. data/lib/vk_music/utility/artist_loader.rb +17 -0
  11. data/lib/vk_music/utility/artist_url_parser.rb +22 -0
  12. data/lib/vk_music/utility/audio_data_parser.rb +3 -3
  13. data/lib/vk_music/utility/audio_items_parser.rb +2 -2
  14. data/lib/vk_music/utility/audio_node_parser.rb +1 -1
  15. data/lib/vk_music/utility/audios_from_ids_loader.rb +1 -1
  16. data/lib/vk_music/utility/audios_ids_getter.rb +1 -1
  17. data/lib/vk_music/utility/audios_loader.rb +1 -1
  18. data/lib/vk_music/utility/data_type_guesser.rb +7 -1
  19. data/lib/vk_music/utility/duration_parser.rb +1 -1
  20. data/lib/vk_music/utility/last_profile_post_loader.rb +1 -1
  21. data/lib/vk_music/utility/link_decoder.rb +4 -3
  22. data/lib/vk_music/utility/node_text_children_reader.rb +2 -2
  23. data/lib/vk_music/utility/playlist_loader.rb +1 -1
  24. data/lib/vk_music/utility/playlist_node_parser.rb +1 -1
  25. data/lib/vk_music/utility/playlist_section_loader.rb +1 -1
  26. data/lib/vk_music/utility/playlist_url_parser.rb +1 -1
  27. data/lib/vk_music/utility/post_loader.rb +1 -1
  28. data/lib/vk_music/utility/post_url_parser.rb +1 -1
  29. data/lib/vk_music/utility/profile_id_resolver.rb +8 -1
  30. data/lib/vk_music/utility/wall_loader.rb +1 -1
  31. data/lib/vk_music/version.rb +1 -2
  32. data/lib/vk_music/web_parser/artist.rb +16 -0
  33. data/lib/vk_music/web_parser/{audios.rb → audios_reload.rb} +0 -0
  34. metadata +10 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8c860184e789669f3064d22a6a25e0dc37cb133334b17b8ce029cb2c937c06b
4
- data.tar.gz: 4eb06a451e1d69e8838b8aad2423d88a0edbdf2f12b0331dba98d6fdaf636be8
3
+ metadata.gz: 4cccd078598095d7d1a1b60af470f3544e17c4824f4e9a8cb1504a40aa0c571b
4
+ data.tar.gz: aa7a431ee677cdafbf2d2909e5465f22694653cfb412052d6d43c1a907ee4c7a
5
5
  SHA512:
6
- metadata.gz: 928a6156a75b7724975fc81fd390f8d11a011950fc9741fea4587e8350512b3a204d63acd8bfb846e7b1543979675de3d2b21ac4217a7f5bdc3c9942f6288926
7
- data.tar.gz: 34b8788ce3e592d390a09047bd6ac238c4182ad4d680db52aa76f6eef5327fe212cb8a28492cf46dabfb4975a9b3221b4290c15686040eae3db8e232b6cae9f7
6
+ metadata.gz: 5c062b5417c094c5b126ae11f5ad6905088832bedf3fc84e78c5df33ef884ec2c8429eadfee9d8566caf26fca4c1ccde29d7ec3a37f4a0388cd3b185c3a6f662
7
+ data.tar.gz: 263167df0338a1bf4ca8c82a2f7fd32826131482351fa33b47d82b137700aa561a691e85b767ee73af90f671d7ad29bbf05ee8031c3e6bf0bff0fc8ac06a0609
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
+ # uses: ruby/setup-ruby@v1
27
+ uses: ruby/setup-ruby@v1.52.0
28
+ with:
29
+ ruby-version: 2.7.2
30
+ - name: Install dependencies
31
+ run: bundle install
32
+ - name: Run rubocop
33
+ run: bundle exec rake rubocop
34
+ - name: Run yarddoc
35
+ run: bundle exec rake yard
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vk_music (4.0.0)
4
+ vk_music (4.1.1)
5
5
  execjs (~> 2.7)
6
6
  json (~> 2.3)
7
7
  logger (~> 1.4)
@@ -16,9 +16,10 @@ GEM
16
16
  ast (2.4.1)
17
17
  byebug (11.1.3)
18
18
  coderay (1.1.3)
19
- crack (0.4.4)
19
+ crack (0.4.5)
20
+ rexml
20
21
  diff-lcs (1.4.4)
21
- docile (1.3.2)
22
+ docile (1.3.4)
22
23
  domain_name (0.5.20190701)
23
24
  unf (>= 0.0.5, < 1.0.0)
24
25
  dotenv (2.7.6)
@@ -26,8 +27,8 @@ GEM
26
27
  hashdiff (1.0.1)
27
28
  http-cookie (1.0.3)
28
29
  domain_name (~> 0.5)
29
- json (2.3.1)
30
- logger (1.4.2)
30
+ json (2.5.1)
31
+ logger (1.4.3)
31
32
  mechanize (2.7.6)
32
33
  domain_name (~> 0.5, >= 0.5.1)
33
34
  http-cookie (~> 1.0)
@@ -41,70 +42,70 @@ GEM
41
42
  mime-types (3.3.1)
42
43
  mime-types-data (~> 3.2015)
43
44
  mime-types-data (3.2020.1104)
44
- mini_portile2 (2.4.0)
45
+ mini_portile2 (2.5.0)
45
46
  net-http-digest_auth (1.4.1)
46
47
  net-http-persistent (2.9.4)
47
- nokogiri (1.10.10)
48
- mini_portile2 (~> 2.4.0)
49
- nokogiri (1.10.10-x64-mingw32)
50
- mini_portile2 (~> 2.4.0)
48
+ nokogiri (1.11.1)
49
+ mini_portile2 (~> 2.5.0)
50
+ racc (~> 1.4)
51
51
  ntlm-http (0.1.1)
52
- parallel (1.19.2)
53
- parser (2.7.2.0)
52
+ parallel (1.20.1)
53
+ parser (3.0.0.0)
54
54
  ast (~> 2.4.1)
55
55
  pry (0.13.1)
56
56
  coderay (~> 1.1)
57
57
  method_source (~> 1.0)
58
58
  public_suffix (4.0.6)
59
+ racc (1.5.2)
59
60
  rainbow (3.0.0)
60
- rake (13.0.1)
61
- regexp_parser (1.8.2)
61
+ rake (13.0.3)
62
+ regexp_parser (2.0.3)
62
63
  rexml (3.2.4)
63
64
  rspec (3.10.0)
64
65
  rspec-core (~> 3.10.0)
65
66
  rspec-expectations (~> 3.10.0)
66
67
  rspec-mocks (~> 3.10.0)
67
- rspec-core (3.10.0)
68
+ rspec-core (3.10.1)
68
69
  rspec-support (~> 3.10.0)
69
- rspec-expectations (3.10.0)
70
+ rspec-expectations (3.10.1)
70
71
  diff-lcs (>= 1.2.0, < 2.0)
71
72
  rspec-support (~> 3.10.0)
72
- rspec-mocks (3.10.0)
73
+ rspec-mocks (3.10.1)
73
74
  diff-lcs (>= 1.2.0, < 2.0)
74
75
  rspec-support (~> 3.10.0)
75
- rspec-support (3.10.0)
76
- rubocop (1.2.0)
76
+ rspec-support (3.10.1)
77
+ rubocop (1.7.0)
77
78
  parallel (~> 1.10)
78
79
  parser (>= 2.7.1.5)
79
80
  rainbow (>= 2.2.2, < 4.0)
80
- regexp_parser (>= 1.8)
81
+ regexp_parser (>= 1.8, < 3.0)
81
82
  rexml
82
- rubocop-ast (>= 1.0.1)
83
+ rubocop-ast (>= 1.2.0, < 2.0)
83
84
  ruby-progressbar (~> 1.7)
84
85
  unicode-display_width (>= 1.4.0, < 2.0)
85
- rubocop-ast (1.1.1)
86
+ rubocop-ast (1.4.0)
86
87
  parser (>= 2.7.1.5)
87
- ruby-progressbar (1.10.1)
88
- simplecov (0.19.1)
88
+ ruby-progressbar (1.11.0)
89
+ simplecov (0.21.1)
89
90
  docile (~> 1.1)
90
91
  simplecov-html (~> 0.11)
92
+ simplecov_json_formatter (~> 0.1)
91
93
  simplecov-html (0.12.3)
94
+ simplecov_json_formatter (0.1.2)
92
95
  unf (0.1.4)
93
96
  unf_ext
94
97
  unf_ext (0.0.7.7)
95
- unf_ext (0.0.7.7-x64-mingw32)
96
98
  unicode-display_width (1.7.0)
97
99
  vcr (6.0.0)
98
- webmock (3.9.5)
100
+ webmock (3.11.0)
99
101
  addressable (>= 2.3.6)
100
102
  crack (>= 0.3.2)
101
103
  hashdiff (>= 0.4.0, < 2.0.0)
102
104
  webrobots (0.1.2)
103
- yard (0.9.25)
105
+ yard (0.9.26)
104
106
 
105
107
  PLATFORMS
106
108
  ruby
107
- x64-mingw32
108
109
 
109
110
  DEPENDENCIES
110
111
  byebug
@@ -120,4 +121,4 @@ DEPENDENCIES
120
121
  yard
121
122
 
122
123
  BUNDLED WITH
123
- 2.1.4
124
+ 2.2.4
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ![Gem](https://img.shields.io/gem/v/vk_music) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/fizvlad/vk-music-rb/Ruby) ![Lines of code](https://img.shields.io/tokei/lines/github/fizvlad/vk-music-rb) ![Gem](https://img.shields.io/gem/dtv/vk_music)
2
+
1
3
  # VkMusic
2
4
 
3
5
  *vk_music* gem is a library to work with audios on popular Russian social network
@@ -79,6 +81,14 @@ You can load up to 10 audios attached to some post. Those audios will be returne
79
81
  audios = client.post(url: "link")
80
82
  ```
81
83
 
84
+ ### Artist audios
85
+
86
+ You can get up to 50 top audios of particular artist:
87
+
88
+ ```ruby
89
+ audios = client.artist(url: "link")
90
+ ```
91
+
82
92
  ### Getting audio URL
83
93
 
84
94
  To get audio URL you should go through following chain:
data/Rakefile CHANGED
@@ -2,14 +2,17 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
5
6
  require 'yard'
6
7
 
7
8
  RSpec::Core::RakeTask.new(:spec)
8
9
 
10
+ RuboCop::RakeTask.new
11
+
9
12
  YARD::Rake::YardocTask.new do |t|
10
13
  t.files = ['lib/**/*.rb']
11
14
  t.options = ['--any', '--extra', '--opts']
12
15
  t.stats_options = ['--list-undoc']
13
16
  end
14
17
 
15
- task default: %i[spec yard]
18
+ task default: %i[rubocop spec yard]
@@ -90,13 +90,14 @@ module VkMusic
90
90
  # @param [Audio, Array(owner_id, audio_id, secret1, secret2), String]
91
91
  # @return [Boolean] id-based comparison
92
92
  def id_matches?(data)
93
- data_id = case data
94
- when Array then data.join('_')
95
- when Audio then data.full_id
96
- when String then data.strip
93
+ data_owner_id, data_id = case data
94
+ when Audio then [data.owner_id, data.id]
95
+ when Array then data.first(2).reverse.map(&:to_i)
96
+ when String then data.split('_').first(2).map(&:to_i)
97
+ else return false
97
98
  end
98
99
 
99
- full_id == data_id
100
+ owner_id == data_owner_id && id == data_id
100
101
  end
101
102
 
102
103
  # @return [String] pretty-printed audio name
@@ -51,12 +51,6 @@ module VkMusic
51
51
  false
52
52
  end
53
53
 
54
- # Unmask old VK music link
55
- # @param limk [String]
56
- def unmask_link(link)
57
- VkMusic::LinkDecoder.unmask_link(link, @id)
58
- end
59
-
60
54
  # Search for audio or playlist
61
55
  #
62
56
  # Possible values of +type+ option:
@@ -131,7 +125,7 @@ module VkMusic
131
125
  Utility::WallLoader.call(agent, id, owner_id, post_id)
132
126
  end
133
127
 
134
- # Get audios attached to post. Specify either +url+ or +(owner_id,post_id)+.
128
+ # Get audios attached to post. Specify either +url+ or +(owner_id,post_id)+
135
129
  # @param url [String]
136
130
  # @param owner_id [Integer]
137
131
  # @param post_id [Integer]
@@ -144,6 +138,18 @@ module VkMusic
144
138
  Utility::PostLoader.call(agent, id, owner_id, post_id)
145
139
  end
146
140
 
141
+ # Artist top audios. Specify either +url+ or +name+ of the artist
142
+ # @param url [String]
143
+ # @param name [String]
144
+ # @return [Array<Audio>] array of audios attached to post
145
+ def artist(url: nil, name: nil)
146
+ name = Utility::ArtistUrlParser.call(url) if url
147
+
148
+ return [] if name.nil? || name.empty?
149
+
150
+ Utility::ArtistLoader.call(agent, id, name)
151
+ end
152
+
147
153
  # Get audios with download URLs by their IDs and secrets
148
154
  # @param args [Array<Audio, (owner_id, audio_id, secret_1, secret_2),
149
155
  # "#{owner_id}_#{id}_#{secret_1}_#{secret_2}">]
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VkMusic
4
+ module Request
5
+ # Artist audios page request
6
+ class Artist < Base
7
+ # Initialize new request
8
+ # @param name [String]
9
+ # @param client_id [Integer]
10
+ def initialize(name, client_id)
11
+ @client_id = client_id
12
+ super("#{VK_ROOT}/artist/#{name}/top_audios", {}, 'GET', {})
13
+ end
14
+
15
+ def_delegators :@parser, :audios
16
+
17
+ private
18
+
19
+ def after_call
20
+ @parser = WebParser::Artist.new(@response, client_id: @client_id)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VkMusic
4
+ module Utility
5
+ # Load artist top audios
6
+ module ArtistLoader
7
+ # @param agent [Mechanize]
8
+ # @param client_id [Integer]
9
+ # @param name [String]
10
+ # @return [Array<Audio>]
11
+ def self.call(agent, client_id, name)
12
+ page = Request::Artist.new(name, client_id).call(agent)
13
+ page.audios
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VkMusic
4
+ module Utility
5
+ # Artist URL parser
6
+ module ArtistUrlParser
7
+ # Regex for artist URL
8
+ ARTIST_POSTFIX = %r{.*artist/([\w.\-~]+)}.freeze
9
+ public_constant :ARTIST_POSTFIX
10
+
11
+ # Get artist name based on provided URL
12
+
13
+ # @param url [String]
14
+ # @return [String?]
15
+ def self.call(url)
16
+ url.match(ARTIST_POSTFIX)&.captures&.first
17
+ rescue StandardError
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,17 +3,17 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Parse {Audio} from +Array+ of audio data
6
- class AudioDataParser
6
+ module AudioDataParser
7
7
  class << self
8
8
  # @param data [Array]
9
9
  # @param client_id [Integer]
10
10
  # @return [Audio]
11
11
  def call(data, client_id)
12
12
  url_encoded = get_url_encoded(data)
13
- secrets = get_secrets(data)
13
+ _add_hash, _edit_hash, _action_hash, _delete_hash, _teplace_hash, url_hash = get_secrets(data)
14
14
 
15
15
  Audio.new(id: data[0], owner_id: data[1],
16
- secret1: secrets[2], secret2: secrets[5],
16
+ secret1: url_hash, secret2: url_hash,
17
17
  artist: CGI.unescapeHTML(data[4]), title: CGI.unescapeHTML(data[3]),
18
18
  duration: data[5],
19
19
  url_encoded: url_encoded, url: nil, client_id: client_id)
@@ -3,12 +3,12 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Parse {Audio} from +Nokogiri::XML::Node+
6
- class AudioItemsParser
6
+ module AudioItemsParser
7
7
  # @param node [Nokogiri::XML::Node]
8
8
  # @param client_id [Integer]
9
9
  # @return [Array<Audio>]
10
10
  def self.call(node, client_id)
11
- node.css('.audio_item.ai_has_btn').map do |elem|
11
+ node.css('.audio_item.ai_has_btn,.audio_item.audio_item_disabled').map do |elem|
12
12
  data = JSON.parse(elem.attribute('data-audio').value)
13
13
  Utility::AudioDataParser.call(data, client_id)
14
14
  end
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Parse {Audio} from +Nokogiri::XML::Node+
6
- class AudioNodeParser
6
+ module AudioNodeParser
7
7
  class << self
8
8
  # @param node [Nokogiri::XML::Node]
9
9
  # @param client_id [Integer]
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Load audios from ids
6
- class AudiosFromIdsLoader
6
+ module AudiosFromIdsLoader
7
7
  # @param agent [Mechanize]
8
8
  # @param ids [Array<String>]
9
9
  # @return [Array<Audio>]
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Load ids from array of data
6
- class AudiosIdsGetter
6
+ module AudiosIdsGetter
7
7
  # @param args [Array<Audio, (owner_id, audio_id, secret_1, secret_2),
8
8
  # "#{owner_id}_#{id}_#{secret_1}_#{secret_2}">]
9
9
  # @return [Array<String>] array of uniq full ids
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Load user or group audios
6
- class AudiosLoader
6
+ module AudiosLoader
7
7
  class << self
8
8
  # @param agent [Mechanize]
9
9
  # @param client_id [Integer]
@@ -1,16 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'playlist_url_parser'
4
+ require_relative 'artist_url_parser'
4
5
  require_relative 'post_url_parser'
5
6
 
6
7
  module VkMusic
7
8
  module Utility
8
9
  # Guess type of method to use based on string data
9
- class DataTypeGuesser
10
+ module DataTypeGuesser
10
11
  # End of playlist URL
11
12
  PLAYLIST_POSTFIX = PlaylistUrlParser::VK_PLAYLIST_URL_POSTFIX
12
13
  public_constant :PLAYLIST_POSTFIX
13
14
 
15
+ # Artist URL postfix
16
+ ARTIST_POSTFIX = ArtistUrlParser::ARTIST_POSTFIX
17
+ public_constant :ARTIST_POSTFIX
18
+
14
19
  # End of post URL
15
20
  POST_POSTFIX = PostUrlParser::POST_POSTFIX
16
21
  public_constant :POST_POSTFIX
@@ -32,6 +37,7 @@ module VkMusic
32
37
  def self.call(data)
33
38
  case data
34
39
  when PLAYLIST_POSTFIX then :playlist
40
+ when ARTIST_POSTFIX then :artist
35
41
  when POST_POSTFIX then :post
36
42
  when WALL_POSTFIX then :wall
37
43
  when AUDIOS_POSTFIX, PROFILE_URL then :audios
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Turn human readable track length to its size in seconds
6
- class DurationParser
6
+ module DurationParser
7
7
  # @param str [String] string in format "HH:MM:SS" or something alike (+/d++ Regex selector is used)
8
8
  # @return [Integer] amount of seconds
9
9
  def self.call(str)
@@ -5,7 +5,7 @@ require_relative 'profile_id_resolver'
5
5
  module VkMusic
6
6
  module Utility
7
7
  # Get user or group id from url
8
- class LastProfilePostLoader
8
+ module LastProfilePostLoader
9
9
  # vk.com url regex
10
10
  VK_PATH = ProfileIdResolver::VK_PATH
11
11
  private_constant :VK_PATH
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Link decoding utilities
6
- class LinkDecoder
6
+ module LinkDecoder
7
7
  # JS code which creates function to unmask audio URL.
8
8
  JS_CODE = <<~HEREDOC
9
9
  function vk_unmask_link(link, vk_id) {
@@ -96,9 +96,10 @@ module VkMusic
96
96
  # @param client_id [Integer] ID of user which got this link. ID is required for decoding.
97
97
  # @return [String?] audio download URL, which can be used only from current IP.
98
98
  def self.call(link, client_id)
99
+ VkMusic.log.debug('LinkDecoder') { "Unmasking link `#{link}` with client id #{client_id}" }
99
100
  @@js_context.call('vk_unmask_link', link, client_id)
100
- rescue StandardError
101
- VkMusic.log.warn('LinkDecoder') { "Failed to decode link: #{link}" }
101
+ rescue StandardError => e
102
+ VkMusic.log.warn('LinkDecoder') { "Failed to decode link `#{link}`: #{e.full_message}" }
102
103
  nil
103
104
  end
104
105
  end
@@ -3,11 +3,11 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Read inner of text-childrens of +Nokogiri::XML::Node+ node
6
- class NodeTextChildrenReader
6
+ module NodeTextChildrenReader
7
7
  # @param node [Nokogiri::XML::Node]
8
8
  # @return [String]
9
9
  def self.call(node)
10
- node.children.select(&:text?).map(&:text).join('').strip
10
+ node.children.select(&:text?).map(&:text).join.strip
11
11
  end
12
12
  end
13
13
  end
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Load playlist audios
6
- class PlaylistLoader
6
+ module PlaylistLoader
7
7
  # @param agent [Mechanize]
8
8
  # @param client_id [Integer]
9
9
  # @param owner_id [Integer]
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Read inner of text-childrens of +Nokogiri::XML::Node+ node
6
- class PlaylistNodeParser
6
+ module PlaylistNodeParser
7
7
  # @param node [Nokogiri::XML::Node]
8
8
  # @return [Playlist]
9
9
  def self.call(node)
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Load sections into playlist
6
- class PlaylistSectionLoader
6
+ module PlaylistSectionLoader
7
7
  # @param agent [Mechanize]
8
8
  # @param client_id [Integer]
9
9
  # @param owner_id [Integer]
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Read inner of text-childrens of +Nokogiri::XML::Node+ node
6
- class PlaylistUrlParser
6
+ module PlaylistUrlParser
7
7
  # Regular expression to parse playlist link. Oh my, it is so big
8
8
  VK_PLAYLIST_URL_POSTFIX = %r{
9
9
  .* # Garbage
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Load wall audios
6
- class PostLoader
6
+ module PostLoader
7
7
  # @param agent [Mechanize]
8
8
  # @param client_id [Integer]
9
9
  # @param owner_id [Integer]
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Load wall audios
6
- class PostUrlParser
6
+ module PostUrlParser
7
7
  # Regex for post URL
8
8
  POST_POSTFIX = /.*wall(-?\d+)_(\d+)/.freeze
9
9
  public_constant :POST_POSTFIX
@@ -3,11 +3,15 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Get user or group id from url
6
- class ProfileIdResolver
6
+ module ProfileIdResolver
7
7
  # vk.com url regex
8
8
  VK_PATH = %r{(?:https?://)?(?:vk\.com/)?([^/?&]+)}.freeze
9
9
  public_constant :VK_PATH
10
10
 
11
+ # audios list page
12
+ AUDIOS_PATH = /audios(-?\d+)/.freeze
13
+ public_constant :AUDIOS_PATH
14
+
11
15
  # vk.com user path regex
12
16
  USER_PATH = /id(\d+)/.freeze
13
17
  public_constant :USER_PATH
@@ -37,6 +41,9 @@ module VkMusic
37
41
  private
38
42
 
39
43
  def direct_match(path)
44
+ audios_match = path.match(AUDIOS_PATH)
45
+ return Integer(audios_match.captures.first, 10) if audios_match
46
+
40
47
  user_match = path.match(USER_PATH)
41
48
  return Integer(user_match.captures.first, 10) if user_match
42
49
 
@@ -3,7 +3,7 @@
3
3
  module VkMusic
4
4
  module Utility
5
5
  # Load wall audios
6
- class WallLoader
6
+ module WallLoader
7
7
  # @param agent [Mechanize]
8
8
  # @param client_id [Integer]
9
9
  # @param owner_id [Integer]
@@ -2,7 +2,6 @@
2
2
 
3
3
  module VkMusic
4
4
  # Library version.
5
- VERSION = '4.0.0'
6
-
5
+ VERSION = '4.1.1'
7
6
  public_constant :VERSION
8
7
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VkMusic
4
+ module WebParser
5
+ # Artist top audios web page
6
+ class Artist < Base
7
+ # @return [Array<Audio>]
8
+ def audios
9
+ audio_section = node.at_css('.AudioSection.AudioSection__artist_audios')
10
+ return [] if audio_section.nil?
11
+
12
+ Utility::AudioItemsParser.call(audio_section, @client_id)
13
+ end
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vk_music
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fizvlad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-26 00:00:00.000000000 Z
11
+ date: 2021-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".env.example"
91
+ - ".github/workflows/ruby.yml"
91
92
  - ".gitignore"
92
93
  - ".rspec"
93
94
  - ".rubocop.yml"
@@ -102,7 +103,8 @@ files:
102
103
  - lib/vk_music/client.rb
103
104
  - lib/vk_music/playlist.rb
104
105
  - lib/vk_music/request.rb
105
- - lib/vk_music/request/audios.rb
106
+ - lib/vk_music/request/artist.rb
107
+ - lib/vk_music/request/audios_reload.rb
106
108
  - lib/vk_music/request/base.rb
107
109
  - lib/vk_music/request/login.rb
108
110
  - lib/vk_music/request/my_page.rb
@@ -113,6 +115,8 @@ files:
113
115
  - lib/vk_music/request/search.rb
114
116
  - lib/vk_music/request/wall_section.rb
115
117
  - lib/vk_music/utility.rb
118
+ - lib/vk_music/utility/artist_loader.rb
119
+ - lib/vk_music/utility/artist_url_parser.rb
116
120
  - lib/vk_music/utility/audio_data_parser.rb
117
121
  - lib/vk_music/utility/audio_items_parser.rb
118
122
  - lib/vk_music/utility/audio_node_parser.rb
@@ -134,7 +138,8 @@ files:
134
138
  - lib/vk_music/utility/wall_loader.rb
135
139
  - lib/vk_music/version.rb
136
140
  - lib/vk_music/web_parser.rb
137
- - lib/vk_music/web_parser/audios.rb
141
+ - lib/vk_music/web_parser/artist.rb
142
+ - lib/vk_music/web_parser/audios_reload.rb
138
143
  - lib/vk_music/web_parser/base.rb
139
144
  - lib/vk_music/web_parser/login.rb
140
145
  - lib/vk_music/web_parser/my_page.rb
@@ -167,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
172
  - !ruby/object:Gem::Version
168
173
  version: '0'
169
174
  requirements: []
170
- rubygems_version: 3.1.2
175
+ rubygems_version: 3.2.4
171
176
  signing_key:
172
177
  specification_version: 4
173
178
  summary: A library to work with audios on popular Russian social network