getTracksFromAlbumUrl method

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

Get the tracks from a Spotify Album URL / URI.

Implementation

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

  var tracks = await _spotifyEngine.albums.tracks(SpotifyEngine.extractId(url)).all();
  var album = await _spotifyEngine.albums.get(SpotifyEngine.extractId(url));

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

  return results;
}