getSimilar method

Future<List<Artist>?> getSimilar({
  1. String? artist,
  2. String? mbid,
  3. int? limit,
  4. bool autoCorrect = false,
})

Get all the artists similar to this artist.

https://www.last.fm/api/show/artist.getSimilar

Implementation

Future<List<Artist>?> getSimilar({
  String? artist,
  String? mbid,
  int? limit,
  bool autoCorrect = false,
}) async {
  if (artist == null && mbid == null) {
    return Future.error(
      ScrobblenautException(
        description: 'This method requires at least artist or mbid.',
      ),
    );
  }

  final parameters = {
    'artist': artist,
    'mbid': mbid,
    'limit': limit,
    'autocorrect': (autoCorrect ? 1 : 0),
  };

  final request = Request(
    api: _api,
    method: 'artist.getSimilar',
    parameters: parameters,
  );

  final response = await request.send(mode: RequestMode.GET);

  final similarArtists = response['similarartists']['artist'];

  return similarArtists == null
      ? null
      : List.generate(
          (similarArtists as List).length,
          (i) => Artist.fromJson(similarArtists[i]),
        );
}