vk_music 2.2.1 → 3.0.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/Gemfile +6 -4
- data/Gemfile.lock +66 -60
- data/README.md +87 -81
- data/bin/console +10 -14
- data/lib/vk_music.rb +18 -18
- data/lib/vk_music/audio.rb +68 -115
- data/lib/vk_music/client.rb +357 -497
- data/lib/vk_music/constants.rb +3 -20
- data/lib/vk_music/exceptions.rb +1 -12
- data/lib/vk_music/link_decoder.rb +2 -8
- data/lib/vk_music/playlist.rb +30 -41
- data/lib/vk_music/utility.rb +5 -63
- data/lib/vk_music/utility/log.rb +51 -0
- data/lib/vk_music/version.rb +5 -7
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e95f75b40e89ac4f7d51056b3412f343e171a92431ebab522a998120df7f2d8
|
|
4
|
+
data.tar.gz: 03613c0cd92fd68728c25f04442c8d8f7c24276b52c7e2af4c4c448a319c9c10
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c32a1cabae2d9307e074132ccc69edf174df097d5fbf4c9a2fc596f33ca58f1cbbf49dab2c9ddbf21200e9f76326ab7926c1c68fc8b0dc81837c9faf1e9273f4
|
|
7
|
+
data.tar.gz: b836b42444769bde9ea746aafa62300800d0d4c5e673b8c6ce6c4ff060ce20d152a8fd6b18189d1c63dce3d0203def9aab42d20fc2c4db181489906f8dcced01
|
data/Gemfile
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
source "https://rubygems.org"
|
|
2
|
-
|
|
3
|
-
# Specify your gem's dependencies in vk_music.gemspec
|
|
4
|
-
gemspec
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
# Specify your gem's dependencies in vk_music.gemspec
|
|
4
|
+
gemspec
|
|
5
5
|
|
|
6
6
|
gem "logger", "~> 1.4"
|
|
7
7
|
|
|
8
8
|
gem "mechanize", "~> 2.7"
|
|
9
|
+
|
|
10
|
+
gem "pry", "~> 0.12.2"
|
data/Gemfile.lock
CHANGED
|
@@ -1,60 +1,66 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
vk_music (
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
net-http-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
mime-types
|
|
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
|
-
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
vk_music (3.0.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.2.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.7-x64-mingw32)
|
|
40
|
+
mini_portile2 (~> 2.4.0)
|
|
41
|
+
ntlm-http (0.1.1)
|
|
42
|
+
pry (0.12.2)
|
|
43
|
+
coderay (~> 1.1.0)
|
|
44
|
+
method_source (~> 0.9.0)
|
|
45
|
+
rake (10.5.0)
|
|
46
|
+
unf (0.1.4)
|
|
47
|
+
unf_ext
|
|
48
|
+
unf_ext (0.0.7.6)
|
|
49
|
+
webrobots (0.1.2)
|
|
50
|
+
yard (0.9.20)
|
|
51
|
+
|
|
52
|
+
PLATFORMS
|
|
53
|
+
x64-mingw32
|
|
54
|
+
|
|
55
|
+
DEPENDENCIES
|
|
56
|
+
bundler (~> 2.0)
|
|
57
|
+
logger (~> 1.4)
|
|
58
|
+
mechanize (~> 2.7)
|
|
59
|
+
minitest (~> 5.0)
|
|
60
|
+
pry (~> 0.12.2)
|
|
61
|
+
rake (~> 10.0)
|
|
62
|
+
vk_music!
|
|
63
|
+
yard (~> 0.9)
|
|
64
|
+
|
|
65
|
+
BUNDLED WITH
|
|
66
|
+
2.0.2
|
data/README.md
CHANGED
|
@@ -1,81 +1,87 @@
|
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
playlist
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
urls =
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### User or group audios
|
|
52
|
-
You can load
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
##
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
client = VkMusic::Client.new(username: "+71234567890", password: "password")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Searching for audios
|
|
33
|
+
You can search audios by name with following method:
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
audios = client.find("Acid Spit - Mega Drive")
|
|
37
|
+
puts audios[0] # Basic information about audio
|
|
38
|
+
puts audios[0].url # URL to access audio. Notice that it is only accessible from your IP
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Parsing playlists
|
|
42
|
+
You can load all the audios from playlist using following method:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
playlist = client.playlist(url: "https://vk.com/audio?z=audio_playlist-37661843_1/0e420c32c8b69e6637")
|
|
46
|
+
last_audios = playlist.first(10) # => Array<Audio>
|
|
47
|
+
client.update_urls(last_audios) # We have to manually retrieve URLs for playlists
|
|
48
|
+
urls = last_audios.map(&:url) # URLs for every audio
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### User or group audios
|
|
52
|
+
You can load audios from user or group page. Those audios will be returned as playlist. To do it simply pass user or group id:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
playlist = client.audios(owner_id: 8024985)
|
|
56
|
+
last_audios = playlist.first(10) # => Array<Audio>
|
|
57
|
+
client.update_urls(last_audios) # We have to manually retrieve URLs for playlists
|
|
58
|
+
urls = last_audios.map(&:url) # URLs for every audio
|
|
59
|
+
```
|
|
60
|
+
You can set how many audios you actually need as well:
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
user_playlist = client.audios(url: "vk.com/id8024985", up_to: 10)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Audios from post
|
|
67
|
+
You can load up to 10 audios attached to some post. Those audios will be returned as array:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
audios = client.post(url: "https://vk.com/wall-4790861_5453")
|
|
71
|
+
urls = audios.map(&:url) # URLs for every audio
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
## Development
|
|
76
|
+
|
|
77
|
+
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.
|
|
78
|
+
|
|
79
|
+
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).
|
|
80
|
+
|
|
81
|
+
## Contributing
|
|
82
|
+
|
|
83
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fizvlad/vk-music-rb/issues.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/bin/console
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
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.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
# Pry.start
|
|
12
|
-
|
|
13
|
-
require "irb"
|
|
14
|
-
IRB.start(__FILE__)
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
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.
|
|
8
|
+
|
|
9
|
+
require "pry"
|
|
10
|
+
Pry.start
|
data/lib/vk_music.rb
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
require "cgi"
|
|
2
|
-
require "logger"
|
|
3
|
-
require "mechanize"
|
|
4
|
-
require "execjs"
|
|
5
|
-
require "json"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
##
|
|
17
|
-
# Main module.
|
|
18
|
-
module VkMusic; end
|
|
1
|
+
require "cgi"
|
|
2
|
+
require "logger"
|
|
3
|
+
require "mechanize"
|
|
4
|
+
require "execjs"
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
require_relative "vk_music/version"
|
|
8
|
+
require_relative "vk_music/constants"
|
|
9
|
+
require_relative "vk_music/exceptions"
|
|
10
|
+
require_relative "vk_music/utility"
|
|
11
|
+
require_relative "vk_music/link_decoder"
|
|
12
|
+
require_relative "vk_music/audio"
|
|
13
|
+
require_relative "vk_music/playlist"
|
|
14
|
+
require_relative "vk_music/client"
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# Main module.
|
|
18
|
+
module VkMusic; end
|
data/lib/vk_music/audio.rb
CHANGED
|
@@ -1,43 +1,30 @@
|
|
|
1
|
-
##
|
|
2
|
-
# @!macro [new] options_hash_param
|
|
3
|
-
# @param options [Hash] hash with options.
|
|
4
|
-
|
|
5
1
|
module VkMusic
|
|
6
|
-
|
|
7
2
|
##
|
|
8
3
|
# Class representing VK audio.
|
|
9
4
|
class Audio
|
|
10
|
-
|
|
11
5
|
##
|
|
12
6
|
# @return [Integer, nil] ID of audio.
|
|
13
7
|
attr_reader :id
|
|
14
|
-
|
|
15
8
|
##
|
|
16
9
|
# @return [Integer, nil] ID of audio owner.
|
|
17
10
|
attr_reader :owner_id
|
|
18
|
-
|
|
19
11
|
##
|
|
20
12
|
# @return [String, nil] part of secret hash which used when using +act=reload_audio+.
|
|
21
13
|
attr_reader :secret_1, :secret_2
|
|
22
|
-
|
|
23
14
|
##
|
|
24
15
|
# @return [String] name of artist.
|
|
25
16
|
attr_reader :artist
|
|
26
|
-
|
|
27
17
|
##
|
|
28
18
|
# @return [String] title of song.
|
|
29
19
|
attr_reader :title
|
|
30
|
-
|
|
31
20
|
##
|
|
32
21
|
# @return [Integer] duration of track in seconds.
|
|
33
22
|
attr_reader :duration
|
|
34
|
-
|
|
35
23
|
##
|
|
36
|
-
#
|
|
24
|
+
# Read decoded download URL.
|
|
37
25
|
#
|
|
38
26
|
# If link was already decoded, returns cached value. Else decodes existing link.
|
|
39
27
|
# If no link can be provided, returns +nil+.
|
|
40
|
-
#
|
|
41
28
|
# @return [String, nil] decoded download URL or +nil+ if not available.
|
|
42
29
|
def url
|
|
43
30
|
if url_cached?
|
|
@@ -45,18 +32,15 @@ module VkMusic
|
|
|
45
32
|
elsif @url_encoded && @client_id
|
|
46
33
|
@url = VkMusic::LinkDecoder.unmask_link(@url_encoded, @client_id)
|
|
47
34
|
else
|
|
48
|
-
@url # nil
|
|
35
|
+
@url # => nil
|
|
49
36
|
end
|
|
50
37
|
end
|
|
51
|
-
|
|
52
38
|
##
|
|
53
39
|
# @return [String, nil] encoded download URL.
|
|
54
40
|
attr_reader :url_encoded
|
|
55
|
-
|
|
56
41
|
##
|
|
57
42
|
# @return [Integer, nil] user ID which should be use for decoding.
|
|
58
43
|
attr_reader :client_id
|
|
59
|
-
|
|
60
44
|
##
|
|
61
45
|
# @return [String, nil] full ID of audio or +nil+ if some of components are missing.
|
|
62
46
|
def full_id
|
|
@@ -69,25 +53,22 @@ module VkMusic
|
|
|
69
53
|
def url_cached?
|
|
70
54
|
!!(@url)
|
|
71
55
|
end
|
|
72
|
-
|
|
73
56
|
##
|
|
74
57
|
# @return [Boolean] whether able to get download URL without web requests.
|
|
75
58
|
def url_available?
|
|
76
59
|
!!(url_cached? || (@url_encoded && @client_id))
|
|
77
60
|
end
|
|
78
|
-
|
|
79
61
|
##
|
|
80
62
|
# @return [Boolean] whether it's possible to get download URL with {Client#from_id}.
|
|
81
63
|
def url_accessable?
|
|
82
64
|
!!(@id && @owner_id && @secret_1 && @secret_2)
|
|
83
65
|
end
|
|
84
|
-
|
|
66
|
+
|
|
85
67
|
##
|
|
86
68
|
# @return [String] information about audio.
|
|
87
69
|
def to_s
|
|
88
70
|
"#{@artist} - #{@title} [#{Utility.format_seconds(@duration)}]"
|
|
89
71
|
end
|
|
90
|
-
|
|
91
72
|
##
|
|
92
73
|
# @return [String] extended information about audio.
|
|
93
74
|
def pp
|
|
@@ -103,76 +84,53 @@ module VkMusic
|
|
|
103
84
|
end
|
|
104
85
|
|
|
105
86
|
##
|
|
106
|
-
# Update audio
|
|
107
|
-
#
|
|
108
|
-
# @
|
|
109
|
-
#
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
# @overload update_url(audio)
|
|
113
|
-
# Copy URLs from this audio (no checks applied).
|
|
114
|
-
# @param audio [Audio]
|
|
115
|
-
#
|
|
116
|
-
# @overload update_url(options)
|
|
117
|
-
# @macro options_hash_param
|
|
118
|
-
# @option options [String, nil] :url decoded download URL.
|
|
119
|
-
# @option options [String, nil] :url_encoded decoded download URL.
|
|
120
|
-
# @option options [String, nil] :client_id decoded download URL.
|
|
121
|
-
#
|
|
87
|
+
# Update audio from another audio or from provided hash.
|
|
88
|
+
# @param from [Audio, nil]
|
|
89
|
+
# @param url [String, nil]
|
|
90
|
+
# @param url_encoded [String, nil]
|
|
91
|
+
# @param client_id [String, nil]
|
|
122
92
|
# @return [self]
|
|
123
|
-
def
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
# Only save URL if it's already decoded and cached
|
|
129
|
-
@url = arg.url if arg.url_cached?
|
|
130
|
-
@url_encoded = arg.url_encoded
|
|
131
|
-
@client_id = arg.client_id
|
|
132
|
-
when Hash
|
|
133
|
-
@url_encoded = Utility.unless_nil_to String, options[:url_encoded]
|
|
134
|
-
@url = Utility.unless_nil_to String, options[:url]
|
|
135
|
-
@client_id = Utility.unless_nil_to Integer, options[:client_id]
|
|
136
|
-
else
|
|
137
|
-
raise ArgumentError, "Bad arguments", caller
|
|
93
|
+
def update(from: nil, url: nil, url_encoded: nil, client_id: nil)
|
|
94
|
+
if from
|
|
95
|
+
url_encoded = from.url_encoded
|
|
96
|
+
url = from.url_cached? ? from.url : nil
|
|
97
|
+
client_id = from.client_id
|
|
138
98
|
end
|
|
99
|
+
|
|
100
|
+
@url_encoded = url_encoded unless url_encoded.nil?
|
|
101
|
+
@url = url unless url.nil?
|
|
102
|
+
@client_id = client_id unless client_id.nil?
|
|
139
103
|
self
|
|
140
104
|
end
|
|
141
|
-
|
|
105
|
+
|
|
142
106
|
##
|
|
143
107
|
# Initialize new audio.
|
|
144
|
-
#
|
|
145
|
-
# @
|
|
146
|
-
#
|
|
147
|
-
# @
|
|
148
|
-
# @
|
|
149
|
-
# @
|
|
150
|
-
# @
|
|
151
|
-
# @
|
|
152
|
-
# @
|
|
153
|
-
# @
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
@
|
|
159
|
-
@
|
|
160
|
-
@
|
|
161
|
-
@
|
|
162
|
-
@
|
|
163
|
-
@
|
|
164
|
-
@
|
|
165
|
-
@url_encoded = Utility.unless_nil_to String, options[:url_encoded]
|
|
166
|
-
@url = Utility.unless_nil_to String, options[:url]
|
|
167
|
-
@client_id = Utility.unless_nil_to Integer, options[:client_id]
|
|
108
|
+
# @param id [Integer, nil]
|
|
109
|
+
# @param owner_id [Integer, nil]
|
|
110
|
+
# @param secret_1 [String, nil]
|
|
111
|
+
# @param secret_2 [String, nil]
|
|
112
|
+
# @param artist [String]
|
|
113
|
+
# @param title [String]
|
|
114
|
+
# @param duration [Integer]
|
|
115
|
+
# @param url_encoded [String, nil]
|
|
116
|
+
# @param url [String, nil]
|
|
117
|
+
# @param client_id [Integer, nil]
|
|
118
|
+
def initialize(id: nil, owner_id: nil, secret_1: nil, secret_2: nil, artist: "", title: "", duration: 0, url_encoded: nil, url: nil, client_id: nil)
|
|
119
|
+
@id = id
|
|
120
|
+
@owner_id = owner_id
|
|
121
|
+
@secret_1 = secret_1
|
|
122
|
+
@secret_2 = secret_2
|
|
123
|
+
@artist = artist.strip
|
|
124
|
+
@title = title.strip
|
|
125
|
+
@duration = duration
|
|
126
|
+
@url_encoded = url_encoded
|
|
127
|
+
@url = url
|
|
128
|
+
@client_id = client_id
|
|
168
129
|
end
|
|
169
|
-
|
|
170
130
|
##
|
|
171
131
|
# Initialize new audio from Nokogiri HTML node.
|
|
172
|
-
#
|
|
173
132
|
# @param node [Nokogiri::XML::Node] node, which match following CSS selector: +.audio_item.ai_has_btn+
|
|
174
133
|
# @param client_id [Integer]
|
|
175
|
-
#
|
|
176
134
|
# @return [Audio]
|
|
177
135
|
def self.from_node(node, client_id)
|
|
178
136
|
input = node.at_css("input")
|
|
@@ -180,54 +138,49 @@ module VkMusic
|
|
|
180
138
|
url_encoded = input.attribute("value").to_s
|
|
181
139
|
url_encoded = nil if url_encoded == Constants::URL::VK[:audio_unavailable] || url_encoded.empty?
|
|
182
140
|
id_array = node.attribute("data-id").to_s.split("_")
|
|
183
|
-
|
|
184
|
-
new(
|
|
185
|
-
:
|
|
186
|
-
:
|
|
187
|
-
:
|
|
188
|
-
:
|
|
189
|
-
:
|
|
190
|
-
:
|
|
191
|
-
:
|
|
192
|
-
:
|
|
193
|
-
|
|
141
|
+
|
|
142
|
+
new(
|
|
143
|
+
id: id_array[1].to_i,
|
|
144
|
+
owner_id: id_array[0].to_i,
|
|
145
|
+
artist: node.at_css(".ai_artist").text.strip,
|
|
146
|
+
title: node.at_css(".ai_title").text.strip,
|
|
147
|
+
duration: node.at_css(".ai_dur").attribute("data-dur").to_s.to_i,
|
|
148
|
+
url_encoded: url_encoded,
|
|
149
|
+
url: nil,
|
|
150
|
+
client_id: client_id
|
|
151
|
+
)
|
|
194
152
|
else
|
|
195
153
|
# Probably audios from some post
|
|
196
|
-
new(
|
|
197
|
-
:
|
|
198
|
-
:
|
|
199
|
-
:
|
|
200
|
-
|
|
154
|
+
new(
|
|
155
|
+
artist: node.at_css(".medias_audio_artist").text.strip,
|
|
156
|
+
title: Utility.plain_text(node.at_css(".medias_audio_title")).strip,
|
|
157
|
+
duration: Utility.parse_duration(node.at_css(".medias_audio_dur").text)
|
|
158
|
+
)
|
|
201
159
|
end
|
|
202
160
|
end
|
|
203
|
-
|
|
204
161
|
##
|
|
205
162
|
# Initialize new audio from VK data array.
|
|
206
|
-
#
|
|
207
163
|
# @param data [Array]
|
|
208
164
|
# @param client_id [Integer]
|
|
209
|
-
#
|
|
210
165
|
# @return [Audio]
|
|
211
166
|
def self.from_data(data, client_id)
|
|
212
167
|
url_encoded = data[2].to_s
|
|
213
168
|
url_encoded = nil if url_encoded.empty?
|
|
214
|
-
|
|
169
|
+
|
|
215
170
|
secrets = data[13].to_s.split("/")
|
|
216
171
|
|
|
217
|
-
new(
|
|
218
|
-
:
|
|
219
|
-
:
|
|
220
|
-
:
|
|
221
|
-
:
|
|
222
|
-
:
|
|
223
|
-
:
|
|
224
|
-
:
|
|
225
|
-
:
|
|
226
|
-
:
|
|
227
|
-
:
|
|
228
|
-
|
|
172
|
+
new(
|
|
173
|
+
id: data[0].to_i,
|
|
174
|
+
owner_id: data[1].to_i,
|
|
175
|
+
secret_1: secrets[3],
|
|
176
|
+
secret_2: secrets[5],
|
|
177
|
+
artist: CGI.unescapeHTML(data[4]),
|
|
178
|
+
title: CGI.unescapeHTML(data[3]),
|
|
179
|
+
duration: data[5].to_i,
|
|
180
|
+
url_encoded: url_encoded,
|
|
181
|
+
url: nil,
|
|
182
|
+
client_id: client_id
|
|
183
|
+
)
|
|
229
184
|
end
|
|
230
|
-
|
|
231
185
|
end
|
|
232
|
-
|
|
233
186
|
end
|