parseHomeSection static method
Implementation
static HomeSection parseHomeSection(dynamic data) {
final pageType = traverseString(
data, ["contents", "title", "browseEndpoint", "pageType"]);
final playlistId = traverseString(
data,
["navigationEndpoint", "watchPlaylistEndpoint", "playlistId"],
);
return HomeSection(
title: traverseString(data, ["header", "title", "text"]) ?? '',
contents: traverseList(data, ["contents"])
.map((item) {
switch (pageType) {
case 'MUSIC_PAGE_TYPE_ALBUM':
return AlbumParser.parseHomeSection(item);
case 'MUSIC_PAGE_TYPE_PLAYLIST':
return PlaylistParser.parseHomeSection(item);
case "":
if (playlistId != null) {
return PlaylistParser.parseHomeSection(item);
} else {
return SongParser.parseHomeSection(item);
}
default:
return null;
}
})
.where((element) => element != null)
.cast<dynamic>()
.toList(),
);
}