parseAlbum function
- JsonMap result
Parses an album from result
.
Implementation
JsonMap parseAlbum(JsonMap result) {
final JsonMap realResult;
if (result.containsKey(MTRIR)) {
realResult = nav(result, [MTRIR]) as JsonMap;
} else {
realResult = result;
}
final artists =
List<JsonMap>.from(
(nav(realResult, ['subtitle', 'runs'], nullIfAbsent: true) ?? [])
as List,
) // TODO should nullIfAbsent be true?
.where((x) => x.containsKey('navigationEndpoint'))
.map((x) => parseIdName(x as JsonMap?))
.toList();
final album = <String, dynamic>{
'title': nav(realResult, TITLE_TEXT),
'type': nav(realResult, SUBTITLE),
'artists': artists,
'browseId': nav(realResult, [...TITLE, ...NAVIGATION_BROWSE_ID]),
'audioPlaylistId': parseAlbumPlaylistIdIfExists(
nav(realResult, THUMBNAIL_OVERLAY_NAVIGATION, nullIfAbsent: true)
as JsonMap?,
),
'thumbnails': nav(realResult, THUMBNAIL_RENDERER),
'isExplicit':
nav(realResult, SUBTITLE_BADGE_LABEL, nullIfAbsent: true) != null,
};
final year = nav(realResult, SUBTITLE2, nullIfAbsent: true);
if (year != null && (year is String) && RegExp(r'^\d+$').hasMatch(year)) {
album['year'] = year;
}
return album;
}