getEpisode method
- String videoId
Retrieve episode data for a single episode.
videoId
browseId
(MPED..
) orvideoId
for a single episode.
NOTE:
- To save an episode, you need to call PlaylistsMixin.addPlaylistItems to add
it to the
SE
(saved episodes) playlist.
Returns Map containing information about the episode.
The description elements are based on a custom class, not shown in the example below.
Example:
{
"author": {
"name": "Stanford GSB Podcasts",
"id": "MPSPPLxq_lXOUlvQDUNyoBYLkN8aVt5yAwEtG9"
},
"title": "124. Making Meetings Me...",
"date": "Jan 16, 2024",
"duration": "25 min",
"saved": false,
"playlistId": "MPSPPLxq_lXOUlvQDUNyoBYLkN8aVt5yAwEtG9",
"description": [
{
"text": "Delve into why people hate meetings, ... Karin Reed ("
},
{
"text": "https://speakerdynamics.com/team/",
"url": "https://speakerdynamics.com/team/"
},
{
"text": ")Chapters:("
},
{
"text": "00:00",
"seconds": 0
},
{
"text": ") Introduction Host Matt Abrahams...("
},
{
"text": "01:30",
"seconds": 90
}
]
}
Implementation
Future<JsonMap> getEpisode(String videoId) async {
final browseId = videoId.startsWith('MPED') ? videoId : 'MPED$videoId';
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 episode = parseEpisodeHeader(header as JsonMap);
episode['description'] = null;
final descriptionRuns = nav(twoColumns, [
'secondaryContents',
...SECTION_LIST_ITEM,
...DESCRIPTION_SHELF,
'description',
'runs',
], nullIfAbsent: true);
if (descriptionRuns != null) {
episode['description'] = Description.fromRuns(
descriptionRuns as List<JsonMap>,
);
}
return episode;
}