forked from zmb3/spotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
track_attributes.go
431 lines (381 loc) · 18 KB
/
track_attributes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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
175
176
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
207
208
209
210
211
212
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
255
256
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
package spotify
// TrackAttributes contains various tuneable parameters that can be used for recommendations.
// For each of the tuneable track attributes, target, min and max values may be provided.
// Target:
// Tracks with the attribute values nearest to the target values will be preferred.
// For example, you might request TargetEnergy=0.6 and TargetDanceability=0.8.
// All target values will be weighed equally in ranking results.
// Max:
// A hard ceiling on the selected track attribute’s value can be provided.
// For example, MaxInstrumentalness=0.35 would filter out most tracks
// that are likely to be instrumental.
// Min:
// A hard floor on the selected track attribute’s value can be provided.
// For example, min_tempo=140 would restrict results to only those tracks
// with a tempo of greater than 140 beats per minute.
type TrackAttributes struct {
intAttributes map[string]int
floatAttributes map[string]float64
}
// NewTrackAttributes returns a new TrackAttributes instance with no attributes set.
// Attributes can then be chained following a builder pattern:
// ta := NewTrackAttributes().
// MaxAcousticness(0.15).
// TargetPopularity(90)
func NewTrackAttributes() *TrackAttributes {
return &TrackAttributes{
intAttributes: map[string]int{},
floatAttributes: map[string]float64{},
}
}
// MaxAcousticness sets the maximum acousticness
// Acousticness is a confidence measure from 0.0 to 1.0 of whether
// the track is acoustic. A value of 1.0 represents high confidence
// that the track is acoustic.
func (ta *TrackAttributes) MaxAcousticness(acousticness float64) *TrackAttributes {
ta.floatAttributes["max_acousticness"] = acousticness
return ta
}
// MinAcousticness sets the minimum acousticness
// Acousticness is a confidence measure from 0.0 to 1.0 of whether
// the track is acoustic. A value of 1.0 represents high confidence
// that the track is acoustic.
func (ta *TrackAttributes) MinAcousticness(acousticness float64) *TrackAttributes {
ta.floatAttributes["min_acousticness"] = acousticness
return ta
}
// TargetAcousticness sets the target acousticness
// Acousticness is a confidence measure from 0.0 to 1.0 of whether
// the track is acoustic. A value of 1.0 represents high confidence
// that the track is acoustic.
func (ta *TrackAttributes) TargetAcousticness(acousticness float64) *TrackAttributes {
ta.floatAttributes["target_acousticness"] = acousticness
return ta
}
// MaxDanceability sets the maximum danceability
// Danceability describes how suitable a track is for dancing based on
// a combination of musical elements including tempo, rhythm stability,
// beat strength, and overall regularity.
// A value of 0.0 is least danceable and 1.0 is most danceable.
func (ta *TrackAttributes) MaxDanceability(danceability float64) *TrackAttributes {
ta.floatAttributes["max_danceability"] = danceability
return ta
}
// MinDanceability sets the minimum danceability
// Danceability describes how suitable a track is for dancing based on
// a combination of musical elements including tempo, rhythm stability,
// beat strength, and overall regularity.
// A value of 0.0 is least danceable and 1.0 is most danceable.
func (ta *TrackAttributes) MinDanceability(danceability float64) *TrackAttributes {
ta.floatAttributes["min_danceability"] = danceability
return ta
}
// TargetDanceability sets the target danceability
// Danceability describes how suitable a track is for dancing based on
// a combination of musical elements including tempo, rhythm stability,
// beat strength, and overall regularity.
// A value of 0.0 is least danceable and 1.0 is most danceable.
func (ta *TrackAttributes) TargetDanceability(danceability float64) *TrackAttributes {
ta.floatAttributes["target_danceability"] = danceability
return ta
}
// MaxDuration sets the maximum length of the track in milliseconds
func (ta *TrackAttributes) MaxDuration(duration int) *TrackAttributes {
ta.intAttributes["max_duration_ms"] = duration
return ta
}
// MinDuration sets the minimum length of the track in milliseconds
func (ta *TrackAttributes) MinDuration(duration int) *TrackAttributes {
ta.intAttributes["min_duration_ms"] = duration
return ta
}
// TargetDuration sets the target length of the track in milliseconds
func (ta *TrackAttributes) TargetDuration(duration int) *TrackAttributes {
ta.intAttributes["target_duration_ms"] = duration
return ta
}
// MaxEnergy sets the maximum energy
// Energy is a measure from 0.0 to 1.0 and represents a perceptual measure
// of intensity and activity. Typically, energetic tracks feel fast, loud,
// and noisy.
func (ta *TrackAttributes) MaxEnergy(energy float64) *TrackAttributes {
ta.floatAttributes["max_energy"] = energy
return ta
}
// MinEnergy sets the minimum energy
// Energy is a measure from 0.0 to 1.0 and represents a perceptual measure
// of intensity and activity. Typically, energetic tracks feel fast, loud,
// and noisy.
func (ta *TrackAttributes) MinEnergy(energy float64) *TrackAttributes {
ta.floatAttributes["min_energy"] = energy
return ta
}
// TargetEnergy sets the target energy
// Energy is a measure from 0.0 to 1.0 and represents a perceptual measure
// of intensity and activity. Typically, energetic tracks feel fast, loud,
// and noisy.
func (ta *TrackAttributes) TargetEnergy(energy float64) *TrackAttributes {
ta.floatAttributes["target_energy"] = energy
return ta
}
// MaxInstrumentalness sets the maximum instrumentalness
// Instrumentalness predicts whether a track contains no vocals.
// "Ooh" and "aah" sounds are treated as instrumental in this context.
// Rap or spoken word tracks are clearly "vocal".
// The closer the instrumentalness value is to 1.0,
// the greater likelihood the track contains no vocal content.
// Values above 0.5 are intended to represent instrumental tracks,
// but confidence is higher as the value approaches 1.0.
func (ta *TrackAttributes) MaxInstrumentalness(instrumentalness float64) *TrackAttributes {
ta.floatAttributes["max_instrumentalness"] = instrumentalness
return ta
}
// MinInstrumentalness sets the minimum instrumentalness
// Instrumentalness predicts whether a track contains no vocals.
// "Ooh" and "aah" sounds are treated as instrumental in this context.
// Rap or spoken word tracks are clearly "vocal".
// The closer the instrumentalness value is to 1.0,
// the greater likelihood the track contains no vocal content.
// Values above 0.5 are intended to represent instrumental tracks,
// but confidence is higher as the value approaches 1.0.
func (ta *TrackAttributes) MinInstrumentalness(instrumentalness float64) *TrackAttributes {
ta.floatAttributes["min_instrumentalness"] = instrumentalness
return ta
}
// TargetInstrumentalness sets the target instrumentalness
// Instrumentalness predicts whether a track contains no vocals.
// "Ooh" and "aah" sounds are treated as instrumental in this context.
// Rap or spoken word tracks are clearly "vocal".
// The closer the instrumentalness value is to 1.0,
// the greater likelihood the track contains no vocal content.
// Values above 0.5 are intended to represent instrumental tracks,
// but confidence is higher as the value approaches 1.0.
func (ta *TrackAttributes) TargetInstrumentalness(instrumentalness float64) *TrackAttributes {
ta.floatAttributes["target_instrumentalness"] = instrumentalness
return ta
}
// MaxKey sets the maximum key
// Integers map to pitches using standard Pitch Class notation
// (https://en.wikipedia.org/wiki/Pitch_class).
func (ta *TrackAttributes) MaxKey(key int) *TrackAttributes {
ta.intAttributes["max_key"] = key
return ta
}
// MinKey sets the minimum key
// Integers map to pitches using standard Pitch Class notation
// (https://en.wikipedia.org/wiki/Pitch_class).
func (ta *TrackAttributes) MinKey(key int) *TrackAttributes {
ta.intAttributes["min_key"] = key
return ta
}
// TargetKey sets the target key
// Integers map to pitches using standard Pitch Class notation
// (https://en.wikipedia.org/wiki/Pitch_class).
func (ta *TrackAttributes) TargetKey(key int) *TrackAttributes {
ta.intAttributes["target_key"] = key
return ta
}
// MaxLiveness sets the maximum liveness
// Detects the presence of an audience in the recording. Higher liveness
// values represent an increased probability that the track was performed live.
// A value above 0.8 provides strong likelihood that the track is live.
func (ta *TrackAttributes) MaxLiveness(liveness float64) *TrackAttributes {
ta.floatAttributes["max_liveness"] = liveness
return ta
}
// MinLiveness sets the minimum liveness
// Detects the presence of an audience in the recording. Higher liveness
// values represent an increased probability that the track was performed live.
// A value above 0.8 provides strong likelihood that the track is live.
func (ta *TrackAttributes) MinLiveness(liveness float64) *TrackAttributes {
ta.floatAttributes["min_liveness"] = liveness
return ta
}
// TargetLiveness sets the target liveness
// Detects the presence of an audience in the recording. Higher liveness
// values represent an increased probability that the track was performed live.
// A value above 0.8 provides strong likelihood that the track is live.
func (ta *TrackAttributes) TargetLiveness(liveness float64) *TrackAttributes {
ta.floatAttributes["target_liveness"] = liveness
return ta
}
// MaxLoudness sets the maximum loudness in decibels (dB)
// Loudness values are averaged across the entire track and are
// useful for comparing the relative loudness of tracks.
// Typical values range between -60 and 0 dB.
func (ta *TrackAttributes) MaxLoudness(loudness float64) *TrackAttributes {
ta.floatAttributes["max_loudness"] = loudness
return ta
}
// MinLoudness sets the minimum loudness in decibels (dB)
// Loudness values are averaged across the entire track and are
// useful for comparing the relative loudness of tracks.
// Typical values range between -60 and 0 dB.
func (ta *TrackAttributes) MinLoudness(loudness float64) *TrackAttributes {
ta.floatAttributes["min_loudness"] = loudness
return ta
}
// TargetLoudness sets the target loudness in decibels (dB)
// Loudness values are averaged across the entire track and are
// useful for comparing the relative loudness of tracks.
// Typical values range between -60 and 0 dB.
func (ta *TrackAttributes) TargetLoudness(loudness float64) *TrackAttributes {
ta.floatAttributes["target_loudness"] = loudness
return ta
}
// MaxMode sets the maximum mode
// Mode indicates the modality (major or minor) of a track.
func (ta *TrackAttributes) MaxMode(mode int) *TrackAttributes {
ta.intAttributes["max_mode"] = mode
return ta
}
// MinMode sets the minimum mode
// Mode indicates the modality (major or minor) of a track.
func (ta *TrackAttributes) MinMode(mode int) *TrackAttributes {
ta.intAttributes["min_mode"] = mode
return ta
}
// TargetMode sets the target mode
// Mode indicates the modality (major or minor) of a track.
func (ta *TrackAttributes) TargetMode(mode int) *TrackAttributes {
ta.intAttributes["target_mode"] = mode
return ta
}
// MaxPopularity sets the maximum popularity.
// The value will be between 0 and 100, with 100 being the most popular.
// The popularity is calculated by algorithm and is based, in the most part,
// on the total number of plays the track has had and how recent those plays are.
// Note: When applying track relinking via the market parameter, it is expected to find
// relinked tracks with popularities that do not match min_*, max_* and target_* popularities.
// These relinked tracks are accurate replacements for unplayable tracks
// with the expected popularity scores. Original, non-relinked tracks are
// available via the linked_from attribute of the relinked track response.
func (ta *TrackAttributes) MaxPopularity(popularity int) *TrackAttributes {
ta.intAttributes["max_popularity"] = popularity
return ta
}
// MinPopularity sets the minimum popularity.
// The value will be between 0 and 100, with 100 being the most popular.
// The popularity is calculated by algorithm and is based, in the most part,
// on the total number of plays the track has had and how recent those plays are.
// Note: When applying track relinking via the market parameter, it is expected to find
// relinked tracks with popularities that do not match min_*, max_* and target_* popularities.
// These relinked tracks are accurate replacements for unplayable tracks
// with the expected popularity scores. Original, non-relinked tracks are
// available via the linked_from attribute of the relinked track response.
func (ta *TrackAttributes) MinPopularity(popularity int) *TrackAttributes {
ta.intAttributes["min_popularity"] = popularity
return ta
}
// TargetPopularity sets the target popularity.
// The value will be between 0 and 100, with 100 being the most popular.
// The popularity is calculated by algorithm and is based, in the most part,
// on the total number of plays the track has had and how recent those plays are.
// Note: When applying track relinking via the market parameter, it is expected to find
// relinked tracks with popularities that do not match min_*, max_* and target_* popularities.
// These relinked tracks are accurate replacements for unplayable tracks
// with the expected popularity scores. Original, non-relinked tracks are
// available via the linked_from attribute of the relinked track response.
func (ta *TrackAttributes) TargetPopularity(popularity int) *TrackAttributes {
ta.intAttributes["target_popularity"] = popularity
return ta
}
// MaxSpeechiness sets the maximum speechiness.
// Speechiness detects the presence of spoken words in a track.
// The more exclusively speech-like the recording, the closer to 1.0
// the speechiness will be.
// Values above 0.66 describe tracks that are probably made entirely of
// spoken words. Values between 0.33 and 0.66 describe tracks that may
// contain both music and speech, including such cases as rap music.
// Values below 0.33 most likely represent music and other non-speech-like tracks.
func (ta *TrackAttributes) MaxSpeechiness(speechiness float64) *TrackAttributes {
ta.floatAttributes["max_speechiness"] = speechiness
return ta
}
// MinSpeechiness sets the minimum speechiness.
// Speechiness detects the presence of spoken words in a track.
// The more exclusively speech-like the recording, the closer to 1.0
// the speechiness will be.
// Values above 0.66 describe tracks that are probably made entirely of
// spoken words. Values between 0.33 and 0.66 describe tracks that may
// contain both music and speech, including such cases as rap music.
// Values below 0.33 most likely represent music and other non-speech-like tracks.
func (ta *TrackAttributes) MinSpeechiness(speechiness float64) *TrackAttributes {
ta.floatAttributes["min_speechiness"] = speechiness
return ta
}
// TargetSpeechiness sets the target speechiness.
// Speechiness detects the presence of spoken words in a track.
// The more exclusively speech-like the recording, the closer to 1.0
// the speechiness will be.
// Values above 0.66 describe tracks that are probably made entirely of
// spoken words. Values between 0.33 and 0.66 describe tracks that may
// contain both music and speech, including such cases as rap music.
// Values below 0.33 most likely represent music and other non-speech-like tracks.
func (ta *TrackAttributes) TargetSpeechiness(speechiness float64) *TrackAttributes {
ta.floatAttributes["target_speechiness"] = speechiness
return ta
}
// MaxTempo sets the maximum tempo in beats per minute (BPM).
func (ta *TrackAttributes) MaxTempo(tempo float64) *TrackAttributes {
ta.floatAttributes["max_tempo"] = tempo
return ta
}
// MinTempo sets the minimum tempo in beats per minute (BPM).
func (ta *TrackAttributes) MinTempo(tempo float64) *TrackAttributes {
ta.floatAttributes["min_tempo"] = tempo
return ta
}
// TargetTempo sets the target tempo in beats per minute (BPM).
func (ta *TrackAttributes) TargetTempo(tempo float64) *TrackAttributes {
ta.floatAttributes["target_tempo"] = tempo
return ta
}
// MaxTimeSignature sets the maximum time signature
// The time signature (meter) is a notational convention to
// specify how many beats are in each bar (or measure).
func (ta *TrackAttributes) MaxTimeSignature(timeSignature int) *TrackAttributes {
ta.intAttributes["max_time_signature"] = timeSignature
return ta
}
// MinTimeSignature sets the minimum time signature
// The time signature (meter) is a notational convention to
// specify how many beats are in each bar (or measure).
func (ta *TrackAttributes) MinTimeSignature(timeSignature int) *TrackAttributes {
ta.intAttributes["min_time_signature"] = timeSignature
return ta
}
// TargetTimeSignature sets the target time signature
// The time signature (meter) is a notational convention to
// specify how many beats are in each bar (or measure).
func (ta *TrackAttributes) TargetTimeSignature(timeSignature int) *TrackAttributes {
ta.intAttributes["target_time_signature"] = timeSignature
return ta
}
// MaxValence sets the maximum valence.
// Valence is a measure from 0.0 to 1.0 describing the musical positiveness
/// conveyed by a track.
// Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric),
// while tracks with low valence sound more negative (e.g. sad, depressed, angry).
func (ta *TrackAttributes) MaxValence(valence float64) *TrackAttributes {
ta.floatAttributes["max_valence"] = valence
return ta
}
// MinValence sets the minimum valence.
// Valence is a measure from 0.0 to 1.0 describing the musical positiveness
/// conveyed by a track.
// Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric),
// while tracks with low valence sound more negative (e.g. sad, depressed, angry).
func (ta *TrackAttributes) MinValence(valence float64) *TrackAttributes {
ta.floatAttributes["min_valence"] = valence
return ta
}
// TargetValence sets the target valence.
// Valence is a measure from 0.0 to 1.0 describing the musical positiveness
/// conveyed by a track.
// Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric),
// while tracks with low valence sound more negative (e.g. sad, depressed, angry).
func (ta *TrackAttributes) TargetValence(valence float64) *TrackAttributes {
ta.floatAttributes["target_valence"] = valence
return ta
}