vk_music 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79ce8368cee1e94e3f1351753ba42167f2310148d22c96d274fa0056cda2e06d
4
- data.tar.gz: ff35c242aaf9eecdc529eb478346a6e7883d1eb437d7f4fe163d36ebc893092a
3
+ metadata.gz: 3e95f75b40e89ac4f7d51056b3412f343e171a92431ebab522a998120df7f2d8
4
+ data.tar.gz: 03613c0cd92fd68728c25f04442c8d8f7c24276b52c7e2af4c4c448a319c9c10
5
5
  SHA512:
6
- metadata.gz: c08525601176055fb0c94f666f28a654cea22f196db413d4e9bd0a425e716bcc1752e1f4f9e6de87772d105db41629aa5bb149de5b8cfaa42f020f57038a4d4a
7
- data.tar.gz: 7ccd31000b153925a63b69c6d796bfa9d58adf2c8b2fc1ed86c99024f913590bfcba32bb29b27c89c61cb630d6a540f55a4417051d8145601c2d7a5e732e4d9c
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 (2.2.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
- 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
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
- ```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).
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
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
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
- 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
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
@@ -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
- # Access decoded download URL.
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 URLs.
107
- #
108
- # @overload update_url(decoded_url)
109
- # Simply save download URL.
110
- # @param decoded_url [String]
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 update_url(arg)
124
- case arg
125
- when String
126
- @url = arg
127
- when Audio
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
- # @macro options_hash_param
146
- #
147
- # @option options [Integer, nil] :id
148
- # @option options [Integer, nil] :owner_id
149
- # @option options [String, nil] :secret_1
150
- # @option options [String, nil] :secret_2
151
- # @option options [String] :artist
152
- # @option options [String] :title
153
- # @option options [Integer] :duration
154
- # @option options [String, nil] :url_encoded
155
- # @option options [String, nil] :url
156
- # @option options [Integer, nil] :client_id
157
- def initialize(options = {})
158
- @id = Utility.unless_nil_to Integer, options[:id]
159
- @owner_id = Utility.unless_nil_to Integer, options[:owner_id]
160
- @secret_1 = Utility.unless_nil_to String, options[:secret_1]
161
- @secret_2 = Utility.unless_nil_to String, options[:secret_2]
162
- @artist = options[:artist].to_s.strip
163
- @title = options[:title].to_s.strip
164
- @duration = options[:duration].to_i
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
- :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
- })
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
- :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
- })
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
- :id => data[0].to_i,
219
- :owner_id => data[1].to_i,
220
- :secret_1 => secrets[3],
221
- :secret_2 => secrets[5],
222
- :artist => CGI.unescapeHTML(data[4]),
223
- :title => CGI.unescapeHTML(data[3]),
224
- :duration => data[5].to_i,
225
- :url_encoded => url_encoded,
226
- :url => nil,
227
- :client_id => client_id
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