vk_music 3.1.7 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +3 -0
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/.rubocop.yml +56 -0
- data/Gemfile +38 -10
- data/Gemfile.lock +123 -70
- data/LICENSE.txt +0 -0
- data/README.md +111 -94
- data/Rakefile +12 -22
- data/bin/console +18 -24
- data/lib/vk_music.rb +32 -18
- data/lib/vk_music/audio.rb +111 -187
- data/lib/vk_music/client.rb +187 -677
- data/lib/vk_music/playlist.rb +44 -97
- data/lib/vk_music/request.rb +13 -0
- data/lib/vk_music/request/audios.rb +29 -0
- data/lib/vk_music/request/base.rb +75 -0
- data/lib/vk_music/request/login.rb +35 -0
- data/lib/vk_music/request/my_page.rb +21 -0
- data/lib/vk_music/request/playlist.rb +31 -0
- data/lib/vk_music/request/playlist_section.rb +35 -0
- data/lib/vk_music/request/post.rb +22 -0
- data/lib/vk_music/request/profile.rb +24 -0
- data/lib/vk_music/request/search.rb +34 -0
- data/lib/vk_music/request/wall_section.rb +34 -0
- data/lib/vk_music/utility.rb +8 -78
- data/lib/vk_music/utility/audio_data_parser.rb +37 -0
- data/lib/vk_music/utility/audio_items_parser.rb +18 -0
- data/lib/vk_music/utility/audio_node_parser.rb +59 -0
- data/lib/vk_music/utility/audios_from_ids_loader.rb +21 -0
- data/lib/vk_music/utility/audios_ids_getter.rb +25 -0
- data/lib/vk_music/utility/audios_loader.rb +37 -0
- data/lib/vk_music/utility/data_type_guesser.rb +43 -0
- data/lib/vk_music/utility/duration_parser.rb +17 -0
- data/lib/vk_music/utility/last_profile_post_loader.rb +26 -0
- data/lib/vk_music/utility/link_decoder.rb +106 -0
- data/lib/vk_music/utility/node_text_children_reader.rb +14 -0
- data/lib/vk_music/utility/playlist_loader.rb +30 -0
- data/lib/vk_music/utility/playlist_node_parser.rb +21 -0
- data/lib/vk_music/utility/playlist_section_loader.rb +29 -0
- data/lib/vk_music/utility/playlist_url_parser.rb +32 -0
- data/lib/vk_music/utility/post_loader.rb +23 -0
- data/lib/vk_music/utility/post_url_parser.rb +24 -0
- data/lib/vk_music/utility/profile_id_resolver.rb +51 -0
- data/lib/vk_music/utility/wall_loader.rb +25 -0
- data/lib/vk_music/version.rb +8 -5
- data/lib/vk_music/web_parser.rb +9 -0
- data/lib/vk_music/web_parser/audios.rb +20 -0
- data/lib/vk_music/web_parser/base.rb +27 -0
- data/lib/vk_music/web_parser/login.rb +13 -0
- data/lib/vk_music/web_parser/my_page.rb +19 -0
- data/lib/vk_music/web_parser/playlist.rb +33 -0
- data/lib/vk_music/web_parser/playlist_section.rb +53 -0
- data/lib/vk_music/web_parser/post.rb +15 -0
- data/lib/vk_music/web_parser/profile.rb +33 -0
- data/lib/vk_music/web_parser/search.rb +56 -0
- data/lib/vk_music/web_parser/wall_section.rb +53 -0
- data/vk_music.gemspec +36 -40
- metadata +58 -77
- data/.travis.yml +0 -7
- data/bin/setup +0 -8
- data/lib/vk_music/constants.rb +0 -78
- data/lib/vk_music/exceptions.rb +0 -21
- data/lib/vk_music/link_decoder.rb +0 -102
- data/lib/vk_music/utility/log.rb +0 -51
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VkMusic
|
4
|
+
module WebParser
|
5
|
+
# Post page web parser
|
6
|
+
class Post < Base
|
7
|
+
# @return [Array<Audio>]
|
8
|
+
def audios
|
9
|
+
node.css('.wi_body > .pi_medias .medias_audio').map do |el|
|
10
|
+
Utility::AudioNodeParser.call(el, @client_id)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VkMusic
|
4
|
+
module WebParser
|
5
|
+
# Profile page parser
|
6
|
+
class Profile < Base
|
7
|
+
# Regex for href which contains id of profile
|
8
|
+
ID_CONTAINING_HREF = /(?:audios|photo|write|owner_id=|friends\?id=)(-?\d+)/.freeze
|
9
|
+
private_constant :ID_CONTAINING_HREF
|
10
|
+
|
11
|
+
# Regex for ID of .wall_item anchor
|
12
|
+
POST_ANCHOR_NAME_REGEX = /post(-?\d+)_(\d+)/.freeze
|
13
|
+
private_constant :POST_ANCHOR_NAME_REGEX
|
14
|
+
|
15
|
+
# Profile id
|
16
|
+
def id
|
17
|
+
link = node.link_with(href: ID_CONTAINING_HREF, css: '.basisProfile a,.basisGroup a')
|
18
|
+
return unless link
|
19
|
+
|
20
|
+
Integer(link.href.match(ID_CONTAINING_HREF).captures.first, 10)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Last post ID
|
24
|
+
def last_post_id
|
25
|
+
ids = node.css('.wall_posts .wall_item').map do |el|
|
26
|
+
str = el.at_css('.post__anchor')&.attr('name')&.match(POST_ANCHOR_NAME_REGEX)&.captures&.last
|
27
|
+
str ? Integer(str, 10) : nil
|
28
|
+
end
|
29
|
+
ids.compact.max
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VkMusic
|
4
|
+
module WebParser
|
5
|
+
# Audio search page parser
|
6
|
+
class Search < Base
|
7
|
+
# Audios found
|
8
|
+
# @return [Array<Audio>]
|
9
|
+
def audios
|
10
|
+
title_index = search_result_blocks.find_index { |node| node.inner_text.include?('Все аудиозаписи') }
|
11
|
+
return [] if title_index.nil?
|
12
|
+
|
13
|
+
block = search_result_blocks[title_index + 1]
|
14
|
+
|
15
|
+
Utility::AudioItemsParser.call(block, @client_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Path to page with all results
|
19
|
+
# @return [String?]
|
20
|
+
def audios_all_path
|
21
|
+
title = search_result_blocks.find { |node| node.inner_text.include?('Все аудиозаписи') }
|
22
|
+
return if title.nil?
|
23
|
+
|
24
|
+
title.at_css('a').attribute('href').value
|
25
|
+
end
|
26
|
+
|
27
|
+
# Playlists found
|
28
|
+
# @return [Array<Playlist>]
|
29
|
+
def playlists
|
30
|
+
title_index = search_result_blocks.find_index { |node| node.inner_text.include?('Альбомы') }
|
31
|
+
return [] if title_index.nil?
|
32
|
+
|
33
|
+
block = search_result_blocks[title_index + 1]
|
34
|
+
|
35
|
+
block.css('.audioPlaylists__item').map do |elem|
|
36
|
+
Utility::PlaylistNodeParser.call(elem)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Path to page with all results
|
41
|
+
# @return [String?]
|
42
|
+
def playlists_all_path
|
43
|
+
title = search_result_blocks.find { |node| node.inner_text.include?('Альбомы') }
|
44
|
+
return if title.nil?
|
45
|
+
|
46
|
+
title.at_css('a').attribute('href').value
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def search_result_blocks
|
52
|
+
@search_result_blocks ||= node.css('.AudioBlock').children
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VkMusic
|
4
|
+
module WebParser
|
5
|
+
# WallSection JSON parser
|
6
|
+
class WallSection < Base
|
7
|
+
# Parsed JSON
|
8
|
+
def data
|
9
|
+
@data ||= json['data'].first || {}
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Array<Audio>]
|
13
|
+
def audios
|
14
|
+
return unless data&.key?('list')
|
15
|
+
|
16
|
+
data['list'].map do |el|
|
17
|
+
Utility::AudioDataParser.call(el, @client_id)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [String]
|
22
|
+
def title
|
23
|
+
return unless data&.key?('title')
|
24
|
+
|
25
|
+
data['title'].to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [String?]
|
29
|
+
def subtitle
|
30
|
+
return unless data&.key?('rawDescription')
|
31
|
+
|
32
|
+
re = data['rawDescription']
|
33
|
+
return if re.nil? || re.empty?
|
34
|
+
|
35
|
+
re
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Integer?]
|
39
|
+
def real_size
|
40
|
+
return unless data&.key?('totalCount')
|
41
|
+
|
42
|
+
data['totalCount']
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Boolean]
|
46
|
+
def more?
|
47
|
+
return unless data&.key?('hasMore')
|
48
|
+
|
49
|
+
data['hasMore'].to_s == '1'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/vk_music.gemspec
CHANGED
@@ -1,40 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
spec.
|
9
|
-
spec.
|
10
|
-
|
11
|
-
spec.
|
12
|
-
|
13
|
-
spec.
|
14
|
-
spec.
|
15
|
-
|
16
|
-
spec.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
spec.metadata[
|
21
|
-
spec.metadata[
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
spec.
|
32
|
-
spec.
|
33
|
-
spec.
|
34
|
-
|
35
|
-
spec.add_runtime_dependency
|
36
|
-
|
37
|
-
spec.add_runtime_dependency "net-http-persistent", "2.9.4" # Required for mechanize. Future versions cause error.
|
38
|
-
spec.add_runtime_dependency "execjs", "~>2.7"
|
39
|
-
spec.add_runtime_dependency "json", "~>2.0"
|
40
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'vk_music/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'vk_music'
|
9
|
+
spec.version = VkMusic::VERSION
|
10
|
+
spec.authors = ['Fizvlad']
|
11
|
+
spec.email = ['fizvlad@mail.ru']
|
12
|
+
|
13
|
+
spec.summary = 'A library to work with audios on popular Russian social network'
|
14
|
+
spec.description = 'A library to work with audios on popular Russian social network'
|
15
|
+
spec.homepage = 'https://github.com/fizvlad/vk-music-rb'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.required_ruby_version = '>=2.7.1'
|
19
|
+
|
20
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
+
spec.metadata['source_code_uri'] = 'https://github.com/fizvlad/vk-music-rb'
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/fizvlad/vk-music-rb/releases'
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
end
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_runtime_dependency('execjs', '~> 2.7')
|
32
|
+
spec.add_runtime_dependency('json', '~> 2.3')
|
33
|
+
spec.add_runtime_dependency('logger', '~> 1.4')
|
34
|
+
spec.add_runtime_dependency('mechanize', '~> 2.7')
|
35
|
+
spec.add_runtime_dependency('net-http-persistent', '2.9.4')
|
36
|
+
end
|
metadata
CHANGED
@@ -1,71 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vk_music
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
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-
|
11
|
+
date: 2020-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '2.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '13.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '13.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: yard
|
14
|
+
name: execjs
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
44
16
|
requirements:
|
45
17
|
- - "~>"
|
46
18
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
49
21
|
prerelease: false
|
50
22
|
version_requirements: !ruby/object:Gem::Requirement
|
51
23
|
requirements:
|
52
24
|
- - "~>"
|
53
25
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
26
|
+
version: '2.7'
|
55
27
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
28
|
+
name: json
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
58
30
|
requirements:
|
59
31
|
- - "~>"
|
60
32
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
type: :
|
33
|
+
version: '2.3'
|
34
|
+
type: :runtime
|
63
35
|
prerelease: false
|
64
36
|
version_requirements: !ruby/object:Gem::Requirement
|
65
37
|
requirements:
|
66
38
|
- - "~>"
|
67
39
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
40
|
+
version: '2.3'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: logger
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,61 +80,70 @@ dependencies:
|
|
108
80
|
- - '='
|
109
81
|
- !ruby/object:Gem::Version
|
110
82
|
version: 2.9.4
|
111
|
-
|
112
|
-
name: execjs
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '2.7'
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '2.7'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: json
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '2.0'
|
132
|
-
type: :runtime
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '2.0'
|
139
|
-
description: Library to work with audios on popular Russian social network vk.com.
|
140
|
-
VK disabled their public API for audios, so it is now necessary to use parsers instead.
|
83
|
+
description: A library to work with audios on popular Russian social network
|
141
84
|
email:
|
142
85
|
- fizvlad@mail.ru
|
143
86
|
executables: []
|
144
87
|
extensions: []
|
145
88
|
extra_rdoc_files: []
|
146
89
|
files:
|
90
|
+
- ".env.example"
|
147
91
|
- ".gitignore"
|
148
|
-
- ".
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
149
94
|
- Gemfile
|
150
95
|
- Gemfile.lock
|
151
96
|
- LICENSE.txt
|
152
97
|
- README.md
|
153
98
|
- Rakefile
|
154
99
|
- bin/console
|
155
|
-
- bin/setup
|
156
100
|
- lib/vk_music.rb
|
157
101
|
- lib/vk_music/audio.rb
|
158
102
|
- lib/vk_music/client.rb
|
159
|
-
- lib/vk_music/constants.rb
|
160
|
-
- lib/vk_music/exceptions.rb
|
161
|
-
- lib/vk_music/link_decoder.rb
|
162
103
|
- lib/vk_music/playlist.rb
|
104
|
+
- lib/vk_music/request.rb
|
105
|
+
- lib/vk_music/request/audios.rb
|
106
|
+
- lib/vk_music/request/base.rb
|
107
|
+
- lib/vk_music/request/login.rb
|
108
|
+
- lib/vk_music/request/my_page.rb
|
109
|
+
- lib/vk_music/request/playlist.rb
|
110
|
+
- lib/vk_music/request/playlist_section.rb
|
111
|
+
- lib/vk_music/request/post.rb
|
112
|
+
- lib/vk_music/request/profile.rb
|
113
|
+
- lib/vk_music/request/search.rb
|
114
|
+
- lib/vk_music/request/wall_section.rb
|
163
115
|
- lib/vk_music/utility.rb
|
164
|
-
- lib/vk_music/utility/
|
116
|
+
- lib/vk_music/utility/audio_data_parser.rb
|
117
|
+
- lib/vk_music/utility/audio_items_parser.rb
|
118
|
+
- lib/vk_music/utility/audio_node_parser.rb
|
119
|
+
- lib/vk_music/utility/audios_from_ids_loader.rb
|
120
|
+
- lib/vk_music/utility/audios_ids_getter.rb
|
121
|
+
- lib/vk_music/utility/audios_loader.rb
|
122
|
+
- lib/vk_music/utility/data_type_guesser.rb
|
123
|
+
- lib/vk_music/utility/duration_parser.rb
|
124
|
+
- lib/vk_music/utility/last_profile_post_loader.rb
|
125
|
+
- lib/vk_music/utility/link_decoder.rb
|
126
|
+
- lib/vk_music/utility/node_text_children_reader.rb
|
127
|
+
- lib/vk_music/utility/playlist_loader.rb
|
128
|
+
- lib/vk_music/utility/playlist_node_parser.rb
|
129
|
+
- lib/vk_music/utility/playlist_section_loader.rb
|
130
|
+
- lib/vk_music/utility/playlist_url_parser.rb
|
131
|
+
- lib/vk_music/utility/post_loader.rb
|
132
|
+
- lib/vk_music/utility/post_url_parser.rb
|
133
|
+
- lib/vk_music/utility/profile_id_resolver.rb
|
134
|
+
- lib/vk_music/utility/wall_loader.rb
|
165
135
|
- lib/vk_music/version.rb
|
136
|
+
- lib/vk_music/web_parser.rb
|
137
|
+
- lib/vk_music/web_parser/audios.rb
|
138
|
+
- lib/vk_music/web_parser/base.rb
|
139
|
+
- lib/vk_music/web_parser/login.rb
|
140
|
+
- lib/vk_music/web_parser/my_page.rb
|
141
|
+
- lib/vk_music/web_parser/playlist.rb
|
142
|
+
- lib/vk_music/web_parser/playlist_section.rb
|
143
|
+
- lib/vk_music/web_parser/post.rb
|
144
|
+
- lib/vk_music/web_parser/profile.rb
|
145
|
+
- lib/vk_music/web_parser/search.rb
|
146
|
+
- lib/vk_music/web_parser/wall_section.rb
|
166
147
|
- vk_music.gemspec
|
167
148
|
homepage: https://github.com/fizvlad/vk-music-rb
|
168
149
|
licenses:
|
@@ -179,15 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
160
|
requirements:
|
180
161
|
- - ">="
|
181
162
|
- !ruby/object:Gem::Version
|
182
|
-
version: 2.
|
163
|
+
version: 2.7.1
|
183
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
165
|
requirements:
|
185
166
|
- - ">="
|
186
167
|
- !ruby/object:Gem::Version
|
187
168
|
version: '0'
|
188
169
|
requirements: []
|
189
|
-
rubygems_version: 3.1.
|
170
|
+
rubygems_version: 3.1.2
|
190
171
|
signing_key:
|
191
172
|
specification_version: 4
|
192
|
-
summary:
|
173
|
+
summary: A library to work with audios on popular Russian social network
|
193
174
|
test_files: []
|