How can I tell if a YouTube video is being embedded before I try to download it?

I have a chromeless YouTube player that I'm trying to upload videos to, but only some videos work - not all. If I'm not mistaken, the ones that don't download are related to copyright infringement (for example, some cartoon episode won't download, but a home movie about a kid doing a backflip). What I'm trying to do is either find out if these videos will download, after we try to download them, or sooner.

As an example, here are two Nataly Dawn videos. One is loading, the other is not.

// loads and plays the video

// doesn't load/play the video


From looking at the data as a working video and a non-working video , I can't see anything to indicate that the latter is not being embedded. [I'm looking for tags <yt:accessControl>

or missing yt:format='5'

(cf. How do I use the Youtube API to test video embedding? ) But to no avail.]

From what I've tried in the console, it loadVideoById

always returns undefined

, regardless of whether the video is actually loaded. I cannot find an API method to determine if the video did it.


source to share

2 answers

Both videos you mentioned seem to be downloadable and playable to me. For example use: playground for google codes and embed your videos in HTML option tags.

Here are some tips.

  • Use the v = 2 parameter in the gdata request to use the current YT data API.
  • This blog post lists some additional restrictions you might need to determine if a video is playable or embeddable .
  • Some videos may be embedded but not playable. In this case, the only thing you can do is use the JavaScript PlayerAPI to search for the event stateChange

    that says it is playing, and then use it setInterval

    to poll the video through getCurrentTime

    to find out the actual entertainment. This is a bit crazy for most applications.


Currently you can hook up the onError built-in api event and check for error codes 101 and 150 (they are the same) which determine that the video was blocked from the built-in game. Moreover, it will allow you to act differently in case of other errors (bad query, html 5 questions, etc.).

function onError(event){
        case 2:
            console.log('request contains an invalid parameter value')
        case 5:
            console.log('The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred.')
        case 100:
            console.log('The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private.')
        case 101:
        case 150:
            console.log('Uploader has blocked this content from embedded playback')
            console.log('error code: '



If you want the embedded video results to be returned by the search api, include videoEmbeddable:"true"

in your query



All Articles