YouTube.js icon indicating copy to clipboard operation
YouTube.js copied to clipboard

10.0.0 [YOUTUBEJS][Parser]: InnertubeError: Something went wrong at ContentMetadataView!

Open iBicha opened this issue 1 year ago • 3 comments

Steps to reproduce

Happens when trying to read playlists (I'll dig into this further when I have some time)

This is from yt2alt, usage looks like this

    async getPlaylistWithVideos(playlistId, limit = PLAYLIST_LIMIT) {
        await this.createSession();

        let playlist = await this.innertube.getPlaylist(playlistId);

        const videos = await this.getFeedVideosWithLimit(playlist, limit);

        return this.toPlaylistWithVideos(playlist, videos);
    }

    async getFeedVideosWithLimit(feed, limit = PLAYLIST_LIMIT) {
        const videos = [];
        while (limit === -1 || videos.length < limit) {
            try {
                videos.push(...feed.videos);
                if (!feed.has_continuation) {
                    break;
                }
                feed = await feed.getContinuation();
            } catch (error) {
                console.error(error);
                break;
            }
        }

        return videos.slice(0, limit)
            .map(video => this.toVideo(video));
    }

Failure Logs

[YOUTUBEJS][Parser]: InnertubeError: Something went wrong at ContentMetadataView!
This is a bug, please report it at https://github.com/LuanRT/YouTube.js/issues
    at ERROR_HANDLER (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/parser.js:48:31)
    at Module.parseItem (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/parser.js:393:13)
    at new PageHeaderView (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/classes/PageHeaderView.js:16:32)
    at Module.parseItem (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/parser.js:388:28)
    at new PageHeader (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/classes/PageHeader.js:8:31)
    at parseItem (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/parser.js:388:28)
    at parse (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/parser.js:437:34)
    at Module.parseResponse (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/parser.js:194:34)
    at new Feed (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/core/mixins/Feed.js:39:61)
    at new Playlist (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/youtube/Playlist.js:22:9) {
  info: {
    stack: "TypeError: Cannot destructure property 'content' of 'data' as it is undefined.\n" +
      '    at Text.fromAttributed (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/classes/misc/Text.js:42:17)\n' +
      '    at file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/classes/ContentMetadataView.js:10:32\n' +
      '    at Array.map (<anonymous>)\n' +
      '    at file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/classes/ContentMetadataView.js:9:98\n' +
      '    at Array.map (<anonymous>)\n' +
      '    at new ContentMetadataView (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/classes/ContentMetadataView.js:6:48)\n' +
      '    at Module.parseItem (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/parser.js:388:28)\n' +
      '    at new PageHeaderView (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/classes/PageHeaderView.js:16:32)\n' +
      '    at Module.parseItem (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/parser.js:388:28)\n' +
      '    at new PageHeader (file:///Users/brahim/Roku/yt2alt/node_modules/youtubei.js/dist/src/parser/classes/PageHeader.js:8:31)'
  },
  date: 2024-06-16T16:18:45.549Z,
  version: '10.0.0'
}

Expected behavior

Reads videos from playlists

Current behavior

Error printed, but still successfully reads videos (or at least the ids are there)

Version

Default

Anything else?

No response

Checklist

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

iBicha avatar Jun 16 '24 16:06 iBicha

So when reading this playlist I have, the issue is with the parsing of ContentMetadataView.

Parsing assumes that a ContentMetadataView contains rows, and each row contains parts, and each part is a text. But in my case I see that a part can be of type AvatarStack, which seems to be a list of avatars (I assume this is because maybe it is possible, or it will become possible, to collaborate on creating a playlist by multiple people maybe?)

Here's the json of this ContentMetadataView causing the bug

{
  "metadataRows": [
    {
      "metadataParts": [
        {
          "avatarStack": {
            "avatarStackViewModel": {
              "avatars": [
                {
                  "avatarViewModel": {
                    "image": {
                      "sources": [
                        {
                          "url": "https://yt3.ggpht.com/ytc/redacted",
                          "width": 48,
                          "height": 48
                        }
                      ],
                      "processor": {
                        "borderImageProcessor": {
                          "circular": true
                        }
                      }
                    },
                    "avatarImageSize": "AVATAR_SIZE_XS"
                  }
                }
              ],
              "text": {
                "content": "redacted",
                "commandRuns": [
                  {
                    "startIndex": 0,
                    "length": 15,
                    "onTap": {
                      "innertubeCommand": {
                        "clickTrackingParams": "redacted",
                        "commandMetadata": {
                          "webCommandMetadata": {
                            "url": "/@BrahimHadriche",
                            "webPageType": "WEB_PAGE_TYPE_CHANNEL",
                            "rootVe": 3611,
                            "apiUrl": "/youtubei/v1/browse"
                          }
                        },
                        "browseEndpoint": {
                          "browseId": "redacted",
                          "canonicalBaseUrl": "redacted"
                        }
                      }
                    }
                  }
                ],
                "styleRuns": [
                  {
                    "startIndex": 0,
                    "length": 15,
                    "weightLabel": "FONT_WEIGHT_NORMAL",
                    "styleRunExtensions": {
                      "styleRunColorMapExtension": {
                        "colorMap": [
                          {
                            "key": "USER_INTERFACE_THEME_LIGHT",
                            "value": 4294967295
                          },
                          {
                            "key": "USER_INTERFACE_THEME_DARK",
                            "value": 4294967295
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    },
    {
      "metadataParts": [
        {
          "text": {
            "content": "9 videos"
          }
        },
        {
          "text": {
            "content": "Public"
          }
        }
      ]
    }
  ]
} 

iBicha avatar Jun 16 '24 20:06 iBicha

Until now YouTube has only used that node on the channel page, hence the current handling. Sounds like they are switching to that on the playlist page too then.

Thank you for providing the snippet that causes the problem, that will make it easier to add support for it.

absidue avatar Jun 16 '24 21:06 absidue

I got the same error when running my playlist organizer tool. The JSON of ContentMetadataView looks a little different, so I'll paste mine as well.

{
  "metadataRows": [
    {
      "metadataParts": [
        {
          "avatarStack": {
            "avatarStackViewModel": {
              "avatars": [
                {
                  "avatarViewModel": {
                    "image": {
                      "sources": [
                        {
                          "url": "<url-redacted>",
                          "width": 48,
                          "height": 48
                        }
                      ],
                      "processor": {
                        "borderImageProcessor": {
                          "circular": true
                        }
                      }
                    },
                    "avatarImageSize": "AVATAR_SIZE_XS"
                  }
                }
              ],
              "text": {
                "content": "<test-redacted>",
                "commandRuns": [
                  {
                    "startIndex": 0,
                    "length": 14,
                    "onTap": {
                      "innertubeCommand": {
                        "clickTrackingParams": "redacted",
                        "commandMetadata": {
                          "webCommandMetadata": {
                            "url": "/@redacted",
                            "webPageType": "WEB_PAGE_TYPE_CHANNEL",
                            "rootVe": 3611,
                            "apiUrl": "/youtubei/v1/browse"
                          }
                        },
                        "browseEndpoint": {
                          "browseId": "redacted",
                          "canonicalBaseUrl": "/@redacted"
                        }
                      }
                    }
                  }
                ],
                "styleRuns": [
                  {
                    "startIndex": 0,
                    "length": 14,
                    "fontColor": 4294967295,
                    "weightLabel": "FONT_WEIGHT_NORMAL"
                  }
                ]
              },
              "rendererContext": {
                "loggingContext": {
                  "loggingDirectives": {
                    "trackingParams": "redacted",
                    "visibility": {
                      "types": "12"
                    },
                    "clientVeSpec": {
                      "uiType": 184971,
                      "veCounter": 610901681
                    }
                  }
                },
                "accessibilityContext": {
                  "label": "redacted"
                },
                "commandContext": {
                  "onTap": {
                    "innertubeCommand": {
                      "clickTrackingParams": "redacted",
                      "commandMetadata": {
                        "webCommandMetadata": {
                          "url": "/@redacted",
                          "webPageType": "WEB_PAGE_TYPE_CHANNEL",
                          "rootVe": 3611,
                          "apiUrl": "/youtubei/v1/browse"
                        }
                      },
                      "browseEndpoint": {
                        "browseId": "redacted",
                        "canonicalBaseUrl": "/@redacted"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      ]
    },
    {
      "metadataParts": [
        {
          "text": {
            "content": "Playlist"
          }
        },
        {
          "text": {
            "content": "Public"
          }
        },
        {
          "text": {
            "content": "260 videos"
          }
        },
        {
          "text": {
            "content": "4,628,354 views"
          }
        }
      ]
    }
  ],
  "delimiter": "•",
  "rendererContext": {
    "loggingContext": {
      "loggingDirectives": {
        "trackingParams": "redacted",
        "visibility": {
          "types": "12"
        },
        "clientVeSpec": {
          "uiType": 176757,
          "veCounter": 610901680
        }
      }
    }
  }
}

wogikaze avatar Oct 16 '24 07:10 wogikaze