vk_music 3.1.1 → 3.1.6

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: fa5586e89dfad05d417c5b0c2466a561091c4a9383857da45fee1ee126f8b6a5
4
- data.tar.gz: f4c788d950d1a36e25df46e7edbfe4507dc21078f35956f6503f18832c91b7c0
3
+ metadata.gz: 6142de69f08e3ca82697048c3062fc42eea675370f64e678433f8587edc4011e
4
+ data.tar.gz: 8321b28592040daf8af1880c0fb15a1969ba33017cdd9a2919063c43f446ce9e
5
5
  SHA512:
6
- metadata.gz: 99793ea61b1020faa0290d94adfcbb9734deb1f7770a8f9fb5bd390ed686fe138d32f72ce5a4d2ebb80d120ed98af19179f6481d810aba63163f158d8fe05ab8
7
- data.tar.gz: 0274015ac09a8189c09fdb9979c784607a08c67b4f090149e3306b73915cfd68b78c2aa729f117bf392e8bfff42e432dd303843bb7db0afe27a39f8bcd45423c
6
+ metadata.gz: 21d19b28d4141f33ae545a5216ec6ee192df00de769b9f8cb2f9b856a997662d8bd31560f1846dac7370b142d8182baa0789d3dfa2599afc7d8bf8408f142ea5
7
+ data.tar.gz: e431fd771443125940ef2bb3fc611b63d3f9c7d3818caf0712af3103331f6d0643c02b3bdf5aacba61852447e10ef854cfeeb9b47a3a63278a9349585094f751
@@ -1,69 +1,70 @@
1
- PATH
2
- remote: .
3
- specs:
4
- vk_music (3.1.0)
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.2)
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.0)
21
- logger (1.4.1)
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)
33
- mime-types-data (~> 3.2015)
34
- mime-types-data (3.2019.1009)
35
- mini_portile2 (2.4.0)
36
- minitest (5.13.0)
37
- net-http-digest_auth (1.4.1)
38
- net-http-persistent (2.9.4)
39
- nokogiri (1.10.8)
40
- mini_portile2 (~> 2.4.0)
41
- nokogiri (1.10.8-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.6)
51
- webrobots (0.1.2)
52
- yard (0.9.20)
53
-
54
- PLATFORMS
55
- ruby
56
- x64-mingw32
57
-
58
- DEPENDENCIES
59
- bundler (~> 2.0)
60
- logger (~> 1.4)
61
- mechanize (~> 2.7)
62
- minitest (~> 5.0)
63
- pry (~> 0.12.2)
64
- rake (~> 13.0)
65
- vk_music!
66
- yard (~> 0.9)
67
-
68
- BUNDLED WITH
69
- 2.0.2
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
@@ -120,6 +120,7 @@ module VkMusic
120
120
  @owner_id = owner_id
121
121
  @secret_1 = secret_1
122
122
  @secret_2 = secret_2
123
+ @secret_1 = @secret_2 if @secret_1.nil? || @secret_1.empty?
123
124
  @artist = artist.strip
124
125
  @title = title.strip
125
126
  @duration = duration
@@ -152,7 +153,7 @@ module VkMusic
152
153
  else
153
154
  # Probably audios from some post
154
155
  new(
155
- artist: node.at_css(".medias_audio_artist").text.strip,
156
+ artist: node.at_css(".medias_music_author").text.strip,
156
157
  title: Utility.plain_text(node.at_css(".medias_audio_title")).strip,
157
158
  duration: Utility.parse_duration(node.at_css(".medias_audio_dur").text)
158
159
  )
@@ -81,7 +81,7 @@ module VkMusic
81
81
  raise Exceptions::ParseError
82
82
  end
83
83
  raise ArgumentError unless owner_id && playlist_id
84
- use_web = up_to > 200 if use_web.nil?
84
+ use_web ||= (up_to <= 200)
85
85
  if use_web
86
86
  playlist_web(owner_id, playlist_id, access_hash, up_to: up_to)
87
87
  else
@@ -467,26 +467,7 @@ module VkMusic
467
467
  # @param up_to [Integer] if less than 0, all audios will be loaded.
468
468
  # @return [Playlist]
469
469
  def playlist_web(owner_id, playlist_id, access_hash = nil, up_to: -1)
470
- # Load first page and get info
471
- first_page = load_page_playlist(owner_id, playlist_id, access_hash, offset: 0)
472
- begin
473
- # Parse out essential data
474
- title = first_page.at_css(".audioPlaylist__title").text.strip
475
- subtitle = first_page.at_css(".audioPlaylist__subtitle").text.strip
476
-
477
- footer_node = first_page.at_css(".audioPlaylist__footer")
478
- if footer_node
479
- footer_match = footer_node.text.strip.match(/^\d+/)
480
- real_size = footer_match ? footer_match[0].to_i : 0
481
- else
482
- real_size = 0
483
- end
484
- rescue
485
- raise Exceptions::ParseError
486
- end
487
- # Now we can be sure we are on correct page and have essential data.
488
-
489
- first_page_audios = audios_from_page(first_page)
470
+ first_page_audios, title, subtitle, real_size = playlist_first_page_web(owner_id, playlist_id, access_hash || "")
490
471
 
491
472
  # Check whether need to make additional requests
492
473
  up_to = real_size if (up_to < 0 || up_to > real_size)
@@ -514,18 +495,16 @@ module VkMusic
514
495
  # @param up_to [Integer] if less than 0, all audios will be loaded.
515
496
  # @return [Playlist]
516
497
  def playlist_json(owner_id, playlist_id, access_hash, up_to: -1)
517
- # Trying to parse out audios
518
- first_json = load_json_playlist_section(owner_id, playlist_id, access_hash, offset: 0)
519
- begin
520
- first_data = first_json["data"][0]
521
- first_data_audios = audios_from_data(first_data["list"])
522
- rescue
523
- raise Exceptions::ParseError
498
+ if playlist_id == -1
499
+ first_audios, title, subtitle, real_size = playlist_first_page_json(owner_id, playlist_id, access_hash || "")
500
+ else
501
+ first_audios, title, subtitle, real_size = playlist_first_page_web(owner_id, playlist_id, access_hash || "")
524
502
  end
503
+ # NOTE: We need to load first page from web to be able to unmask links in future
525
504
 
526
- real_size = first_data["totalCount"]
505
+ # Check whether need to make additional requests
527
506
  up_to = real_size if (up_to < 0 || up_to > real_size)
528
- list = first_data_audios.first(up_to)
507
+ list = first_audios.first(up_to)
529
508
  while list.length < up_to do
530
509
  json = load_json_playlist_section(owner_id, playlist_id, access_hash, offset: list.length)
531
510
  audios = begin
@@ -538,11 +517,11 @@ module VkMusic
538
517
 
539
518
  begin
540
519
  Playlist.new(list,
541
- id: first_data["id"],
542
- owner_id: first_data["owner_id"],
543
- access_hash: first_data["access_hash"],
544
- title: CGI.unescapeHTML(first_data["title"].to_s),
545
- subtitle: CGI.unescapeHTML(first_data["subtitle"].to_s),
520
+ id: playlist_id,
521
+ owner_id: owner_id,
522
+ access_hash: access_hash,
523
+ title: title,
524
+ subtitle: subtitle,
546
525
  real_size: real_size
547
526
  )
548
527
  rescue
@@ -550,6 +529,59 @@ module VkMusic
550
529
  end
551
530
  end
552
531
 
532
+ ##
533
+ # Load playlist first page in web and return essential data.
534
+ # @note not suitable for user audios
535
+ # @param owner_id [Integer]
536
+ # @param playlist_id [Integer]
537
+ # @param access_hash [String, nil]
538
+ # @return [Array<Array, String, String, Integer>] array with audios from first page, title, subtitle and playlist real size.
539
+ def playlist_first_page_web(owner_id, playlist_id, access_hash)
540
+ first_page = load_page_playlist(owner_id, playlist_id, access_hash, offset: 0)
541
+ begin
542
+ # Parse out essential data
543
+ title = first_page.at_css(".audioPlaylist__title").text.strip
544
+ subtitle = first_page.at_css(".audioPlaylist__subtitle").text.strip
545
+
546
+ footer_node = first_page.at_css(".audioPlaylist__footer")
547
+ if footer_node
548
+ footer_text = footer_node.text.strip
549
+ footer_text.gsub!(/\s/, "") # Removing all whitespace to get rid of delimiters ('1 042 audios')
550
+ footer_match = footer_text.match(/^\d+/)
551
+ real_size = footer_match ? footer_match[0].to_i : 0
552
+ else
553
+ real_size = 0
554
+ end
555
+
556
+ first_audios = audios_from_page(first_page)
557
+ rescue
558
+ raise Exceptions::ParseError
559
+ end
560
+ [first_audios, title, subtitle, real_size]
561
+ end
562
+
563
+ ##
564
+ # Load playlist first page in JSON and return essential data.
565
+ # @param owner_id [Integer]
566
+ # @param playlist_id [Integer]
567
+ # @param access_hash [String, nil]
568
+ # @return [Array<Array, String, String, Integer>] array with audios from first page, title, subtitle and playlist real size.
569
+ def playlist_first_page_json(owner_id, playlist_id, access_hash)
570
+ first_json = load_json_playlist_section(owner_id, playlist_id, access_hash, offset: 0)
571
+ begin
572
+ first_data = first_json["data"][0]
573
+ first_data_audios = audios_from_data(first_data["list"])
574
+ rescue
575
+ raise Exceptions::ParseError
576
+ end
577
+
578
+ real_size = first_data["totalCount"]
579
+ title = CGI.unescapeHTML(first_data["title"].to_s)
580
+ subtitle = CGI.unescapeHTML(first_data["subtitle"].to_s)
581
+
582
+ [first_data_audios, title, subtitle, real_size]
583
+ end
584
+
553
585
  ##
554
586
  # Found playlist URLs on *global* search page.
555
587
  # @param obj [Mechanize::Page, String, URI]
@@ -52,7 +52,7 @@ module VkMusic
52
52
  VK_AUDIOS_URL_POSTFIX = /^audios(-?\d+)$/
53
53
  ##
54
54
  # Playlist URL regular expression.
55
- VK_PLAYLIST_URL_POSTFIX = /.*(?:audio_playlist|album\/)(-?\d+)_(\d+)(?:(?:(?:.*(?=&access_hash=)&access_hash=)|\/|%2F|_)([\da-z]+))?/
55
+ VK_PLAYLIST_URL_POSTFIX = /.*(?:audio_playlist|album\/|playlist\/)(-?\d+)_(\d+)(?:(?:(?:.*(?=&access_hash=)&access_hash=)|\/|%2F|_)([\da-z]+))?/
56
56
  ##
57
57
  # Post URL regular expression #1.
58
58
  VK_POST_URL_POSTFIX = /.*post(-?\d+)_(\d+)/
@@ -1,5 +1,5 @@
1
1
  module VkMusic
2
2
  ##
3
3
  # Library version.
4
- VERSION = "3.1.1"
4
+ VERSION = "3.1.6"
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.1
4
+ version: 3.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fizvlad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2020-09-07 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.0.4
189
+ rubygems_version: 3.1.2
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Provides interface to work with VK music via HTTP requests