vk_music 4.0.3 → 4.1.0

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
  SHA256:
3
- metadata.gz: 067f26c1a3f2e46794a61c4a62fae7dd40f190e70e91b7331c4891f83cf3bd9f
4
- data.tar.gz: 2942d5b5999a65a8fd29b8eebc2e632b44c944d204984d0d85df4a3fdf74c437
3
+ metadata.gz: 175777250336a247babea9660fef9e8b2dd070afb304bf4943f5a5f5706d4961
4
+ data.tar.gz: fb2421372d37fefc25dadb6823f06c4c7cb4b55cf961830dc3738435a0a758af
5
5
  SHA512:
6
- metadata.gz: 512889a498b3d0aa5c3413e24596b660d312acddb450052f8d1d44315c1e84d89749fbdb9d225b2e21555eb83efbca6d77922c0227a287154dee78991786250f
7
- data.tar.gz: e3bf4628feccd1120a9afaedfebe3a5d9d9b9f6965b13dd3bcec58526bbcf2fdcd943577e33b2b398227f7c48fd60577ecf81686b42283540e0ef6308df26132
6
+ metadata.gz: a3aa8fe59c41de35155c0111cf2ff54cd3bcbc101490a2ae614ac54920773f3bed658a197f2bce829f95634475c0698272f3efbf806c5f0c422b08a33d5ef607
7
+ data.tar.gz: a3e462914a5123ed99aa9eb23f0e13b011b9dd7593a4046c139d0d399ff33a9051efb09def9d6940545ab293c6e7e1e6a798d78b4976b7359b7f3f7aafae5b10
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vk_music (4.0.3)
4
+ vk_music (4.1.0)
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)
@@ -41,37 +42,39 @@ 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)
48
+ nokogiri (1.11.0)
49
+ mini_portile2 (~> 2.5.0)
50
+ racc (~> 1.4)
49
51
  ntlm-http (0.1.1)
50
52
  parallel (1.20.1)
51
- parser (2.7.2.0)
53
+ parser (3.0.0.0)
52
54
  ast (~> 2.4.1)
53
55
  pry (0.13.1)
54
56
  coderay (~> 1.1)
55
57
  method_source (~> 1.0)
56
58
  public_suffix (4.0.6)
59
+ racc (1.5.2)
57
60
  rainbow (3.0.0)
58
- rake (13.0.1)
59
- regexp_parser (2.0.0)
61
+ rake (13.0.3)
62
+ regexp_parser (2.0.3)
60
63
  rexml (3.2.4)
61
64
  rspec (3.10.0)
62
65
  rspec-core (~> 3.10.0)
63
66
  rspec-expectations (~> 3.10.0)
64
67
  rspec-mocks (~> 3.10.0)
65
- rspec-core (3.10.0)
68
+ rspec-core (3.10.1)
66
69
  rspec-support (~> 3.10.0)
67
- rspec-expectations (3.10.0)
70
+ rspec-expectations (3.10.1)
68
71
  diff-lcs (>= 1.2.0, < 2.0)
69
72
  rspec-support (~> 3.10.0)
70
- rspec-mocks (3.10.0)
73
+ rspec-mocks (3.10.1)
71
74
  diff-lcs (>= 1.2.0, < 2.0)
72
75
  rspec-support (~> 3.10.0)
73
- rspec-support (3.10.0)
74
- rubocop (1.6.1)
76
+ rspec-support (3.10.1)
77
+ rubocop (1.7.0)
75
78
  parallel (~> 1.10)
76
79
  parser (>= 2.7.1.5)
77
80
  rainbow (>= 2.2.2, < 4.0)
@@ -80,10 +83,10 @@ GEM
80
83
  rubocop-ast (>= 1.2.0, < 2.0)
81
84
  ruby-progressbar (~> 1.7)
82
85
  unicode-display_width (>= 1.4.0, < 2.0)
83
- rubocop-ast (1.3.0)
86
+ rubocop-ast (1.4.0)
84
87
  parser (>= 2.7.1.5)
85
- ruby-progressbar (1.10.1)
86
- simplecov (0.20.0)
88
+ ruby-progressbar (1.11.0)
89
+ simplecov (0.21.1)
87
90
  docile (~> 1.1)
88
91
  simplecov-html (~> 0.11)
89
92
  simplecov_json_formatter (~> 0.1)
@@ -94,12 +97,12 @@ GEM
94
97
  unf_ext (0.0.7.7)
95
98
  unicode-display_width (1.7.0)
96
99
  vcr (6.0.0)
97
- webmock (3.10.0)
100
+ webmock (3.11.0)
98
101
  addressable (>= 2.3.6)
99
102
  crack (>= 0.3.2)
100
103
  hashdiff (>= 0.4.0, < 2.0.0)
101
104
  webrobots (0.1.2)
102
- yard (0.9.25)
105
+ yard (0.9.26)
103
106
 
104
107
  PLATFORMS
105
108
  ruby
data/README.md CHANGED
@@ -81,6 +81,14 @@ You can load up to 10 audios attached to some post. Those audios will be returne
81
81
  audios = client.post(url: "link")
82
82
  ```
83
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
+
84
92
  ### Getting audio URL
85
93
 
86
94
  To get audio URL you should go through following chain:
@@ -125,7 +125,7 @@ module VkMusic
125
125
  Utility::WallLoader.call(agent, id, owner_id, post_id)
126
126
  end
127
127
 
128
- # 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)+
129
129
  # @param url [String]
130
130
  # @param owner_id [Integer]
131
131
  # @param post_id [Integer]
@@ -138,6 +138,18 @@ module VkMusic
138
138
  Utility::PostLoader.call(agent, id, owner_id, post_id)
139
139
  end
140
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
+
141
153
  # Get audios with download URLs by their IDs and secrets
142
154
  # @param args [Array<Audio, (owner_id, audio_id, secret_1, secret_2),
143
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
@@ -11,6 +11,10 @@ module VkMusic
11
11
  PLAYLIST_POSTFIX = PlaylistUrlParser::VK_PLAYLIST_URL_POSTFIX
12
12
  public_constant :PLAYLIST_POSTFIX
13
13
 
14
+ # Artist URL postfix
15
+ ARTIST_POSTFIX = ArtistUrlParser::ARTIST_POSTFIX
16
+ public_constant :ARTIST_POSTFIX
17
+
14
18
  # End of post URL
15
19
  POST_POSTFIX = PostUrlParser::POST_POSTFIX
16
20
  public_constant :POST_POSTFIX
@@ -32,6 +36,7 @@ module VkMusic
32
36
  def self.call(data)
33
37
  case data
34
38
  when PLAYLIST_POSTFIX then :playlist
39
+ when ARTIST_POSTFIX then :artist
35
40
  when POST_POSTFIX then :post
36
41
  when WALL_POSTFIX then :wall
37
42
  when AUDIOS_POSTFIX, PROFILE_URL then :audios
@@ -2,6 +2,6 @@
2
2
 
3
3
  module VkMusic
4
4
  # Library version.
5
- VERSION = '4.0.3'
5
+ VERSION = '4.1.0'
6
6
  public_constant :VERSION
7
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.3
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fizvlad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-03 00:00:00.000000000 Z
11
+ date: 2021-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -103,6 +103,7 @@ files:
103
103
  - lib/vk_music/client.rb
104
104
  - lib/vk_music/playlist.rb
105
105
  - lib/vk_music/request.rb
106
+ - lib/vk_music/request/artist.rb
106
107
  - lib/vk_music/request/audios_reload.rb
107
108
  - lib/vk_music/request/base.rb
108
109
  - lib/vk_music/request/login.rb
@@ -114,6 +115,8 @@ files:
114
115
  - lib/vk_music/request/search.rb
115
116
  - lib/vk_music/request/wall_section.rb
116
117
  - lib/vk_music/utility.rb
118
+ - lib/vk_music/utility/artist_loader.rb
119
+ - lib/vk_music/utility/artist_url_parser.rb
117
120
  - lib/vk_music/utility/audio_data_parser.rb
118
121
  - lib/vk_music/utility/audio_items_parser.rb
119
122
  - lib/vk_music/utility/audio_node_parser.rb
@@ -135,6 +138,7 @@ files:
135
138
  - lib/vk_music/utility/wall_loader.rb
136
139
  - lib/vk_music/version.rb
137
140
  - lib/vk_music/web_parser.rb
141
+ - lib/vk_music/web_parser/artist.rb
138
142
  - lib/vk_music/web_parser/audios_reload.rb
139
143
  - lib/vk_music/web_parser/base.rb
140
144
  - lib/vk_music/web_parser/login.rb