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
19 changes: 7 additions & 12 deletions src/parsers/songs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,22 @@ export interface ArtistRun {
type: "artist" | "channel";
}

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

export function parse_song_artists_runs(runs) {
Comment thread
nico-iaco marked this conversation as resolved.
Outdated
if (!runs)
return [];
Comment thread
nico-iaco marked this conversation as resolved.
Outdated
const artists = [];

Copilot AI Jul 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding explicit TypeScript annotations for the runs parameter (e.g., runs?: any[]) and the function return type (: ArtistRun[]) to improve type safety and clarity.

Suggested change
export function parse_song_artists_runs(runs) {
if (!runs)
return [];
const artists = [];
export function parse_song_artists_runs(runs: { text: string }[] | undefined): ArtistRun[] {
if (!runs)
return [];
const artists: ArtistRun[] = [];

Copilot uses AI. Check for mistakes.
Comment thread
nico-iaco marked this conversation as resolved.
Outdated
const result = Array(Math.floor(runs.length / 2) + 1).fill(undefined).map((_, index) => index);
for (const i of result) {
const run = runs[i * 2];

Copilot AI Jul 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating an intermediate array with fill and map, consider iterating directly over runs using for (let i = 0; i < runs.length; i += 2) to reduce memory allocations.

Suggested change
const result = Array(Math.floor(runs.length / 2) + 1).fill(undefined).map((_, index) => index);
for (const i of result) {
const run = runs[i * 2];
for (let i = 0; i < runs.length; i += 2) {
const run = runs[i];

Copilot uses AI. Check for mistakes.
Comment thread
nico-iaco marked this conversation as resolved.
Outdated

if (run == null) continue;

if (run == null)
Comment thread
nico-iaco marked this conversation as resolved.
Outdated
continue;
Comment thread
nico-iaco marked this conversation as resolved.
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