Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Playlist): trying to parse an already parsed response #286

Merged
merged 1 commit into from
Jan 10, 2023

Conversation

LuanRT
Copy link
Owner

@LuanRT LuanRT commented Jan 10, 2023

Description

I saw this issue in FreeTubeApp/FreeTube#3046 and figured I'd take a crack at it. It would seem that InnerTube has some trouble loading the last videos of long playlists (perhaps because they can only load in batches of 100 videos and never less than that?).

Since the library never expects on_load_received_actions to be undefined when doing pagination, it thinks the response is not parsed and tries to parse it, inevitably ending up in a InnertubeError: Type not found! which is then followed by InnertubeError: This playlist does not exist when retrieving the last page of a long playlist. It says “Type not found” because it's trying to run Parser#parseResponse on the parsed data all over again. To fix this, I explicitly set already_parsed to true in Playlist#getContinuation() and added a messages prop to Playlist (which in this case obviously returns Unavailable videos are hidden and No videos in this playlist yet when YouTube can't return more playlist items).

Code I used to test this:

let playlist = await yt.getPlaylist('PLcyItF5YjT0dYq2E7Oti1pgBsRNq3A3jW');

let i = 0;

while (true) {
  try {
    console.info(i++);
    playlist = await playlist.getContinuation();
  } catch (e) {
    console.log(e); // after the fix this should return a normal “There are no continuations” error
    console.log(playlist.has_continuation) // false
    console.log(playlist.messages);
    break;
  }
}

Output:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
InnertubeError: There are no continuations
 at Playlist.<anonymous> (..)
 at Generator.next (<anonymous>)
  ....

Note that 100 * 18 = 1800 which is roughly the size of the playlist used.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

This resulted in a 'InnertubeError: Type not found!' which was then followed by 'InnertubeError: This playlist does not exist' when retrieving the last page of a long playlist.
@LuanRT LuanRT marked this pull request as ready for review January 10, 2023 20:15
@LuanRT LuanRT merged commit e8af2a6 into main Jan 10, 2023
@LuanRT LuanRT deleted the fix/long-yt-playlist-pagination branch January 10, 2023 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant