vk_music 2.1.5 → 2.2.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: 8c686eab537cc09b5b535b48ab5ec5bec07f7de32b40ef24da79581dfc4a9db1
4
- data.tar.gz: 5bfa7741c641c5cc7207df7e4b9a6733287c255e6d83437bcd34077a34c241ac
3
+ metadata.gz: 6a40ac2ba500bdf24f6ccb6e645216bd4716458d5c795c8a65acc82887dd37a0
4
+ data.tar.gz: 0ad38527b6a893916a904d3eca60f55aac5d534255cdcff1a0ff0f60ba0794e7
5
5
  SHA512:
6
- metadata.gz: c6bb22c0d5e613e04021f525e40addbe27d3f81892a3dc9799be64b6b08efd59ca5241eb2824ff88ba620ddf1fca9ee555b8e748eba73a47f73cac1cee750b00
7
- data.tar.gz: 27250ddbe84cd15da149bbc259acc54c4d20a441dca6b1286cded0d08d4623de27da1f13a60a2d3b7d2cb045bfcd019a5e8abd6cda950e970a211bf69d17ee05
6
+ metadata.gz: 408afa4efb6f4ca2b4deb6f7670775bd8569cebab42d6d825f7cd4f60a3503ebc53b415b5046ad69254ca4d4ffb526858428a23f4fde4ba2cdb81eee05c245db
7
+ data.tar.gz: 64ee9349066a69fbef74d3b84cf03bea651bc30504eef7a009e243e5889bcf28be7281bbbfb8b20b491c2d748c2961531461c98a8c7966d0b0e3e8957b1eea97
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.5
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in vk_music.gemspec
4
+ gemspec
5
+
6
+ gem "logger", "~> 1.4"
7
+
8
+ gem "mechanize", "~> 2.7"
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
- # vk_music
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
- ## Dependencies
7
-
8
- * [mechanize](https://github.com/sparklemotion/mechanize "mechanize") (interaction with website)
9
- * [execjs](https://github.com/rails/execjs "execjs") (JS interpreter)
10
-
11
-
12
- ## Installation
13
-
14
- Simpliest way to install gem:
15
- ```
16
- gem install vk_music
17
- ```
18
-
19
- Alternatively, you can build gem from sources with following command:
20
- ```
21
- gem build vk_music.gemspec
22
- ```
23
-
24
- ... and install it:
25
- ```
26
- gem install vk_music-*.gem
27
- ```
28
-
29
-
30
- ## Usage
31
-
32
- You can take a look on documentation [here](https://www.rubydoc.info/gems/vk_music/).
33
-
34
- ### Logging in
35
- Firstly, it is required to create new *VkMusic::Client* and provide login credentials:
36
- ```ruby
37
- client = VkMusic::Client.new(username: "+71234567890", password: "password")
38
- ```
39
-
40
- ### Searching for audios
41
- You can search audios by name with following method:
42
- ```ruby
43
- audios = client.find("Acid Spit - Mega Drive")
44
- puts audios[0] # Basic information about audio
45
- puts audios[0].url # URL to access audio. Notice that it is only accessible from your IP
46
- ```
47
-
48
- ### Parsing playlists
49
- You can load all the audios from playlist using following method:
50
- ```ruby
51
- playlist = client.playlist("https://vk.com/audio?z=audio_playlist-37661843_1/0e420c32c8b69e6637")
52
- ```
53
- 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.
54
- For example, following method will perform only one HTML request:
55
- ```ruby
56
- playlist = client.playlist("https://vk.com/audio?z=audio_playlist121570739_7", up_to: 100)
57
- urls = playlist.map(&:url) # URLs for every audio
58
- ```
59
-
60
- ### User or group audios
61
- 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:
62
- ```ruby
63
- user_playlist = client.audios(owner_id: 8024985)
64
- group_playlist = client.audios(owner_id: -4790861) # Group and public id starts with '-'
65
- ```
66
- You can set how many audios you actually need as well:
67
- ```ruby
68
- user_playlist = client.audios(owner_id: 8024985, up_to: 10)
69
- ```
70
-
71
- ### Audios from post
72
- You can load up to 10 audios attached to some post. Those audios will be returned as array:
73
- ```ruby
74
- audios = client.post("https://vk.com/wall-4790861_5453")
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
- desc "Create documentation"
2
- task :doc do
3
- puts `yardoc`
4
- end
5
-
6
- desc "Build gem file"
7
- task :build do
8
- puts `gem build vk_music.gemspec`
9
- end
10
-
11
- desc "Uninstall gem"
12
- task :uninstall do
13
- puts `gem uninstall vk_music`
14
- end
15
-
16
- desc "Build and install gem"
17
- task :install_local => :build do
18
- puts `gem install ./vk_music-*.gem`
19
- end
20
-
21
- desc "Run tests"
22
- task :test do
23
- puts "Running tests require login credetionals (NOTICE: they won't be hidden in anyway)"
24
-
25
- print "Login: "
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
- require_relative "../lib/vk_music.rb"
4
- require "irb"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/vk_music.rb CHANGED
@@ -1,7 +1,18 @@
1
- require_relative "vk_music/constants.rb"
2
- require_relative "vk_music/exceptions.rb"
3
- require_relative "vk_music/utility.rb"
4
- require_relative "vk_music/link_decoder.rb"
5
- require_relative "vk_music/audio.rb"
6
- require_relative "vk_music/playlist.rb"
7
- require_relative "vk_music/client.rb"
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,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} (Able to get decoded URL: #{url_available? ? "yes" : "no"}, able to get URL from VK: #{url_accessable? ? "yes" : "no"})"
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
- url_encoded = node.at_css("input").attribute("value").to_s
166
- url_encoded = nil if url_encoded == Constants::URL::VK[:audio_unavailable] || url_encoded.empty?
167
- id_array = node.attribute("data-id").to_s.split("_")
168
-
169
- new({
170
- :id => id_array[1].to_i,
171
- :owner_id => id_array[0].to_i,
172
- :artist => node.at_css(".ai_artist").text.strip,
173
- :title => node.at_css(".ai_title").text.strip,
174
- :duration => node.at_css(".ai_dur").attribute("data-dur").to_s.to_i,
175
- :url_encoded => url_encoded,
176
- :url => nil,
177
- :client_id => client_id
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
  ##