getPodcast method
Returns podcast metadata and episodes.
playlistId
Playlist id.limit
How many songs to return.null
retrieves them all. (Default:100
).
NOTE:
- To add a podcast to your library, you need to call
ratePlaylist
on it. // TODO ratePlaylist is currently missing
Returns Map with podcast information.
Example:
{
"author": {
"name": "Stanford Graduate School of Business",
"id": "UCGwuxdEeCf0TIA2RbPOj-8g"
},
"title": "Think Fast, Talk Smart: The Podcast",
"description": "Join Matt Abrahams, a lecturer of...",
"saved": false,
"episodes": [
{
"index": 0,
"title": "132. Lean Into Failure: How to Make Mistakes That Work | Think Fast, Talk Smart: Communication...",
"description": "Effective and productive teams and...",
"duration": "25 min",
"videoId": "xAEGaW2my7E",
"browseId": "MPEDxAEGaW2my7E",
"videoType": "MUSIC_VIDEO_TYPE_PODCAST_EPISODE",
"date": "Mar 5, 2024",
"thumbnails": [...]
}
]
}
Implementation
Future<JsonMap> getPodcast(String playlistId, {int? limit = 100}) async {
final browseId =
playlistId.startsWith('MPSP') ? playlistId : 'MPSP$playlistId';
final body = {'browseId': browseId};
const endpoint = 'browse';
final response = await sendRequest(endpoint, body);
final twoColumns = nav(response, TWO_COLUMN_RENDERER);
final header = nav(twoColumns, [
...TAB_CONTENT,
...SECTION_LIST_ITEM,
...RESPONSIVE_HEADER,
]);
final podcast = parsePodcastHeader(header as JsonMap);
final results =
nav(twoColumns, [
'secondaryContents',
...SECTION_LIST_ITEM,
...MUSIC_SHELF,
])
as JsonMap;
Future<List> parseFunc(contents) =>
parseContentList(contents as List<JsonMap>, parseEpisode, key: MMRIR);
final episodes = await parseFunc(results['contents']);
if (results.containsKey('continuations')) {
Future<JsonMap> requestFunc(String additionalParams) =>
sendRequest(endpoint, body, additionalParams: additionalParams);
final remainingLimit = limit == null ? null : (limit - episodes.length);
episodes.addAll(
await getContinuations(
results,
'musicShelfContinuation',
remainingLimit,
requestFunc,
parseFunc,
),
);
}
podcast['episodes'] = episodes;
return podcast;
}