How to Handle Missing Audio Features in MeloData
Before using audio features to sort a playlist, decide what should happen when a track has no value for the field you are sorting on.
MeloData reports missing audio features as null. Treating that as zero can send unknown tracks to one end of a ranking and make the result look more certain than the data supports.
Keep unavailable values separate. If tempo is required, omit tracks without a finite tempo from that calculation or show that the value is missing. If valence is optional, use the available features and leave valence out when it's null.
Check the response source as well. Archive data and live preview analysis have different field coverage. A value derived from an audio preview describes that preview, which may differ from the full track.
An uncached track may first return HTTP 202. Follow Retry-After, use a bounded retry loop, and handle a later metadata-only or unavailable result. A loading indicator should not depend on every track eventually receiving every feature.
The current MeloData documentation describes these states. Start there when deciding which fields your integration can require.
Keep missing values out of a tempo calculation
For a completed response with a features object, check for a finite numeric BPM before using it. This JavaScript example keeps missing or invalid values as null:
function bpmForRanking(data) {
const bpm = data?.features?.bpm;
return typeof bpm === "number" && Number.isFinite(bpm)
? bpm
: null;
}
Don't use Number(value) for this check. In JavaScript, Number(null) is zero. That conversion loses the distinction between a missing measurement and a numeric result.
Check the response state first
The feature endpoint is GET /api/v1/tracks/{isrc}/features. Use this order when handling its response:
- If the HTTP status is 202, respect
Retry-Afterand apply your retry limit. There isn't a completed feature record yet. - Handle HTTP errors separately from successful data responses.
- For a successful response, check
data.statusforpartialorunavailablebefore treating it as a completed analysis. - For a completed analysis, inspect
data.sourceand the individual feature values. Partial and unavailable responses don't include the same fields as a completed record.
A partial result may still contain a catalog BPM, but it isn't a full audio analysis. Decide whether that source is appropriate for your feature before mixing it with measured values.
Live analysis uses an audio preview, so a measurement may describe a different section from the one your listener hears. The MeloData documentation explains source-specific coverage and the preview-window limits.