From 713fd13c74449e00b4f85582a8ffbf8a28a0a421 Mon Sep 17 00:00:00 2001 From: Patrick Kan <55383971+patrickkfkan@users.noreply.github.com> Date: Sun, 14 Aug 2022 06:46:55 +0800 Subject: [PATCH] fix(music#Library): sort_by err when items <= 1 (#137) --- src/parser/ytmusic/Library.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/parser/ytmusic/Library.ts b/src/parser/ytmusic/Library.ts index 28c60104..473695b3 100644 --- a/src/parser/ytmusic/Library.ts +++ b/src/parser/ytmusic/Library.ts @@ -124,6 +124,9 @@ class Library { if (shuffle) { if (!shuffle_endpoint) { + if (data.items.length <= 1) { + return data; + } throw new InnertubeError('Unable to obtain endpoint for sort_by value \'random\''); } return this.#fetchAndParseShuffledSongs(shuffle_endpoint); @@ -172,6 +175,9 @@ class Library { (item) => item.as(DropdownItem).label === SORT_BY_TEXTS[sort_by])?.as(DropdownItem); if (!dropdownItem?.endpoint?.browse) { + if (data.items.length <= 1) { + return data; + } throw new InnertubeError(`Unable to obtain browse endpoint for sort_by value '${sort_by}'`); }