getTracksFromPlaylistUrl method

Future<List<SpotifyResult>> getTracksFromPlaylistUrl(
  1. String url
)

Get the tracks from a Spotify Playlist URL / URI.

Note

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

Implementation

Future<List<SpotifyResult>> getTracksFromPlaylistUrl(String url) async {
  var results = <SpotifyResult>[];

  var tracks =
      await _spotifyEngine.playlists.getTracksByPlaylistId(SpotifyEngine.extractId(url)).all();

  for (var track in tracks) {
    results.add(
      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,
      ),
    );
  }

  return results;
}