diff --git a/src/mixins/playlist.ts b/src/mixins/playlist.ts index 447045a..6e87dec 100644 --- a/src/mixins/playlist.ts +++ b/src/mixins/playlist.ts @@ -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, diff --git a/src/parsers/songs.ts b/src/parsers/songs.ts index 82ac526..107e248 100644 --- a/src/parsers/songs.ts +++ b/src/parsers/songs.ts @@ -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; }