Skip to content

16.0.1 Bug: ChannelSubMenu parser fails due to changes in InnerTube response structure #1140

@Elian-Al

Description

@Elian-Al

Steps to reproduce

  1. Initialize a YouTube.js instance using account cookies.
  2. Get a channel: const channel = await yt.getChannel('CHANNEL_ID');
  3. Attempt to fetch playlists: const playlists = await channel.getPlaylists();
  4. The parser will encounter a ChannelSubMenu node and fail because it looks for contentTypeSubMenuItems at the root of the data object.

Failure Logs

InnertubeError: Something went wrong at ChannelSubMenu!
TypeError: Cannot read properties of undefined (reading 'map')
    at new ChannelSubMenu (file:///C:/Users/.../node_modules/youtubei.js/dist/src/parser/classes/ChannelSubMenu.js:10:73)
    at Module.parseItem (file:///C:/Users/.../node_modules/youtubei.js/dist/src/parser/parser.js:423:28)

Expected behavior

The getPlaylists() method should return the playlists without crashing. The ChannelSubMenu class should correctly map the sub-menu items even if they are nested within sortSetting.

Current behavior

The library throws an InnertubeError because YouTube has changed the JSON structure. The items previously found in data.contentTypeSubMenuItems are now located in data.sortSetting.sortFilterSubMenuRenderer.subMenuItems.

Version

Default

Anything else?

I found a fix by updating src/parser/classes/ChannelSubMenu.js. It seems the data structure has changed. Here is the logic I used to fix it:
Replace data.contentTypeSubMenuItems by data.sortSetting.sortFilterSubMenuRenderer.subMenuItems

ChannelSubMenu.js

Checklist

  • I am running the latest version.
  • I checked the documentation and found no answer.
  • I have searched the existing issues and made sure this is not a duplicate.
  • I have provided sufficient information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions