From e024375992ddc57a0f96235e8113ba7608f9ff33 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Sat, 21 Jan 2023 11:13:42 +0100 Subject: [PATCH] fix(VideoInfo): Gracefully handle missing watch next continuation --- src/parser/youtube/VideoInfo.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/parser/youtube/VideoInfo.ts b/src/parser/youtube/VideoInfo.ts index ed917aece..1eba4ce47 100644 --- a/src/parser/youtube/VideoInfo.ts +++ b/src/parser/youtube/VideoInfo.ts @@ -164,7 +164,7 @@ class VideoInfo { this.watch_next_feed = secondary_results.firstOfType(ItemSection)?.contents || secondary_results; - if (this.watch_next_feed && Array.isArray(this.watch_next_feed)) + if (this.watch_next_feed && Array.isArray(this.watch_next_feed) && this.watch_next_feed.at(-1)?.is(ContinuationItem)) this.#watch_next_continuation = this.watch_next_feed.pop()?.as(ContinuationItem); this.player_overlays = next?.player_overlays.item().as(PlayerOverlay); @@ -254,7 +254,11 @@ class VideoInfo { throw new InnertubeError('AppendContinuationItemsAction not found'); this.watch_next_feed = data?.contents; - this.#watch_next_continuation = this.watch_next_feed?.pop()?.as(ContinuationItem); + if (this.watch_next_feed?.at(-1)?.is(ContinuationItem)) { + this.#watch_next_continuation = this.watch_next_feed.pop()?.as(ContinuationItem); + } else { + this.#watch_next_continuation = undefined; + } return this; }