Class: SpotifyWebApi::Track

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/spotify_web_api/models/track.rb

Overview

Track Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(num_samples = SKIP, duration = SKIP, sample_md5 = SKIP, offset_seconds = SKIP, window_seconds = SKIP, analysis_sample_rate = SKIP, analysis_channels = SKIP, end_of_fade_in = SKIP, start_of_fade_out = SKIP, loudness = SKIP, tempo = SKIP, tempo_confidence = SKIP, time_signature = SKIP, time_signature_confidence = SKIP, key = SKIP, key_confidence = SKIP, mode = SKIP, mode_confidence = SKIP, codestring = SKIP, code_version = SKIP, echoprintstring = SKIP, echoprint_version = SKIP, synchstring = SKIP, synch_version = SKIP, rhythmstring = SKIP, rhythm_version = SKIP) ⇒ Track

Returns a new instance of Track.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/spotify_web_api/models/track.rb', line 213

def initialize(num_samples = SKIP, duration = SKIP, sample_md5 = SKIP,
               offset_seconds = SKIP, window_seconds = SKIP,
               analysis_sample_rate = SKIP, analysis_channels = SKIP,
               end_of_fade_in = SKIP, start_of_fade_out = SKIP,
               loudness = SKIP, tempo = SKIP, tempo_confidence = SKIP,
               time_signature = SKIP, time_signature_confidence = SKIP,
               key = SKIP, key_confidence = SKIP, mode = SKIP,
               mode_confidence = SKIP, codestring = SKIP,
               code_version = SKIP, echoprintstring = SKIP,
               echoprint_version = SKIP, synchstring = SKIP,
               synch_version = SKIP, rhythmstring = SKIP,
               rhythm_version = SKIP)
  @num_samples = num_samples unless num_samples == SKIP
  @duration = duration unless duration == SKIP
  @sample_md5 = sample_md5 unless sample_md5 == SKIP
  @offset_seconds = offset_seconds unless offset_seconds == SKIP
  @window_seconds = window_seconds unless window_seconds == SKIP
  @analysis_sample_rate = analysis_sample_rate unless analysis_sample_rate == SKIP
  @analysis_channels = analysis_channels unless analysis_channels == SKIP
  @end_of_fade_in = end_of_fade_in unless end_of_fade_in == SKIP
  @start_of_fade_out = start_of_fade_out unless start_of_fade_out == SKIP
  @loudness = loudness unless loudness == SKIP
  @tempo = tempo unless tempo == SKIP
  @tempo_confidence = tempo_confidence unless tempo_confidence == SKIP
  @time_signature = time_signature unless time_signature == SKIP
  unless time_signature_confidence == SKIP
    @time_signature_confidence =
      time_signature_confidence
  end
  @key = key unless key == SKIP
  @key_confidence = key_confidence unless key_confidence == SKIP
  @mode = mode unless mode == SKIP
  @mode_confidence = mode_confidence unless mode_confidence == SKIP
  @codestring = codestring unless codestring == SKIP
  @code_version = code_version unless code_version == SKIP
  @echoprintstring = echoprintstring unless echoprintstring == SKIP
  @echoprint_version = echoprint_version unless echoprint_version == SKIP
  @synchstring = synchstring unless synchstring == SKIP
  @synch_version = synch_version unless synch_version == SKIP
  @rhythmstring = rhythmstring unless rhythmstring == SKIP
  @rhythm_version = rhythm_version unless rhythm_version == SKIP
end

Instance Attribute Details

#analysis_channelsInteger

The number of channels used for analysis. If 1, all channels are summed together to mono before analysis.

Returns:

  • (Integer)


44
45
46
# File 'lib/spotify_web_api/models/track.rb', line 44

def analysis_channels
  @analysis_channels
end

#analysis_sample_rateInteger

The sample rate used to decode and analyze this track. May differ from the actual sample rate of this track available on Spotify.

Returns:

  • (Integer)


39
40
41
# File 'lib/spotify_web_api/models/track.rb', line 39

def analysis_sample_rate
  @analysis_sample_rate
end

#code_versionFloat

A version number for the Echo Nest Musical Fingerprint format used in the codestring field.

Returns:

  • (Float)


115
116
117
# File 'lib/spotify_web_api/models/track.rb', line 115

def code_version
  @code_version
end

#codestringString

An [Echo Nest Musical Fingerprint (ENMFP)](academiccommons.columbia.edu/doi/10.7916/D8Q248M4) codestring for this track.

Returns:

  • (String)


110
111
112
# File 'lib/spotify_web_api/models/track.rb', line 110

def codestring
  @codestring
end

#durationFloat

Length of the track in seconds.

Returns:

  • (Float)


19
20
21
# File 'lib/spotify_web_api/models/track.rb', line 19

def duration
  @duration
end

#echoprint_versionFloat

A version number for the EchoPrint format used in the echoprintstring field.

Returns:

  • (Float)


125
126
127
# File 'lib/spotify_web_api/models/track.rb', line 125

def echoprint_version
  @echoprint_version
end

#echoprintstringString

An [EchoPrint](github.com/spotify/echoprint-codegen) codestring for this track.

Returns:

  • (String)


120
121
122
# File 'lib/spotify_web_api/models/track.rb', line 120

def echoprintstring
  @echoprintstring
end

#end_of_fade_inFloat

The time, in seconds, at which the track’s fade-in period ends. If the track has no fade-in, this will be 0.0.

Returns:

  • (Float)


49
50
51
# File 'lib/spotify_web_api/models/track.rb', line 49

def end_of_fade_in
  @end_of_fade_in
end

#keyInteger

The key the track is in. Integers map to pitches using standard [Pitch Class notation](en.wikipedia.org/wiki/Pitch_class). E.g. 0 = C, 1

C♯/D♭, 2 = D, and so on. If no key was detected, the value is -1.

Returns:

  • (Integer)


90
91
92
# File 'lib/spotify_web_api/models/track.rb', line 90

def key
  @key
end

#key_confidenceFloat

The confidence, from 0.0 to 1.0, of the reliability of the ‘key`.

Returns:

  • (Float)


94
95
96
# File 'lib/spotify_web_api/models/track.rb', line 94

def key_confidence
  @key_confidence
end

#loudnessFloat

The overall loudness of a track in decibels (dB). Loudness values are averaged across the entire track and are useful for comparing relative loudness of tracks. Loudness is the quality of a sound that is the primary psychological correlate of physical strength (amplitude). Values typically range between -60 and 0 db.

Returns:

  • (Float)


62
63
64
# File 'lib/spotify_web_api/models/track.rb', line 62

def loudness
  @loudness
end

#modeInteger

Mode indicates the modality (major or minor) of a track, the type of scale from which its melodic content is derived. Major is represented by 1 and minor is 0.

Returns:

  • (Integer)


100
101
102
# File 'lib/spotify_web_api/models/track.rb', line 100

def mode
  @mode
end

#mode_confidenceFloat

The confidence, from 0.0 to 1.0, of the reliability of the ‘mode`.

Returns:

  • (Float)


104
105
106
# File 'lib/spotify_web_api/models/track.rb', line 104

def mode_confidence
  @mode_confidence
end

#num_samplesInteger

The exact number of audio samples analyzed from this track. See also ‘analysis_sample_rate`.

Returns:

  • (Integer)


15
16
17
# File 'lib/spotify_web_api/models/track.rb', line 15

def num_samples
  @num_samples
end

#offset_secondsInteger

An offset to the start of the region of the track that was analyzed. (As the entire track is analyzed, this should always be 0.)

Returns:

  • (Integer)


28
29
30
# File 'lib/spotify_web_api/models/track.rb', line 28

def offset_seconds
  @offset_seconds
end

#rhythm_versionFloat

A version number for the Rhythmstring used in the rhythmstring field.

Returns:

  • (Float)


142
143
144
# File 'lib/spotify_web_api/models/track.rb', line 142

def rhythm_version
  @rhythm_version
end

#rhythmstringString

A Rhythmstring for this track. The format of this string is similar to the Synchstring.

Returns:

  • (String)


138
139
140
# File 'lib/spotify_web_api/models/track.rb', line 138

def rhythmstring
  @rhythmstring
end

#sample_md5String

This field will always contain the empty string.

Returns:

  • (String)


23
24
25
# File 'lib/spotify_web_api/models/track.rb', line 23

def sample_md5
  @sample_md5
end

#start_of_fade_outFloat

The time, in seconds, at which the track’s fade-out period starts. If the track has no fade-out, this should match the track’s length.

Returns:

  • (Float)


54
55
56
# File 'lib/spotify_web_api/models/track.rb', line 54

def start_of_fade_out
  @start_of_fade_out
end

#synch_versionFloat

A version number for the Synchstring used in the synchstring field.

Returns:

  • (Float)


133
134
135
# File 'lib/spotify_web_api/models/track.rb', line 133

def synch_version
  @synch_version
end

#synchstringString

A [Synchstring](github.com/echonest/synchdata) for this track.

Returns:

  • (String)


129
130
131
# File 'lib/spotify_web_api/models/track.rb', line 129

def synchstring
  @synchstring
end

#tempoFloat

The overall estimated tempo of a track in beats per minute (BPM). In musical terminology, tempo is the speed or pace of a given piece and derives directly from the average beat duration.

Returns:

  • (Float)


68
69
70
# File 'lib/spotify_web_api/models/track.rb', line 68

def tempo
  @tempo
end

#tempo_confidenceFloat

The confidence, from 0.0 to 1.0, of the reliability of the ‘tempo`.

Returns:

  • (Float)


72
73
74
# File 'lib/spotify_web_api/models/track.rb', line 72

def tempo_confidence
  @tempo_confidence
end

#time_signatureInteger

An estimated time signature. The time signature (meter) is a notational convention to specify how many beats are in each bar (or measure). The time signature ranges from 3 to 7 indicating time signatures of “3/4”, to “7/4”.

Returns:

  • (Integer)


79
80
81
# File 'lib/spotify_web_api/models/track.rb', line 79

def time_signature
  @time_signature
end

#time_signature_confidenceFloat

The confidence, from 0.0 to 1.0, of the reliability of the ‘time_signature`.

Returns:

  • (Float)


84
85
86
# File 'lib/spotify_web_api/models/track.rb', line 84

def time_signature_confidence
  @time_signature_confidence
end

#window_secondsInteger

The length of the region of the track was analyzed, if a subset of the track was analyzed. (As the entire track is analyzed, this should always be 0.)

Returns:

  • (Integer)


34
35
36
# File 'lib/spotify_web_api/models/track.rb', line 34

def window_seconds
  @window_seconds
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/spotify_web_api/models/track.rb', line 257

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  num_samples = hash.key?('num_samples') ? hash['num_samples'] : SKIP
  duration = hash.key?('duration') ? hash['duration'] : SKIP
  sample_md5 = hash.key?('sample_md5') ? hash['sample_md5'] : SKIP
  offset_seconds =
    hash.key?('offset_seconds') ? hash['offset_seconds'] : SKIP
  window_seconds =
    hash.key?('window_seconds') ? hash['window_seconds'] : SKIP
  analysis_sample_rate =
    hash.key?('analysis_sample_rate') ? hash['analysis_sample_rate'] : SKIP
  analysis_channels =
    hash.key?('analysis_channels') ? hash['analysis_channels'] : SKIP
  end_of_fade_in =
    hash.key?('end_of_fade_in') ? hash['end_of_fade_in'] : SKIP
  start_of_fade_out =
    hash.key?('start_of_fade_out') ? hash['start_of_fade_out'] : SKIP
  loudness = hash.key?('loudness') ? hash['loudness'] : SKIP
  tempo = hash.key?('tempo') ? hash['tempo'] : SKIP
  tempo_confidence =
    hash.key?('tempo_confidence') ? hash['tempo_confidence'] : SKIP
  time_signature =
    hash.key?('time_signature') ? hash['time_signature'] : SKIP
  time_signature_confidence =
    hash.key?('time_signature_confidence') ? hash['time_signature_confidence'] : SKIP
  key = hash.key?('key') ? hash['key'] : SKIP
  key_confidence =
    hash.key?('key_confidence') ? hash['key_confidence'] : SKIP
  mode = hash.key?('mode') ? hash['mode'] : SKIP
  mode_confidence =
    hash.key?('mode_confidence') ? hash['mode_confidence'] : SKIP
  codestring = hash.key?('codestring') ? hash['codestring'] : SKIP
  code_version = hash.key?('code_version') ? hash['code_version'] : SKIP
  echoprintstring =
    hash.key?('echoprintstring') ? hash['echoprintstring'] : SKIP
  echoprint_version =
    hash.key?('echoprint_version') ? hash['echoprint_version'] : SKIP
  synchstring = hash.key?('synchstring') ? hash['synchstring'] : SKIP
  synch_version = hash.key?('synch_version') ? hash['synch_version'] : SKIP
  rhythmstring = hash.key?('rhythmstring') ? hash['rhythmstring'] : SKIP
  rhythm_version =
    hash.key?('rhythm_version') ? hash['rhythm_version'] : SKIP

  # Create object from extracted values.
  Track.new(num_samples,
            duration,
            sample_md5,
            offset_seconds,
            window_seconds,
            analysis_sample_rate,
            analysis_channels,
            end_of_fade_in,
            start_of_fade_out,
            loudness,
            tempo,
            tempo_confidence,
            time_signature,
            time_signature_confidence,
            key,
            key_confidence,
            mode,
            mode_confidence,
            codestring,
            code_version,
            echoprintstring,
            echoprint_version,
            synchstring,
            synch_version,
            rhythmstring,
            rhythm_version)
end

.namesObject

A mapping from model property names to API property names.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/spotify_web_api/models/track.rb', line 145

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['num_samples'] = 'num_samples'
  @_hash['duration'] = 'duration'
  @_hash['sample_md5'] = 'sample_md5'
  @_hash['offset_seconds'] = 'offset_seconds'
  @_hash['window_seconds'] = 'window_seconds'
  @_hash['analysis_sample_rate'] = 'analysis_sample_rate'
  @_hash['analysis_channels'] = 'analysis_channels'
  @_hash['end_of_fade_in'] = 'end_of_fade_in'
  @_hash['start_of_fade_out'] = 'start_of_fade_out'
  @_hash['loudness'] = 'loudness'
  @_hash['tempo'] = 'tempo'
  @_hash['tempo_confidence'] = 'tempo_confidence'
  @_hash['time_signature'] = 'time_signature'
  @_hash['time_signature_confidence'] = 'time_signature_confidence'
  @_hash['key'] = 'key'
  @_hash['key_confidence'] = 'key_confidence'
  @_hash['mode'] = 'mode'
  @_hash['mode_confidence'] = 'mode_confidence'
  @_hash['codestring'] = 'codestring'
  @_hash['code_version'] = 'code_version'
  @_hash['echoprintstring'] = 'echoprintstring'
  @_hash['echoprint_version'] = 'echoprint_version'
  @_hash['synchstring'] = 'synchstring'
  @_hash['synch_version'] = 'synch_version'
  @_hash['rhythmstring'] = 'rhythmstring'
  @_hash['rhythm_version'] = 'rhythm_version'
  @_hash
end

.nullablesObject

An array for nullable fields



209
210
211
# File 'lib/spotify_web_api/models/track.rb', line 209

def self.nullables
  []
end

.optionalsObject

An array for optional fields



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/spotify_web_api/models/track.rb', line 177

def self.optionals
  %w[
    num_samples
    duration
    sample_md5
    offset_seconds
    window_seconds
    analysis_sample_rate
    analysis_channels
    end_of_fade_in
    start_of_fade_out
    loudness
    tempo
    tempo_confidence
    time_signature
    time_signature_confidence
    key
    key_confidence
    mode
    mode_confidence
    codestring
    code_version
    echoprintstring
    echoprint_version
    synchstring
    synch_version
    rhythmstring
    rhythm_version
  ]
end