vk_music 4.0.2 → 4.1.3

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: 982d3964597ca683823d8dfd1aff172ef5f117b740e9020aabf5019cb43beea5
4
- data.tar.gz: 6bd53fb80d6105287e0db7e2b6af63c224d5ce366b4e227cbb0d310d49c167ec
3
+ metadata.gz: 3c9b4724b7091c0d060e8ea09cf8ee5686f0b9dc62c912f121b35186ea096a3e
4
+ data.tar.gz: 38a52270b5b853898c9d7c0f6393c36bc1f2191df0b067659491308237fe7e27
5
5
  SHA512:
6
- metadata.gz: d15ced8f7a23fdce6ee9304264092b11fceeb93d78f213ff1be8b2e47566c334011b1f8065d88e7125c81df5b4939ca21ee9f986e72f2a13c183edd35c861304
7
- data.tar.gz: 39294ec31d752dc92147916a69f2460110fad028ff7115210bbfae19b786707c7dbc9e7cee5f19a3254b668605785cde10c3fde40cc93d1bd80825415da0a4aa
6
+ metadata.gz: cabca681df9bd70cb047d55172cea71ef1dd1db9fb57f94663a5a74e4223a7a732ee1ed6360119fd78da75aecedb8e00098cb82f6a911a26aec1dcb25af5f568
7
+ data.tar.gz: a9e92369c0dc3525718aac77e5b1a2d68f74ff127cb9067d257c9cd32db7cac3d60d48800a4160d6968e9965ab1874c67c438bbd588a8b3fadf21290454ebda1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vk_music (4.0.2)
4
+ vk_music (4.1.3)
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,52 +27,55 @@ GEM
26
27
  hashdiff (1.0.1)
27
28
  http-cookie (1.0.3)
28
29
  domain_name (~> 0.5)
29
- json (2.4.1)
30
- logger (1.4.2)
31
- mechanize (2.7.6)
32
- domain_name (~> 0.5, >= 0.5.1)
33
- http-cookie (~> 1.0)
34
- mime-types (>= 1.17.2)
35
- net-http-digest_auth (~> 1.1, >= 1.1.1)
36
- net-http-persistent (>= 2.5.2)
37
- nokogiri (~> 1.6)
38
- ntlm-http (~> 0.1, >= 0.1.1)
39
- webrobots (>= 0.0.9, < 0.2)
30
+ json (2.5.1)
31
+ logger (1.4.3)
32
+ mechanize (2.8.0)
33
+ addressable (~> 2.7)
34
+ domain_name (~> 0.5, >= 0.5.20190701)
35
+ http-cookie (~> 1.0, >= 1.0.3)
36
+ mime-types (~> 3.0)
37
+ net-http-digest_auth (~> 1.4, >= 1.4.1)
38
+ net-http-persistent (>= 2.5.2, < 5.0.dev)
39
+ nokogiri (~> 1.11, >= 1.11.2)
40
+ rubyntlm (~> 0.6, >= 0.6.3)
41
+ webrick (~> 1.7)
42
+ webrobots (~> 0.1.2)
40
43
  method_source (1.0.0)
41
44
  mime-types (3.3.1)
42
45
  mime-types-data (~> 3.2015)
43
- mime-types-data (3.2020.1104)
44
- mini_portile2 (2.4.0)
46
+ mime-types-data (3.2021.0225)
47
+ mini_portile2 (2.5.1)
45
48
  net-http-digest_auth (1.4.1)
46
49
  net-http-persistent (2.9.4)
47
- nokogiri (1.10.10)
48
- mini_portile2 (~> 2.4.0)
49
- ntlm-http (0.1.1)
50
+ nokogiri (1.11.3)
51
+ mini_portile2 (~> 2.5.0)
52
+ racc (~> 1.4)
50
53
  parallel (1.20.1)
51
- parser (2.7.2.0)
54
+ parser (3.0.0.0)
52
55
  ast (~> 2.4.1)
53
56
  pry (0.13.1)
54
57
  coderay (~> 1.1)
55
58
  method_source (~> 1.0)
56
59
  public_suffix (4.0.6)
60
+ racc (1.5.2)
57
61
  rainbow (3.0.0)
58
- rake (13.0.1)
59
- regexp_parser (2.0.0)
60
- rexml (3.2.4)
62
+ rake (13.0.3)
63
+ regexp_parser (2.0.3)
64
+ rexml (3.2.5)
61
65
  rspec (3.10.0)
62
66
  rspec-core (~> 3.10.0)
63
67
  rspec-expectations (~> 3.10.0)
64
68
  rspec-mocks (~> 3.10.0)
65
- rspec-core (3.10.0)
69
+ rspec-core (3.10.1)
66
70
  rspec-support (~> 3.10.0)
67
- rspec-expectations (3.10.0)
71
+ rspec-expectations (3.10.1)
68
72
  diff-lcs (>= 1.2.0, < 2.0)
69
73
  rspec-support (~> 3.10.0)
70
- rspec-mocks (3.10.0)
74
+ rspec-mocks (3.10.1)
71
75
  diff-lcs (>= 1.2.0, < 2.0)
72
76
  rspec-support (~> 3.10.0)
73
- rspec-support (3.10.0)
74
- rubocop (1.6.1)
77
+ rspec-support (3.10.1)
78
+ rubocop (1.7.0)
75
79
  parallel (~> 1.10)
76
80
  parser (>= 2.7.1.5)
77
81
  rainbow (>= 2.2.2, < 4.0)
@@ -80,10 +84,11 @@ GEM
80
84
  rubocop-ast (>= 1.2.0, < 2.0)
81
85
  ruby-progressbar (~> 1.7)
82
86
  unicode-display_width (>= 1.4.0, < 2.0)
83
- rubocop-ast (1.3.0)
87
+ rubocop-ast (1.4.0)
84
88
  parser (>= 2.7.1.5)
85
- ruby-progressbar (1.10.1)
86
- simplecov (0.20.0)
89
+ ruby-progressbar (1.11.0)
90
+ rubyntlm (0.6.3)
91
+ simplecov (0.21.1)
87
92
  docile (~> 1.1)
88
93
  simplecov-html (~> 0.11)
89
94
  simplecov_json_formatter (~> 0.1)
@@ -94,12 +99,13 @@ GEM
94
99
  unf_ext (0.0.7.7)
95
100
  unicode-display_width (1.7.0)
96
101
  vcr (6.0.0)
97
- webmock (3.10.0)
102
+ webmock (3.11.0)
98
103
  addressable (>= 2.3.6)
99
104
  crack (>= 0.3.2)
100
105
  hashdiff (>= 0.4.0, < 2.0.0)
106
+ webrick (1.7.0)
101
107
  webrobots (0.1.2)
102
- yard (0.9.25)
108
+ yard (0.9.26)
103
109
 
104
110
  PLATFORMS
105
111
  ruby
@@ -118,4 +124,4 @@ DEPENDENCIES
118
124
  yard
119
125
 
120
126
  BUNDLED WITH
121
- 2.1.4
127
+ 2.2.4
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:
@@ -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
@@ -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
@@ -10,10 +10,10 @@ module VkMusic
10
10
  # @return [Audio]
11
11
  def call(data, client_id)
12
12
  url_encoded = get_url_encoded(data)
13
- _add_hash, _edit_hash, action_hash, _delete_hash, _teplace_hash, url_hash = 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: action_hash, secret2: url_hash,
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)
@@ -1,6 +1,7 @@
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
@@ -11,6 +12,10 @@ module VkMusic
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module VkMusic
4
4
  # Library version.
5
- VERSION = '4.0.2'
5
+ VERSION = '4.1.3'
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
@@ -12,9 +12,13 @@ module VkMusic
12
12
  POST_ANCHOR_NAME_REGEX = /post(-?\d+)_(\d+)/.freeze
13
13
  private_constant :POST_ANCHOR_NAME_REGEX
14
14
 
15
+ # CSS selector for link in basis
16
+ BASIS_LINK_SELECTOR = '.basisProfile a,.basisGroup a,.BasisProfile a,.BasisGroup a'
17
+ private_constant :BASIS_LINK_SELECTOR
18
+
15
19
  # Profile id
16
20
  def id
17
- link = node.link_with(href: ID_CONTAINING_HREF, css: '.basisProfile a,.basisGroup a')
21
+ link = node.link_with(href: ID_CONTAINING_HREF, css: BASIS_LINK_SELECTOR)
18
22
  return unless link
19
23
 
20
24
  Integer(link.href.match(ID_CONTAINING_HREF).captures.first, 10)
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.2
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fizvlad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-17 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -103,7 +103,8 @@ 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/audios.rb
106
+ - lib/vk_music/request/artist.rb
107
+ - lib/vk_music/request/audios_reload.rb
107
108
  - lib/vk_music/request/base.rb
108
109
  - lib/vk_music/request/login.rb
109
110
  - lib/vk_music/request/my_page.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,7 +138,8 @@ 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
138
- - lib/vk_music/web_parser/audios.rb
141
+ - lib/vk_music/web_parser/artist.rb
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
141
145
  - lib/vk_music/web_parser/my_page.rb
@@ -168,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
172
  - !ruby/object:Gem::Version
169
173
  version: '0'
170
174
  requirements: []
171
- rubygems_version: 3.1.2
175
+ rubygems_version: 3.2.4
172
176
  signing_key:
173
177
  specification_version: 4
174
178
  summary: A library to work with audios on popular Russian social network