parseAlbumHeader2024 function

JsonMap parseAlbumHeader2024(
  1. JsonMap response
)

Parse the information in an album header in 2025 format.

Implementation

JsonMap parseAlbumHeader2024(JsonMap response) {
  final header =
      nav(response, [
            ...TWO_COLUMN_RENDERER,
            ...TAB_CONTENT,
            ...SECTION_LIST_ITEM,
            ...RESPONSIVE_HEADER,
          ])
          as JsonMap;
  final album = <String, dynamic>{
    'title': nav(header, TITLE_TEXT),
    'type': nav(header, SUBTITLE),
    'thumbnails': nav(header, THUMBNAILS),
    'isExplicit': nav(header, SUBTITLE_BADGE_LABEL, nullIfAbsent: true) != null,
  };

  album['description'] = nav(header, [
    'description',
    ...DESCRIPTION_SHELF,
    ...DESCRIPTION,
  ], nullIfAbsent: true);

  final albumInfo = parseSongRuns(
    ((header['subtitle'] as JsonMap)['runs'] as List).sublist(2),
  );
  final baseAuthor = parseBaseHeader(header)['author'];
  albumInfo['artists'] = baseAuthor != null ? [baseAuthor] : null;
  album.addAll(albumInfo);
  if (((header['secondSubtitle'] as JsonMap)['runs'] as List).length > 1) {
    album['trackCount'] = toInt(
      (((header['secondSubtitle'] as JsonMap)['runs'] as List)[0]
              as JsonMap)['text']
          as String,
    );
    album['duration'] =
        (((header['secondSubtitle'] as JsonMap)['runs'] as List)[2]
            as JsonMap)['text'];
  } else {
    album['duration'] =
        (((header['secondSubtitle'] as JsonMap)['runs'] as List)[0]
            as JsonMap)['text'];
  }

  // add to library/uploaded
  final buttons = header['buttons'];
  album['audioPlaylistId'] = nav(
    findObjectByKey(buttons as List, 'musicPlayButtonRenderer'),
    ['musicPlayButtonRenderer', 'playNavigationEndpoint', ...WATCH_PID],
    nullIfAbsent: true,
  );

  // remove this once A/B testing is finished and it is no longer covered
  if (album['audioPlaylistId'] == null) {
    album['audioPlaylistId'] = nav(
      findObjectByKey(buttons, 'musicPlayButtonRenderer'),
      [
        'musicPlayButtonRenderer',
        'playNavigationEndpoint',
        ...WATCH_PLAYLIST_ID,
      ],
      nullIfAbsent: true,
    );
  }

  final service = nav(findObjectByKey(buttons, 'toggleButtonRenderer'), [
    'toggleButtonRenderer',
    'defaultServiceEndpoint',
  ], nullIfAbsent: true);

  album['likeStatus'] = 'INDIFFERENT';
  if (service != null) {
    album['likeStatus'] = parseLikeStatus(service as JsonMap);
  }

  return album;
}