How do I check if a video exists on YouTube, using PHP?
http://www.youtube.com/watch?v=bQVoAWSP7k4 http://www.youtube.com/watch?v=bQVoAWSP7k4&feature=popular http://www.youtube.com/watch?v=McNqjYiFmyQ&feature=related&bhablah http://youtube.com/watch?v=bQVoAWSP7k4
var matches = $('#videoUrl').val().match(/http:\/\/(?:www\.)?youtube.*watch\?v=([a-zA-Z0-9\-_]+)/);
if (matches) {
alert('valid');
} else {
alert('Invalid');
}
You should request to this URL
https://www.googleapis.com/youtube/v3/videos?id={the_id_of_the_video}&key={your_api_key}&part=status
After that, you will receive the response json that contains uploadStatus
field
{
etag = "\"I_8xdZu766_FSaexEaDXTIfEWc0/8QgL7Pcv5G8OwpNyKYJa8PaQTc0\"";
items = (
{
...
status = {
embeddable = 1;
license = youtube;
privacyStatus = public;
publicStatsViewable = 1;
uploadStatus = processed;
};
}
);
...
}
And there are 5 possible value for uploadStatus
deleted, failed, processed, rejected, uploaded
For uploadStatus
= processed
or uploaded
=> your youtube video is available