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 +4 -4
- data/Gemfile.lock +70 -69
- data/lib/vk_music/audio.rb +2 -1
- data/lib/vk_music/client.rb +67 -35
- data/lib/vk_music/constants.rb +1 -1
- data/lib/vk_music/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6142de69f08e3ca82697048c3062fc42eea675370f64e678433f8587edc4011e
|
4
|
+
data.tar.gz: 8321b28592040daf8af1880c0fb15a1969ba33017cdd9a2919063c43f446ce9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21d19b28d4141f33ae545a5216ec6ee192df00de769b9f8cb2f9b856a997662d8bd31560f1846dac7370b142d8182baa0789d3dfa2599afc7d8bf8408f142ea5
|
7
|
+
data.tar.gz: e431fd771443125940ef2bb3fc611b63d3f9c7d3818caf0712af3103331f6d0643c02b3bdf5aacba61852447e10ef854cfeeb9b47a3a63278a9349585094f751
|
data/Gemfile.lock
CHANGED
@@ -1,69 +1,70 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
vk_music (3.1.
|
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.
|
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.
|
21
|
-
logger (1.4.
|
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.
|
35
|
-
mini_portile2 (2.4.0)
|
36
|
-
minitest (5.
|
37
|
-
net-http-digest_auth (1.4.1)
|
38
|
-
net-http-persistent (2.9.4)
|
39
|
-
nokogiri (1.10.
|
40
|
-
mini_portile2 (~> 2.4.0)
|
41
|
-
nokogiri (1.10.
|
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.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
data/lib/vk_music/audio.rb
CHANGED
@@ -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(".
|
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
|
)
|
data/lib/vk_music/client.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
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
|
-
|
505
|
+
# Check whether need to make additional requests
|
527
506
|
up_to = real_size if (up_to < 0 || up_to > real_size)
|
528
|
-
list =
|
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:
|
542
|
-
owner_id:
|
543
|
-
access_hash:
|
544
|
-
title:
|
545
|
-
subtitle:
|
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]
|
data/lib/vk_music/constants.rb
CHANGED
@@ -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+)/
|
data/lib/vk_music/version.rb
CHANGED
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.
|
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-
|
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.
|
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
|