getTrackFromTrackUrl method

Future<SpotifyResult> getTrackFromTrackUrl(
  1. String url
)

Find a track from a Spotify Track URL / URI.

Note

  • URL needn't be cleaned before passing it to this function.

Implementation

Future<SpotifyResult> getTrackFromTrackUrl(String url) async {
  var track = await _spotifyEngine.tracks.get(SpotifyEngine.extractId(url));

  return SpotifyResult(
    artists: track.artists?.map((artist) => artist.name!).toList() ?? [],
    title: track.name ?? '',
    album: track.album?.name ?? '',
    sDuration: track.durationMs! ~/ 1000,
    srcUrl: 'https://open.spotify.com/track/${track.uri?.split(':').last}',
    artUrl: track.album?.images?.first.url ?? '',
    source: Source.spotify,
    diskNumber: track.discNumber ?? 0,
    trackNumber: track.trackNumber ?? 0,
  );
}