Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Know if a video Youtube is unavailable with the API

Tags:

youtube-api

Via the Youtube API, how can I detect if a video Youtube is unavailable (ex : https://www.youtube.com/watch?v=5nRZlcB2jPY) ?

Thanks

like image 529
Yohann Avatar asked Sep 09 '15 12:09

Yohann


People also ask

How do you know if a YouTube video is available?

The only thing you have to do is to paste the ID of any YouTube-video in the input field under the empty iframe below and then click on 'Check'. You'll instantly know whether or not the video is available for embedding.

What is an unavailable video on YouTube?

If you consistently can't get a video to play, it's probably a problem with JavaScript or Flash, technologies that YouTube uses to make its site work. If you have JavaScript disabled, you won't be able to watch any YouTube videos. To see videos, go into your browser settings and allow JavaScript to run on YouTube.


2 Answers

This is also partially possible without API. Let's say you want to see if the following video is available:

https://www.youtube.com/watch?v=esDJPiGu5x0

The ID of the video is shown as the GET parameter v. Use this one to request the following thumbnail:

https://img.youtube.com/vi/esDJPiGu5x0/0.jpg

If the content of the response has a length of 0 and/or the http response code by youtube.com is 404, then the video is not available anymore.

like image 87
Marc Ruef Avatar answered Nov 08 '22 23:11

Marc Ruef


You would make an API call for the video status.

https://www.googleapis.com/youtube/v3/videos?id=VIDEOID&part=status&key=APIKEY

Then check the uploadStatus in the json result:

"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
}
like image 25
johnh10 Avatar answered Nov 09 '22 01:11

johnh10