vk_music 2.1.5 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +81 -75
- data/Rakefile +25 -41
- data/bin/console +10 -2
- data/bin/setup +8 -0
- data/lib/vk_music.rb +18 -7
- data/lib/vk_music/audio.rb +42 -19
- data/lib/vk_music/client.rb +43 -28
- data/lib/vk_music/link_decoder.rb +0 -2
- data/lib/vk_music/utility.rb +23 -3
- data/lib/vk_music/version.rb +7 -0
- data/vk_music.gemspec +40 -22
- metadata +82 -50
- data/LICENSE +0 -9
- data/test/test_attached_audios_amount.rb +0 -82
- data/test/test_audios.rb +0 -92
- data/test/test_find.rb +0 -55
- data/test/test_from_id.rb +0 -69
- data/test/test_last_post_id.rb +0 -46
- data/test/test_login.rb +0 -29
- data/test/test_page_id.rb +0 -113
- data/test/test_playlist.rb +0 -109
- data/test/test_post.rb +0 -77
- data/test/test_wall.rb +0 -56
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a40ac2ba500bdf24f6ccb6e645216bd4716458d5c795c8a65acc82887dd37a0
|
|
4
|
+
data.tar.gz: 0ad38527b6a893916a904d3eca60f55aac5d534255cdcff1a0ff0f60ba0794e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 408afa4efb6f4ca2b4deb6f7670775bd8569cebab42d6d825f7cd4f60a3503ebc53b415b5046ad69254ca4d4ffb526858428a23f4fde4ba2cdb81eee05c245db
|
|
7
|
+
data.tar.gz: 64ee9349066a69fbef74d3b84cf03bea651bc30504eef7a009e243e5889bcf28be7281bbbfb8b20b491c2d748c2961531461c98a8c7966d0b0e3e8957b1eea97
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
vk_music (2.2.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
|
+
domain_name (0.5.20190701)
|
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
16
|
+
execjs (2.7.0)
|
|
17
|
+
http-cookie (1.0.3)
|
|
18
|
+
domain_name (~> 0.5)
|
|
19
|
+
json (2.2.0)
|
|
20
|
+
logger (1.4.1)
|
|
21
|
+
mechanize (2.7.6)
|
|
22
|
+
domain_name (~> 0.5, >= 0.5.1)
|
|
23
|
+
http-cookie (~> 1.0)
|
|
24
|
+
mime-types (>= 1.17.2)
|
|
25
|
+
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
|
26
|
+
net-http-persistent (>= 2.5.2)
|
|
27
|
+
nokogiri (~> 1.6)
|
|
28
|
+
ntlm-http (~> 0.1, >= 0.1.1)
|
|
29
|
+
webrobots (>= 0.0.9, < 0.2)
|
|
30
|
+
mime-types (3.3)
|
|
31
|
+
mime-types-data (~> 3.2015)
|
|
32
|
+
mime-types-data (3.2019.1009)
|
|
33
|
+
mini_portile2 (2.4.0)
|
|
34
|
+
minitest (5.12.2)
|
|
35
|
+
net-http-digest_auth (1.4.1)
|
|
36
|
+
net-http-persistent (2.9.4)
|
|
37
|
+
nokogiri (1.10.4-x64-mingw32)
|
|
38
|
+
mini_portile2 (~> 2.4.0)
|
|
39
|
+
ntlm-http (0.1.1)
|
|
40
|
+
rake (10.5.0)
|
|
41
|
+
unf (0.1.4)
|
|
42
|
+
unf_ext
|
|
43
|
+
unf_ext (0.0.7.6)
|
|
44
|
+
webrobots (0.1.2)
|
|
45
|
+
yard (0.9.20)
|
|
46
|
+
|
|
47
|
+
PLATFORMS
|
|
48
|
+
x64-mingw32
|
|
49
|
+
|
|
50
|
+
DEPENDENCIES
|
|
51
|
+
bundler (~> 2.0)
|
|
52
|
+
logger (~> 1.4)
|
|
53
|
+
mechanize (~> 2.7)
|
|
54
|
+
minitest (~> 5.0)
|
|
55
|
+
rake (~> 10.0)
|
|
56
|
+
vk_music!
|
|
57
|
+
yard (~> 0.9)
|
|
58
|
+
|
|
59
|
+
BUNDLED WITH
|
|
60
|
+
2.0.2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Fizvlad
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,75 +1,81 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
*vk_music* gem is a library to work with audios on popular Russian social network [vk.com](https://www.vk.com "vk.com"). VK disabled their public API for audios, so it is now necessary to use parsers instead.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
You can
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
1
|
+
# VkMusic
|
|
2
|
+
|
|
3
|
+
*vk_music* gem is a library to work with audios on popular Russian social network [vk.com](https://www.vk.com "vk.com"). VK disabled their public API for audios, so it is now necessary to use parsers instead.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'vk_music'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install vk_music
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
You can take a look on documentation [here](https://www.rubydoc.info/gems/vk_music/).
|
|
24
|
+
|
|
25
|
+
### Logging in
|
|
26
|
+
Firstly, it is required to create new *VkMusic::Client* and provide login credentials:
|
|
27
|
+
```ruby
|
|
28
|
+
client = VkMusic::Client.new(username: "+71234567890", password: "password")
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Searching for audios
|
|
32
|
+
You can search audios by name with following method:
|
|
33
|
+
```ruby
|
|
34
|
+
audios = client.find("Acid Spit - Mega Drive")
|
|
35
|
+
puts audios[0] # Basic information about audio
|
|
36
|
+
puts audios[0].url # URL to access audio. Notice that it is only accessible from your IP
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Parsing playlists
|
|
40
|
+
You can load all the audios from playlist using following method:
|
|
41
|
+
```ruby
|
|
42
|
+
playlist = client.playlist("https://vk.com/audio?z=audio_playlist-37661843_1/0e420c32c8b69e6637")
|
|
43
|
+
```
|
|
44
|
+
It is only possible to load up to 100 audios from playlist per request, so you can reduce amount of requests by setting up how many audios from playlist you actually need.
|
|
45
|
+
For example, following method will perform only one HTML request:
|
|
46
|
+
```ruby
|
|
47
|
+
playlist = client.playlist("https://vk.com/audio?z=audio_playlist121570739_7", up_to: 100)
|
|
48
|
+
urls = playlist.map(&:url) # URLs for every audio
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### User or group audios
|
|
52
|
+
You can load first 100 audios from user or group page. Those audios will be returned as playlist. To do it simply pass user or group id:
|
|
53
|
+
```ruby
|
|
54
|
+
user_playlist = client.audios(owner_id: 8024985)
|
|
55
|
+
group_playlist = client.audios(owner_id: -4790861) # Group and public id starts with '-'
|
|
56
|
+
```
|
|
57
|
+
You can set how many audios you actually need as well:
|
|
58
|
+
```ruby
|
|
59
|
+
user_playlist = client.audios(owner_id: 8024985, up_to: 10)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Audios from post
|
|
63
|
+
You can load up to 10 audios attached to some post. Those audios will be returned as array:
|
|
64
|
+
```ruby
|
|
65
|
+
audios = client.post("https://vk.com/wall-4790861_5453")
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
72
|
+
|
|
73
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
74
|
+
|
|
75
|
+
## Contributing
|
|
76
|
+
|
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fizvlad/vk-music-rb/issues.
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
|
@@ -1,41 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
username = STDIN.gets.chomp
|
|
27
|
-
|
|
28
|
-
print "Password: "
|
|
29
|
-
password = STDIN.gets.chomp
|
|
30
|
-
puts
|
|
31
|
-
|
|
32
|
-
print "Path to SSL certificate (leave empty if there is no troubles with SSL): "
|
|
33
|
-
ssl_cert_path = STDIN.gets.chomp
|
|
34
|
-
puts
|
|
35
|
-
ENV["SSL_CERT_FILE"] = ssl_cert_path unless ssl_cert_path.empty?
|
|
36
|
-
|
|
37
|
-
Dir[ "test/test*.rb" ].each do |file|
|
|
38
|
-
puts "\n\nRunning #{file}:"
|
|
39
|
-
ruby "-w #{file} '#{username}' '#{password}'"
|
|
40
|
-
end
|
|
41
|
-
end
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require "rake/testtask"
|
|
3
|
+
|
|
4
|
+
task :test do
|
|
5
|
+
puts "Running tests require login credetionals (NOTICE: they won't be hidden in anyway)"
|
|
6
|
+
|
|
7
|
+
print "Login: "
|
|
8
|
+
username = STDIN.gets.chomp
|
|
9
|
+
|
|
10
|
+
print "Password: "
|
|
11
|
+
password = STDIN.gets.chomp
|
|
12
|
+
puts
|
|
13
|
+
|
|
14
|
+
print "Path to SSL certificate (leave empty if there is no troubles with SSL): "
|
|
15
|
+
ssl_cert_path = STDIN.gets.chomp
|
|
16
|
+
puts
|
|
17
|
+
ENV["SSL_CERT_FILE"] = ssl_cert_path unless ssl_cert_path.empty?
|
|
18
|
+
|
|
19
|
+
Dir[ "test/test_*.rb" ].each do |file|
|
|
20
|
+
puts "\n\nRunning #{file}:"
|
|
21
|
+
ruby "-w #{file} '#{username}' '#{password}'"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
task :default => :test
|
data/bin/console
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require "
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "vk_music"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
5
8
|
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
6
14
|
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/vk_music.rb
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
require "cgi"
|
|
2
|
+
require "logger"
|
|
3
|
+
require "mechanize"
|
|
4
|
+
require "execjs"
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
require "vk_music/version"
|
|
8
|
+
require "vk_music/constants"
|
|
9
|
+
require "vk_music/exceptions"
|
|
10
|
+
require "vk_music/utility"
|
|
11
|
+
require "vk_music/link_decoder"
|
|
12
|
+
require "vk_music/audio"
|
|
13
|
+
require "vk_music/playlist"
|
|
14
|
+
require "vk_music/client"
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# Main module.
|
|
18
|
+
module VkMusic; end
|
data/lib/vk_music/audio.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require "cgi"
|
|
2
|
-
|
|
3
1
|
##
|
|
4
2
|
# @!macro [new] options_hash_param
|
|
5
3
|
# @param options [Hash] hash with options.
|
|
@@ -59,6 +57,13 @@ module VkMusic
|
|
|
59
57
|
# @return [Integer, nil] user ID which should be use for decoding.
|
|
60
58
|
attr_reader :client_id
|
|
61
59
|
|
|
60
|
+
##
|
|
61
|
+
# @return [String, nil] full ID of audio or +nil+ if some of components are missing.
|
|
62
|
+
def full_id
|
|
63
|
+
return nil unless @owner_id && @id && @secret_1 && @secret_2
|
|
64
|
+
"#{@owner_id}_#{@id}_#{@secret_1}_#{@secret_2}"
|
|
65
|
+
end
|
|
66
|
+
|
|
62
67
|
##
|
|
63
68
|
# @return [Boolean] whether decoded URL is already cached.
|
|
64
69
|
def url_cached?
|
|
@@ -86,7 +91,15 @@ module VkMusic
|
|
|
86
91
|
##
|
|
87
92
|
# @return [String] extended information about audio.
|
|
88
93
|
def pp
|
|
89
|
-
"#{to_s} (
|
|
94
|
+
"#{to_s} (#{
|
|
95
|
+
if url_available?
|
|
96
|
+
"Able to get decoded URL right away"
|
|
97
|
+
elsif url_accessable?
|
|
98
|
+
"Able to retrieve URL with request"
|
|
99
|
+
else
|
|
100
|
+
"URL not accessable"
|
|
101
|
+
end
|
|
102
|
+
})"
|
|
90
103
|
end
|
|
91
104
|
|
|
92
105
|
##
|
|
@@ -146,8 +159,8 @@ module VkMusic
|
|
|
146
159
|
@owner_id = Utility.unless_nil_to Integer, options[:owner_id]
|
|
147
160
|
@secret_1 = Utility.unless_nil_to String, options[:secret_1]
|
|
148
161
|
@secret_2 = Utility.unless_nil_to String, options[:secret_2]
|
|
149
|
-
@artist = options[:artist].to_s
|
|
150
|
-
@title = options[:title].to_s
|
|
162
|
+
@artist = options[:artist].to_s.strip
|
|
163
|
+
@title = options[:title].to_s.strip
|
|
151
164
|
@duration = options[:duration].to_i
|
|
152
165
|
@url_encoded = Utility.unless_nil_to String, options[:url_encoded]
|
|
153
166
|
@url = Utility.unless_nil_to String, options[:url]
|
|
@@ -162,20 +175,30 @@ module VkMusic
|
|
|
162
175
|
#
|
|
163
176
|
# @return [Audio]
|
|
164
177
|
def self.from_node(node, client_id)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
input = node.at_css("input")
|
|
179
|
+
if input
|
|
180
|
+
url_encoded = input.attribute("value").to_s
|
|
181
|
+
url_encoded = nil if url_encoded == Constants::URL::VK[:audio_unavailable] || url_encoded.empty?
|
|
182
|
+
id_array = node.attribute("data-id").to_s.split("_")
|
|
183
|
+
|
|
184
|
+
new({
|
|
185
|
+
:id => id_array[1].to_i,
|
|
186
|
+
:owner_id => id_array[0].to_i,
|
|
187
|
+
:artist => node.at_css(".ai_artist").text.strip,
|
|
188
|
+
:title => node.at_css(".ai_title").text.strip,
|
|
189
|
+
:duration => node.at_css(".ai_dur").attribute("data-dur").to_s.to_i,
|
|
190
|
+
:url_encoded => url_encoded,
|
|
191
|
+
:url => nil,
|
|
192
|
+
:client_id => client_id
|
|
193
|
+
})
|
|
194
|
+
else
|
|
195
|
+
# Probably audios from some post
|
|
196
|
+
new({
|
|
197
|
+
:artist => node.at_css(".medias_audio_artist").text.strip,
|
|
198
|
+
:title => Utility.plain_text(node.at_css(".medias_audio_title")).strip,
|
|
199
|
+
:duration => Utility.parse_duration(node.at_css(".medias_audio_dur").text)
|
|
200
|
+
})
|
|
201
|
+
end
|
|
179
202
|
end
|
|
180
203
|
|
|
181
204
|
##
|