parseDashboard static method

List<Song> parseDashboard({
  1. List<Result>? dashboard,
})

Implementation

static List<Song> parseDashboard({List<Result>? dashboard}) {
  List<Song> songs = List.generate(dashboard?.length ?? 0, (index) {
    Result? imageLinkElement = dashboard?[index].querySelector('a[href]');
    String? url = imageLinkElement?.href;
    Result? infoElement = dashboard?[index].querySelector('.col-6');
    String? genre = infoElement?.querySelector('span strong')?.text;
    Result? player = dashboard?[index].querySelector('.btn');
    String? cover = player
        ?.attr('data-cover')
        ?.replaceAll(RegExp('/100x100/'), '/325x325/');
    String? name = player?.attr('data-track');
    String? songUrl = player?.attr('data-url');
    String? artistsElement = player?.attr('data-artist');
    List<String>? artistStringList = artistsElement?.split(', ');
    List<Artist> artists =
        List.generate(artistStringList?.length ?? 0, (index) {
      Result? artElement =
          Result(parser.parse(artistStringList?[index]).querySelector('a'));
      String? url = artElement.attr('href');
      String? name = artElement.innerHTML;
      return Artist(url: url, name: name);
    });

    return Song(
        imageUrl: cover,
        songUrl: songUrl,
        url: url,
        genre: genre,
        name: name,
        artists: artists);
  });

  return songs;
}