Skip to content

Commit afe0ec8

Browse files
authored
Merge pull request #20 from nico-iaco/main
2 parents d489370 + 137f442 commit afe0ec8

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

src/mixins/playlist.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export async function get_playlist(
179179
thumbnails: j(header, THUMBNAILS),
180180
description: jo(header, "description", DESCRIPTION_SHELF, DESCRIPTION),
181181
type: run_count > 0 ? j(header, SUBTITLE) : null,
182-
authors: parse_song_artists_runs(header.straplineTextOne.runs),
182+
authors: parse_song_artists_runs(header.straplineTextOne?.runs),
183183
year: j(header, "subtitle.runs", (run_count - 1).toString(), "text"),
184184
trackCount: secondRuns ? secondRuns[0].text : null,
185185
duration: secondRuns && secondRuns.length > 2 ? secondRuns[2].text : null,

src/parsers/songs.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,22 @@ export interface ArtistRun {
116116
}
117117

118118
export function parse_song_artists_runs(runs: any) {
119+
if (!runs || !Array.isArray(runs)) {
120+
return [];
121+
}
119122
const artists: ArtistRun[] = [];
120-
const result = Array(Math.floor(runs.length / 2) + 1).fill(undefined).map((
121-
_,
122-
index,
123-
) => index);
124-
125-
for (const i of result) {
126-
const run = runs[i * 2];
127-
128-
if (run == null) continue;
129-
123+
// Iterate through every other element in 'runs' because each artist entry is located at even indices.
124+
for (let i = 0; i < runs.length; i += 2) {
125+
const run = runs[i];
126+
if (run === null || run === undefined)
127+
continue;
130128
const page_type = jo(run, NAVIGATION_PAGE_TYPE);
131-
132129
artists.push({
133130
name: run.text,
134131
id: jo(run, NAVIGATION_BROWSE_ID),
135132
type: page_type === "MUSIC_PAGE_TYPE_ARTIST" ? "artist" : "channel",
136133
});
137134
}
138-
139135
return artists;
140136
}
141137

0 commit comments

Comments
 (0)