vk_music gem is a library to work with audios on popular Russian social network
Add this line to your application's Gemfile:
gem 'vk_music'
And then execute:
$ bundle
Or install it using gem
:
$ gem install vk_music
You can take a look on documentation at rubydoc.
Firstly, it is required to create new VkMusic::Client
instance and provide login credentials:
client = VkMusic::Client.new(username: "+79991234567", password: "password")
You can search audios using Client#find
:
audios = client.find("Acid Spit - Mega Drive")
You can also search for playlists using same method:
playlists = client.find("Jazz", type: :playlist)
You can load playlist audios with Client#playlist
playlist = client.playlist(url: "link")
You can load profile audios with Client#audios
playlist = client.audios(owner_id: 8024985)
You can load audios from profile wall with Client#wall
playlist = client.wall(owner_id: 8024985)
You can load up to 10 audios attached to some post. Those audios will be returned as array:
audios = client.post(url: "link")
You can get up to 50 top audios of particular artist:
audios = client.artist(url: "link")
To get audio URL you should go through following chain:
- Get audio ID
- Get audio encrypted URL
- Get audio decrypted URL
Usually most of audios already go with ID. Getting encrypted URL requires additional request to web, so it is performed with Client#update_urls
, which will mutate provided array of audios:
client.update_urls(audios_array)
After this you can get decrypted URL using Audio#url
Feel free to add features. However, please make sure all your code is covered with tests.
This gem uses rspec
and vcr
for easy testing. Be careful, though, running rspec
in clean repo may result in lot of requests to web and rate limiting or ban
Bug reports and pull requests are welcome on GitHub at https://github.com/fizvlad/vk-music-rb/issues.
The gem is available as open source under the terms of the MIT License.