vk_music 3.1.3 → 3.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vk_music/client.rb +65 -35
- data/lib/vk_music/constants.rb +1 -1
- data/lib/vk_music/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 745b91709f47cb2b6b5bcaa013824a51f836977ecbe4cd1259a74d4a6f56e8c8
|
4
|
+
data.tar.gz: 9a7a2e9998adcd73a0c87d2934c6e763e8c76fdedcf08f757543497395e64322
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bd33552a23e56c0372500fc1edc20736afed079f650d4405650a91a48d01300269aeb37f51935c2c9916c4ee52449b7abb29949e7b32eb572e4641ac0e05e13
|
7
|
+
data.tar.gz: a252e563da14bcf249e72ab997414dbdb14388fa2308f24afc99f0507d6c003bfd5f80e0335db8df30b8d1eb7300036c2380ad99fd47cf402083238891c4ba17
|
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,57 @@ 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_match = footer_node.text.strip.match(/^\d+/)
|
549
|
+
real_size = footer_match ? footer_match[0].to_i : 0
|
550
|
+
else
|
551
|
+
real_size = 0
|
552
|
+
end
|
553
|
+
|
554
|
+
first_audios = audios_from_page(first_page)
|
555
|
+
rescue
|
556
|
+
raise Exceptions::ParseError
|
557
|
+
end
|
558
|
+
[first_audios, title, subtitle, real_size]
|
559
|
+
end
|
560
|
+
|
561
|
+
##
|
562
|
+
# Load playlist first page in JSON and return essential data.
|
563
|
+
# @param owner_id [Integer]
|
564
|
+
# @param playlist_id [Integer]
|
565
|
+
# @param access_hash [String, nil]
|
566
|
+
# @return [Array<Array, String, String, Integer>] array with audios from first page, title, subtitle and playlist real size.
|
567
|
+
def playlist_first_page_json(owner_id, playlist_id, access_hash)
|
568
|
+
first_json = load_json_playlist_section(owner_id, playlist_id, access_hash, offset: 0)
|
569
|
+
begin
|
570
|
+
first_data = first_json["data"][0]
|
571
|
+
first_data_audios = audios_from_data(first_data["list"])
|
572
|
+
rescue
|
573
|
+
raise Exceptions::ParseError
|
574
|
+
end
|
575
|
+
|
576
|
+
real_size = first_data["totalCount"]
|
577
|
+
title = CGI.unescapeHTML(first_data["title"].to_s)
|
578
|
+
subtitle = CGI.unescapeHTML(first_data["subtitle"].to_s)
|
579
|
+
|
580
|
+
[first_data_audios, title, subtitle, real_size]
|
581
|
+
end
|
582
|
+
|
553
583
|
##
|
554
584
|
# Found playlist URLs on *global* search page.
|
555
585
|
# @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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fizvlad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04
|
11
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|