node-ytpl icon indicating copy to clipboard operation
node-ytpl copied to clipboard

Fix issue when playlistVideoListRenderer is not the first property

Open omenocal opened this issue 3 years ago • 0 comments

I found a playlist that has a different format than others: https://www.youtube.com/playlist?list=PL2aBZuCeDwlQN4aWkYJlwjjNRr8N5Qtt1

When doing some debug I found out that common playlists have the property playlistVideoListRenderer as the first one inside this path:

parsed.json.contents
.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content
.sectionListRenderer.contents[0]
.itemSectionRenderer.contents[0]

But this playlist had not one but two values inside the itemSectionRenderer.contents field, and the first value does not contain the usual playlistVideoListRenderer but a new property called playlistShowMetadataRenderer. Please take a look at this schema-like output:

{
  "json": {
    "contents": {
      "twoColumnBrowseResultsRenderer": {
        "tabs": [
          {
            "tabRenderer": {
              "content": {
                "sectionListRenderer": {
                  "contents": [
                    {
                      "itemSectionRenderer": {
                        "contents": [
                          {
                            "playlistShowMetadataRenderer": {
                              ...
                            }
                          }
                        ],
                        ...
                      }
                    },
                    {
                      "itemSectionRenderer": {
                        "contents": [
                          {
                            "playlistVideoListRenderer": {
                              ...
                            }
                          }
                        ],
                        ...
                      }
                    }
                  ],
                  ...
                }
              },
              ...
            }
          }
        ]
      }
    },
    ...
  },
  ...
}

This PR simply loops into the itemSectionRenderer property to find the right value to move on. I added one test with this specific playlist.

Thanks in advance!

omenocal avatar Aug 31 '22 17:08 omenocal