vk_music 3.1.6 → 3.1.7

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: 6142de69f08e3ca82697048c3062fc42eea675370f64e678433f8587edc4011e
4
- data.tar.gz: 8321b28592040daf8af1880c0fb15a1969ba33017cdd9a2919063c43f446ce9e
3
+ metadata.gz: 49d94fb81d001d5d050d274f14ab6a3931467097adb46aa84601444fba4ac312
4
+ data.tar.gz: b8b6433c2373a1229bf5e27e31d8bc5c7d4ae01840b0620f99e715707ddc665e
5
5
  SHA512:
6
- metadata.gz: 21d19b28d4141f33ae545a5216ec6ee192df00de769b9f8cb2f9b856a997662d8bd31560f1846dac7370b142d8182baa0789d3dfa2599afc7d8bf8408f142ea5
7
- data.tar.gz: e431fd771443125940ef2bb3fc611b63d3f9c7d3818caf0712af3103331f6d0643c02b3bdf5aacba61852447e10ef854cfeeb9b47a3a63278a9349585094f751
6
+ metadata.gz: ee9d28c4ef87b6fc12865ec267aeca8ddb24a9275c6c231f42fc68c6390b8fb9bfa8759f3d0f3b6f17e1d8e4ba8880b32976f987c0bde5edb4c1c3856a0a2ab1
7
+ data.tar.gz: 48451ee22f080a93a0d8fea4fbb468f1c45b97bc089dc87675663d602092ba2fb255826ef3b127129b7d6fe8855751ee6bc3869e0c59ccc8e5e4c413eb9be45d
@@ -1,70 +1,70 @@
1
- PATH
2
- remote: .
3
- specs:
4
- vk_music (3.1.5)
5
- execjs (~> 2.7)
6
- json (~> 2.0)
7
- logger (~> 1.4)
8
- mechanize (~> 2.7)
9
- net-http-persistent (= 2.9.4)
10
-
11
- GEM
12
- remote: https://rubygems.org/
13
- specs:
14
- coderay (1.1.3)
15
- domain_name (0.5.20190701)
16
- unf (>= 0.0.5, < 1.0.0)
17
- execjs (2.7.0)
18
- http-cookie (1.0.3)
19
- domain_name (~> 0.5)
20
- json (2.3.1)
21
- logger (1.4.2)
22
- mechanize (2.7.6)
23
- domain_name (~> 0.5, >= 0.5.1)
24
- http-cookie (~> 1.0)
25
- mime-types (>= 1.17.2)
26
- net-http-digest_auth (~> 1.1, >= 1.1.1)
27
- net-http-persistent (>= 2.5.2)
28
- nokogiri (~> 1.6)
29
- ntlm-http (~> 0.1, >= 0.1.1)
30
- webrobots (>= 0.0.9, < 0.2)
31
- method_source (0.9.2)
32
- mime-types (3.3.1)
33
- mime-types-data (~> 3.2015)
34
- mime-types-data (3.2020.0512)
35
- mini_portile2 (2.4.0)
36
- minitest (5.14.1)
37
- net-http-digest_auth (1.4.1)
38
- net-http-persistent (2.9.4)
39
- nokogiri (1.10.10)
40
- mini_portile2 (~> 2.4.0)
41
- nokogiri (1.10.10-x64-mingw32)
42
- mini_portile2 (~> 2.4.0)
43
- ntlm-http (0.1.1)
44
- pry (0.12.2)
45
- coderay (~> 1.1.0)
46
- method_source (~> 0.9.0)
47
- rake (13.0.1)
48
- unf (0.1.4)
49
- unf_ext
50
- unf_ext (0.0.7.7)
51
- unf_ext (0.0.7.7-x64-mingw32)
52
- webrobots (0.1.2)
53
- yard (0.9.25)
54
-
55
- PLATFORMS
56
- ruby
57
- x64-mingw32
58
-
59
- DEPENDENCIES
60
- bundler (~> 2.0)
61
- logger (~> 1.4)
62
- mechanize (~> 2.7)
63
- minitest (~> 5.0)
64
- pry (~> 0.12.2)
65
- rake (~> 13.0)
66
- vk_music!
67
- yard (~> 0.9)
68
-
69
- BUNDLED WITH
70
- 2.1.4
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vk_music (3.1.7)
5
+ execjs (~> 2.7)
6
+ json (~> 2.0)
7
+ logger (~> 1.4)
8
+ mechanize (~> 2.7)
9
+ net-http-persistent (= 2.9.4)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ coderay (1.1.3)
15
+ domain_name (0.5.20190701)
16
+ unf (>= 0.0.5, < 1.0.0)
17
+ execjs (2.7.0)
18
+ http-cookie (1.0.3)
19
+ domain_name (~> 0.5)
20
+ json (2.3.1)
21
+ logger (1.4.2)
22
+ mechanize (2.7.6)
23
+ domain_name (~> 0.5, >= 0.5.1)
24
+ http-cookie (~> 1.0)
25
+ mime-types (>= 1.17.2)
26
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
27
+ net-http-persistent (>= 2.5.2)
28
+ nokogiri (~> 1.6)
29
+ ntlm-http (~> 0.1, >= 0.1.1)
30
+ webrobots (>= 0.0.9, < 0.2)
31
+ method_source (0.9.2)
32
+ mime-types (3.3.1)
33
+ mime-types-data (~> 3.2015)
34
+ mime-types-data (3.2020.0512)
35
+ mini_portile2 (2.4.0)
36
+ minitest (5.14.1)
37
+ net-http-digest_auth (1.4.1)
38
+ net-http-persistent (2.9.4)
39
+ nokogiri (1.10.10)
40
+ mini_portile2 (~> 2.4.0)
41
+ nokogiri (1.10.10-x64-mingw32)
42
+ mini_portile2 (~> 2.4.0)
43
+ ntlm-http (0.1.1)
44
+ pry (0.12.2)
45
+ coderay (~> 1.1.0)
46
+ method_source (~> 0.9.0)
47
+ rake (13.0.1)
48
+ unf (0.1.4)
49
+ unf_ext
50
+ unf_ext (0.0.7.7)
51
+ unf_ext (0.0.7.7-x64-mingw32)
52
+ webrobots (0.1.2)
53
+ yard (0.9.25)
54
+
55
+ PLATFORMS
56
+ ruby
57
+ x64-mingw32
58
+
59
+ DEPENDENCIES
60
+ bundler (~> 2.0)
61
+ logger (~> 1.4)
62
+ mechanize (~> 2.7)
63
+ minitest (~> 5.0)
64
+ pry (~> 0.12.2)
65
+ rake (~> 13.0)
66
+ vk_music!
67
+ yard (~> 0.9)
68
+
69
+ BUNDLED WITH
70
+ 2.1.4
@@ -43,13 +43,12 @@ module VkMusic
43
43
  def find(query = "", type: :audio)
44
44
  raise ArgumentError if query.empty?
45
45
  uri = URI(Constants::URL::VK[:audios])
46
+ search_page = load_ajax(uri, { "q" => query })
46
47
  case type
47
48
  when :audio
48
- uri.query = Utility.hash_to_params({ "act" => "search", "q" => query })
49
- audios_from_page(uri)
49
+ audios_from_ajax(search_page)
50
50
  when :playlist
51
- uri.query = Utility.hash_to_params({ "q" => query, "tab" => "global" })
52
- urls = playlist_urls_from_page(uri)
51
+ urls = playlist_urls_from_page(search_page)
53
52
  urls.map { |url| playlist(url: url, up_to: 0, use_web: false) }
54
53
  else
55
54
  raise ArgumentError
@@ -363,6 +362,23 @@ module VkMusic
363
362
  raise Exceptions::ParseError, error.message, caller
364
363
  end
365
364
  end
365
+ ##
366
+ # Load response to AJAX post request.
367
+ # @param url [String, URI]
368
+ # @return [Nokogiri::XML::Document]
369
+ def load_ajax(url, query = {})
370
+ uri = URI(url) if url.class != URI
371
+ query["_ajax"] = 1
372
+ headers = { "Content-Type" => "application/x-www-form-urlencoded", "x-requested-with" => "XMLHttpRequest" }
373
+ VkMusic.debug("Loading #{uri} with query #{query}")
374
+ begin
375
+ page = @agent.post(uri, query, headers)
376
+ str = JSON.parse(page.body.strip)["data"][2]
377
+ Nokogiri::XML("<body>#{CGI.unescapeElement(str)}</body>")
378
+ rescue
379
+ raise Exceptions::RequestError
380
+ end
381
+ end
366
382
 
367
383
  ##
368
384
  # Load playlist web page.
@@ -458,6 +474,20 @@ module VkMusic
458
474
  raise Exceptions::ParseError
459
475
  end
460
476
  end
477
+ ##
478
+ # Load audios from AJAX data.
479
+ # @param page [Nokogiri::XML::Document]
480
+ # @return [Array<Audio>]
481
+ def audios_from_ajax(page)
482
+ begin
483
+ page.css(".audio_item.ai_has_btn").map do |elem|
484
+ data = JSON.parse(elem.attribute("data-audio"))
485
+ Audio.from_data(data, @id)
486
+ end
487
+ rescue
488
+ raise Exceptions::ParseError
489
+ end
490
+ end
461
491
 
462
492
  ##
463
493
  # Load playlist through web page requests.
@@ -1,5 +1,5 @@
1
1
  module VkMusic
2
2
  ##
3
3
  # Library version.
4
- VERSION = "3.1.6"
4
+ VERSION = "3.1.7"
5
5
  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: 3.1.6
4
+ version: 3.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fizvlad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-07 00:00:00.000000000 Z
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  requirements: []
189
- rubygems_version: 3.1.2
189
+ rubygems_version: 3.1.4
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Provides interface to work with VK music via HTTP requests