Search code examples
youtube-iframe-api

YouTube embed url with playlist parameter doesn't work except on the first load


I've encountered an issue with YouTube embed urls that have a large number of video ids in the playlist parameter. For example: https://www.youtube.com/embed/VIDEOID1?playlist=VIDEOID2,VIDEOID3,...,VIDEOID20

On the first load, it works, but if I refresh, it says "This video is unavailable". I then tried in other browsers, and on a different computer, and got the same error right away. I waited a few days and tried again, and it worked one time, and then went back to the error. Changing the videos in the list also has the same effect: for each unique list, it works once and then errors out. This only happens with a larger number of videos.

Digging into the html responses and doing a comparison between the times it works and the times it doesn't, I found that there is a PLAYER_VARS object in the JS on the page, and it contains a "list" property when it works, but that property is missing for the times the error occurs. I also found that the value of the "list" property can be used as a query string parameter to the embed url ("list" query string parameter), and that works consistently.

Is this a known bug and/or is there a way to work around it? The evidence seems to suggest some kind of server-side caching problem on the YouTube side.


Solution

  • The cause of this problem turned out to be the inclusion of a couple of videos marked private in the playlist.