patrickkfkan/yt-mix-playlist

Returns null on collapsed playlist

Opened this issue · 2 comments

E.g.

https://www.youtube.com/watch?v=O4irXQhgMqg&list=RDO4irXQhgMqg&start_radio=1

I solved it by changing the getCollapsedPlaylistInfo method to this:

function getCollapsedPlaylistInfo(json) {
     let results;
     let playlistId;
 
     try {
         results = json.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results;
         const playlistResult = results.filter(
             result => result["compactPlaylistRenderer"]
         );
 
         playlistId = playlistResult[0].compactPlaylistRenderer.playlistId;
     } catch (e) {
         return null;
     }
     
     if (Array.isArray(results)) {
         for(let i = 0; i < results.length; i++) {
             let result = results[i];
             let info = result.compactVideoRenderer;
             if (info) {
                 return {
                     id: playlistId,
                     title: parseText(info.title),
                     author: parseText(info.longBylineText),
                     url: URL.resolve(BASE_URL, info.navigationEndpoint.commandMetadata.webCommandMetadata.url),
                     thumbnails: prepImg(info.thumbnail.thumbnails)
                 };
             }
         }
     }
     return null;
 }

I removed videoCount because it seems to be not available and I don't need it.

Thanks. I'll check this and update when I have time (maybe this weekend).

Getting back to this issue...

In your suggested fix, compactPlaylistRenderer actually points to a normal playlist instead of a mix playlist. Even if it is curated by YouTube,a normal playlist has a finite number of videos. A mix playlist, on the other hand, is basically neverending.

The correct element for a mix playlist is still compactRadioRenderer. I did find that the element is sometimes missing from the initial set of items shown in the right-hand column of the site. You would have to scroll down to load more items before you reach the mix playlist. I have therefore applied this logic in the code (v0.1.2-b). You can verify this with the video ID you gave in your post (O4irXQhgMqg). The library should now return the mix playlist correctly.