Skip to content

Commit

Permalink
fix episode top results crashing search
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Nov 3, 2023
1 parent 64547a0 commit 49d2e61
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions parsers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,14 @@ export function parse_search_content(
result: any,
upload = false,
passed_entity?: string,
): SearchContent {
): SearchContent | null {
const flex1 = get_flex_column_item(result, 1);

// uploads artist won't have the second flex column
const entity = passed_entity ||
(flex1 ? __(j(flex1, TEXT_RUN_TEXT)) : "artist");

let parser: (e: any, has_label?: boolean) => SearchContent;
let parser: (e: any, has_label?: boolean) => SearchContent | null;

switch (entity) {
case "station":
Expand Down Expand Up @@ -381,7 +381,11 @@ export function parse_search_content(
try {
return parse_search_album(e);
} catch {
return parse_search_song(e);
try {
return parse_search_song(e);
} catch {
return null;
}
}
};
}
Expand All @@ -396,7 +400,7 @@ export function parse_search_results(
) {
const search_results: SearchContent[] = [];

let parser: (e: any) => SearchContent;
let parser: (e: any) => SearchContent | null;

if (scope == null || scope == "library") {
switch (filter) {
Expand Down Expand Up @@ -430,10 +434,10 @@ export function parse_search_results(
for (const result of results) {
const data = result[MRLIR];

search_results.push(parser(data));
search_results.push(parser(data)!);
}

return search_results;
return search_results.filter((e) => !!e);
}

export function parse_top_result_more(result: any) {
Expand All @@ -455,25 +459,25 @@ export function parse_top_result_more(result: any) {
const entity = flex1 ? __(jo(flex1, TEXT_RUN_TEXT)) as string : null;

if (entity) {
more.push(parse_search_content(content, false));
more.push(parse_search_content(content, false)!);

last_entity = entity;
} else {
try {
more.push(
parse_search_content(content, false, last_entity ?? undefined),
parse_search_content(content, false, last_entity ?? undefined)!,
);
} catch {
// try as album
try {
more.push(
parse_search_content(content, false, "album"),
parse_search_content(content, false, "album")!,
);
} catch {
// try as song
try {
more.push(
parse_search_content(content, false, "song"),
parse_search_content(content, false, "song")!,
);
} catch {
// ignore
Expand All @@ -485,7 +489,7 @@ export function parse_top_result_more(result: any) {
}
}

return more;
return more.filter((e) => !!e);
}

export interface TopResultArtist extends SearchArtist {
Expand Down

0 comments on commit 49d2e61

Please sign in to comment.