getMoodCategories method

Future<JsonMap> getMoodCategories()

Fetch "Moods & Genres" categories from YouTube Music.

Returns Map of sections and categories.

Example:

{
  "title": "Stanford Graduate School of Business",
  "thumbnails": [...],
  "episodes": {
    "browseId": "UCGwuxdEeCf0TIA2RbPOj-8g",
    "results": [
      {
        "index": 0,
        "title": "The Brain Gain: The Impact of Immigration on American Innovation with Rebecca Diamond",
        "description": "Immigrants' contributions to America ...",
        "duration": "24 min",
        "videoId": "TS3Ovvk3VAA",
        "browseId": "MPEDTS3Ovvk3VAA",
        "videoType": "MUSIC_VIDEO_TYPE_PODCAST_EPISODE",
        "date": "Mar 6, 2024",
        "thumbnails": [...]
      }
    ],
    "params": "6gPiAUdxWUJXcFlCQ3BN..."
  },
  "podcasts": {
    "browseId": null,
    "results": [
      {
        "title": "Stanford GSB Podcasts",
        "channel": {
          "id": "UCGwuxdEeCf0TIA2RbPOj-8g",
          "name": "Stanford Graduate School of Business"
        },
        "browseId": "MPSPPLxq_lXOUlvQDUNyoBYLkN8aVt5yAwEtG9",
        "podcastId": "PLxq_lXOUlvQDUNyoBYLkN8aVt5yAwEtG9",
        "thumbnails": [...]
      }
    ]
  }
}

Implementation

Future<JsonMap> getMoodCategories() async {
  final sections = <String, dynamic>{};
  final response = await sendRequest('browse', {
    'browseId': 'FEmusic_moods_and_genres',
  });
  for (final section
      in nav(response, [...SINGLE_COLUMN_TAB, ...SECTION_LIST]) as Iterable) {
    final title = nav(section, [
      ...GRID,
      'header',
      'gridHeaderRenderer',
      ...TITLE_TEXT,
    ]);
    sections[title as String] = <JsonMap>[];
    for (final category in nav(section, GRID_ITEMS) as Iterable) {
      (sections[title] as List).add({
        'title': nav(category, CATEGORY_TITLE),
        'params': nav(category, CATEGORY_PARAMS),
      });
    }
  }
  return sections;
}