class Caldera::Model::Track

Attributes

author[R]

@param [String] The track author.

identifier[R]

@param [String] The track identifier

length[R]

@param [Integer] Length in milliseconds.

position[R]

@param [Integer] The current position in milliseconds.

seekable[R]

@param [true, false]

stream[R]

@param [true, false]

title[R]

@param [String] The track title.

track_data[R]

@param [String] Base64 representation of the track

uri[R]

@param [String] The URI to the track source.

Public Class Methods

from_b64(b64_data) click to toggle source

Decode a track from base64 track data. @param [String] b64_data Base64 encoded track data, recieved from the Lavalink server.

# File lib/caldera/model/track.rb, line 55
def self.from_b64(b64_data)
  data = Base64.decode64(b64_data)
  flags, version = data.unpack('NC')

  raise 'Unsupported track data' if (flags >> 30) != 1

  # This is gross but it's easier than not doing it
  case version
  when 1
    title, author, length, identifier, is_stream, source = data.unpack('@7Z*xZ*Q>xZ*CxZ*')
    Track.new(
      'track' => b64_data,
      'info' => {
        'title' => title,
        'author' => author,
        'length' => length,
        'identifier' => identifier,
        'isStream' => is_stream == 1,
        'source' => source
      }
    )
  when 2
    title, author, length, identifier, is_stream, uri, source = data.unpack('@7Z*xZ*Q>xZ*CxxZ*xZ*xZ*')
    Track.new(
      'track' => b64_data,
      'info' => {
        'title' => title,
        'author' => author,
        'length' => length,
        'identifier' => identifier,
        'isStream' => is_stream == 1,
        'source' => source,
        'uri' => uri
      }
    )
  else
    raise 'Unsupported track version'
  end
end
new(data) click to toggle source
# File lib/caldera/model/track.rb, line 35
def initialize(data)
  # track_data could maybe use a better name. It's
  # a base64 representation of a binary data representation
  # of a track=
  @track_data = data['track']

  info = data['info']
  @identifier = info['identifier']
  @seekable = info['isSeekable']
  @author = info['author']
  @length = info['length']
  @stream = info['isStream']
  @position = info['position']
  @title = info['title']
  @uri = info['uri']
  @source = info['source']
end