Skip to content

Commit

Permalink
fix(VideoInfo): Gracefully handle missing watch next continuation (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Jan 23, 2023
1 parent 8051a7d commit 13ad377
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/parser/youtube/VideoInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 13ad377

Please sign in to comment.