Skip to content
2 changes: 1 addition & 1 deletion src/mixins/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export async function get_playlist(
thumbnails: j(header, THUMBNAILS),
description: jo(header, "description", DESCRIPTION_SHELF, DESCRIPTION),
type: run_count > 0 ? j(header, SUBTITLE) : null,
authors: parse_song_artists_runs(header.straplineTextOne.runs),
authors: parse_song_artists_runs(header.straplineTextOne?.runs),
year: j(header, "subtitle.runs", (run_count - 1).toString(), "text"),
trackCount: secondRuns ? secondRuns[0].text : null,
duration: secondRuns && secondRuns.length > 2 ? secondRuns[2].text : null,
Expand Down
20 changes: 8 additions & 12 deletions src/parsers/songs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,22 @@ export interface ArtistRun {
}

export function parse_song_artists_runs(runs: any) {
if (!runs || !Array.isArray(runs)) {
return [];
}
const artists: ArtistRun[] = [];
const result = Array(Math.floor(runs.length / 2) + 1).fill(undefined).map((
_,
index,
) => index);

for (const i of result) {
const run = runs[i * 2];

if (run == null) continue;

// Iterate through every other element in 'runs' because each artist entry is located at even indices.
for (let i = 0; i < runs.length; i += 2) {
const run = runs[i];
if (run === null || run === undefined)
continue;
const page_type = jo(run, NAVIGATION_PAGE_TYPE);

artists.push({
name: run.text,
id: jo(run, NAVIGATION_BROWSE_ID),
type: page_type === "MUSIC_PAGE_TYPE_ARTIST" ? "artist" : "channel",
});
}

return artists;
}

Expand Down