TimeForANinja / node-ytpl

Anonymous YouTube playlist resolver.
MIT License
203 stars 48 forks source link

Fix issue when playlistVideoListRenderer is not the first property #139

Closed omenocal closed 2 years ago

omenocal commented 2 years ago

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!

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.