getHome method
Get the home page.
The home page is structured as titled rows, returning 3 rows of music suggestions at a time. Content varies and may contain artist, album, song or playlist suggestions, sometimes mixed within the same row.
limit
Number of rows on the home page to return. (Default:3
).
Returns List of Maps keyed with title
text and contents
list.
Example list:
[
{
"title": "Your morning music",
"contents": [
{ // album result
"title": "Sentiment",
"browseId": "MPREb_QtqXtd2xZMR",
"thumbnails": [...]
},
{ // playlist result
"title": "r/EDM top submissions 01/28/2022",
"playlistId": "PLz7-xrYmULdSLRZGk-6GKUtaBZcgQNwel",
"thumbnails": [...],
"description": "redditEDM • 161 songs",
"count": "161",
"author": [
{
"name": "redditEDM",
"id": "UCaTrZ9tPiIGHrkCe5bxOGwA"
}
]
}
]
},
{
"title": "Your favorites",
"contents": [
{ // artist result
"title": "Chill Satellite",
"browseId": "UCrPLFBWdOroD57bkqPbZJog",
"subscribers": "374",
"thumbnails": [...]
},
{ // album result
"title": "Dragon",
"year": "Two Steps From Hell",
"browseId": "MPREb_M9aDqLRbSeg",
"thumbnails": [...]
}
]
},
{
"title": "Quick picks",
"contents": [
{ // song quick pick
"title": "Gravity",
"videoId": "EludZd6lfts",
"artists": [
{
"name": "yetep",
"id": "UCSW0r7dClqCoCvQeqXiZBlg"
}
],
"thumbnails": [...],
"album": {
"name": "Gravity",
"id": "MPREb_D6bICFcuuRY"
}
},
{ // video quick pick
"title": "Gryffin & Illenium (feat. Daya) - Feel Good (L3V3LS Remix)",
"videoId": "bR5l0hJDnX8",
"artists": [
{
"name": "L3V3LS",
"id": "UCCVNihbOdkOWw_-ajIYhAbQ"
}
],
"thumbnails": [...],
"views": "10M"
}
]
}
]
Implementation
Future<List> getHome({int limit = 3}) async {
const endpoint = 'browse';
final body = <String, dynamic>{'browseId': 'FEmusic_home'};
final response = await sendRequest(endpoint, body);
final results = nav(response, [...SINGLE_COLUMN_TAB, ...SECTION_LIST]);
final home = parseMixedContent(List<JsonMap>.from(results as List));
final sectionList =
nav(response, [...SINGLE_COLUMN_TAB, 'sectionListRenderer']) as JsonMap;
if (sectionList.containsKey('continuations')) {
Future<JsonMap> requestFunc(String additionalParams) =>
sendRequest(endpoint, body, additionalParams: additionalParams);
home.addAll(
await getContinuations(
sectionList,
'sectionListContinuation',
limit - home.length,
requestFunc,
parseMixedContent,
),
);
}
return home;
}