class RSpotify::Track

@attr [Album] album The album on which the track appears @attr [Array<Artist>] artists The artists who performed the track @attr [Array<String>] available_markets The markets in which the track can be played. See {en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country codes} @attr [Integer] disc_number The disc number. Usually 1 unless the album consists of more than one disc @attr [Integer] duration_ms The track length in milliseconds @attr [Boolean] explicit Whether or not the track has explicit lyrics. true = yes it does; false = no it does not OR unknown @attr [Hash] external_ids Known external IDs for the track @attr [String] name The name of the track @attr [Integer] popularity The popularity of the track. The value will be between 0 and 100, with 100 being the most popular @attr [String] preview_url A link to a 30 second preview (MP3 format) of the track @attr [Integer] track_number The number of the track. If an album has several discs, the track number is the number on the specified disc @attr [String] played_at The date and time the track was played. Only present when pulled from /recently-played @attr [String] context_type The context the track was played from. Only present when pulled from /recently-played @attr [Boolean] is_playable Whether or not the track is playable in the given market. Only present when track relinking is applied by specifying a market when looking up the track @attr [TrackLink] linked_from Details of the requested track. Only present when track relinking is applied and the returned track is different to the one requested because the latter is not available in the given market

Public Class Methods

find(ids, market: nil) click to toggle source

Returns Track object(s) with id(s) provided

@param ids [String, Array] Maximum: 50 IDs @param market [String] Optional. An {en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country code}. @return [Track, Array<Track>]

@example

track = RSpotify::Track.find('2UzMpPKPhbcC8RbsmuURAZ')
track.class #=> RSpotify::Track
track.name  #=> "Do I Wanna Know?"

ids = %w(2UzMpPKPhbcC8RbsmuURAZ 7Jzsc04YpkRwB1zeyM39wE)
tracks = RSpotify::Base.find(ids, 'track')
tracks.class       #=> Array
tracks.first.class #=> RSpotify::Track
Calls superclass method RSpotify::Base::find
# File lib/rspotify/track.rb, line 35
def self.find(ids, market: nil)
  super(ids, 'track', market: market)
end
new(options = {}) click to toggle source
Calls superclass method RSpotify::Base::new
# File lib/rspotify/track.rb, line 62
def initialize(options = {})
  @available_markets = options['available_markets']
  @disc_number       = options['disc_number']
  @duration_ms       = options['duration_ms']
  @explicit          = options['explicit']
  @external_ids      = options['external_ids']
  @uri               = options['uri']
  @name              = options['name']
  @popularity        = options['popularity']
  @preview_url       = options['preview_url']
  @track_number      = options['track_number']
  @played_at         = options['played_at']
  @context_type      = options['context_type']
  @is_playable       = options['is_playable']

  @album = if options['album']
    Album.new options['album']
  end

  @artists = if options['artists']
    options['artists'].map { |a| Artist.new a }
  end

  @linked_from = if options['linked_from']
    TrackLink.new options['linked_from']
  end

  super(options)
end

Public Instance Methods

audio_features() click to toggle source

Retrieves the audio features for the track

# File lib/rspotify/track.rb, line 58
def audio_features
  RSpotify::AudioFeatures.find(@id)
end