microlinkhq / spotify-url-info

Get metadata from any Spotify URL.
MIT License
72 stars 16 forks source link

`getTracks` returning `duration` instead of `duration_ms` for some tracks. #107

Closed larsrickert closed 1 year ago

larsrickert commented 1 year ago

Describe the bug When calling getTracks(), some tracks will not include the property duration_ms as it is officially documented in type Tracks but instead include the property duration which is not documented in your types. This causes the duration to be undefined and is not usable for further processing.

I am using spotify-url-info version 3.1.9 and isomorphic-unfetch version 0.7.10

Spotify URL(s)

Your Code

import fetch from "isomorphic-unfetch";
import spotify, { Tracks } from "spotify-url-info";

const { getTracks, getData } = spotify(fetch);

// when fetching tracks
const tracks = await getTracks(query);
tracks.forEach(track => {
  console.log(track.duration_ms); // will be undefined for some tracks
  console.log((track as Tracks & {duration?: number}).duration); // is included in some tracks but not all
});

Example object response

{
  type: 'track',
  name: 'fool4love',
  uri: 'spotify:track:3j7ttprPTsaqGMcpUfZuOA',
  id: '3j7ttprPTsaqGMcpUfZuOA',
  title: 'fool4love',
  artists: [ { name: 'ericdoa', uri: 'spotify:artist:4hR6Bm9YYtktXzjmKhb1Cn' } ],
  coverArt: {
    extractedColors: { colorDark: [Object], colorLight: [Object] },
    sources: [ [Object], [Object], [Object] ]
  },
  releaseDate: { isoString: '2022-05-20T00:00:00Z' },
  duration: 128571,
  maxDuration: 128571,
  isPlayable: true,
  isExplicit: false,
  audioPreview: {
    url: 'https://p.scdn.co/mp3-preview/26a10276e66e450a19ace6bf181178c36e1e57b6',
    format: 'MP3_96'
  },
  hasVideo: false,
  },
  hasVideo: false,
  relatedEntityUri: 'spotify:artist:4hR6Bm9YYtktXzjmKhb1Cn',
  external_urls: { spotify: 'https://open.spotify.com/track/3j7ttprPTsaqGMcpUfZuOA' }
}
Kikobeats commented 1 year ago

Hello,

The data comes directly from Spotify. What we can do is to update types here to be up-to-date.

Can you make a PR? 🙂