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

feat(VideoInfo): support get by endpoint + more info #342

Merged
merged 2 commits into from
Mar 8, 2023

Conversation

patrickkfkan
Copy link
Contributor

Adds support for getting video info by endpoint in getInfo(). In addition, add playlist and autoplay to VideoInfo.

The result is that you can now obtain video info within the context of a list such as Playlist or Mix. To illustrate, consider the following endpoint for a Mix item:

// mixEndpoint:
{
  "type": "NavigationEndpoint",
  "payload": {
    "videoId": "XHedu3KcPP0",
    "playlistId": "RDXHedu3KcPP0",
    "params": "OALAAQE%3D",
    "continuePlayback": true
  },
  ...
}

// Call `getInfo()` with mixEndpoint:

const info = await youtube.getInfo(mixEndpoint);

// Now you can get not only info about the video (as referenced by id 'XHedu3KcPP0') itself, but 
// also other items in the list.

// info.playlist:
{
  "id": "RDXHedu3KcPP0",
  "title": "Mix - ...",
  "author": ...,
  "contents": [
    {
      "type": "PlaylistPanelVideo",
      ...
    }
  ]
  ...
}

info.playlist mirrors what you would see on YouTube:

image

Now, say you want to play the last item in the list and get info on that:

const lastVideo = info.playlist.contents.pop();
const newInfo = await youtube.getInfo(lastVideo.endpoint);

// `newInfo.playlist` will now have updated contents based on the `selected` video.
// In the context of a Mix, there would be new items added with some older ones removed.

In addition, you can get the Autoplay video endpoint:

const endpoint = info.autoplay_video_endpoint;

// or obtain from `info.autoplay`

This points to the next item in the list or, if there are none (end of list reached), a video as determined by YouTube autoplay logic.

Of course, you can still call getInfo() with video_id: string. Apparently, there won't be playlist info in this case.

src/Innertube.ts Outdated Show resolved Hide resolved
@LuanRT LuanRT merged commit 0d35fe0 into LuanRT:main Mar 8, 2023
@patrickkfkan patrickkfkan deleted the watch_next branch October 22, 2024 09:04
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.

3 participants