Module: VkMusic::Utility::PlaylistLoader

Defined in:
lib/vk_music/utility/playlist_loader.rb

Overview

Load playlist audios

Class Method Summary collapse

Class Method Details

.call(agent, client_id, owner_id, playlist_id, access_hash, up_to) ⇒ Playlist?

Parameters:

  • agent (Mechanize)
  • client_id (Integer)
  • owner_id (Integer)
  • playlist_id (Integer)
  • access_hash (String, nil)
  • up_to (Integer)

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vk_music/utility/playlist_loader.rb', line 14

def self.call(agent, client_id, owner_id, playlist_id, access_hash, up_to)
  page = Request::Playlist.new(owner_id, playlist_id, access_hash, client_id)
  page.call(agent)
  audios = page.audios
  return if audios.nil? || audios.empty?

  up_to = page.real_size if up_to > page.real_size

  rest = PlaylistSectionLoader.call(agent, client_id, owner_id, playlist_id, access_hash,
                                    audios.size, up_to - audios.size)
  audios.concat(rest)
  Playlist.new(audios, id: playlist_id, owner_id: owner_id, access_hash: access_hash,
                       title: page.title, subtitle: page.subtitle, real_size: page.real_size)
end