I want to validate youtube url's not for regex, but for whether it has been deleted or flagged and hence not playing. It could also be the case that the youtube url is formatted correctly(passes the regex test), but has an invalid video id. Is there a way of finding this out without using youtube api's and simply by javascript(maybe xmlhttprequests?).
How to validate youtube url, if the video has been deleted or videoid is incorrect using javascript?
Asked
Active
Viewed 1,203 times
1 Answers
1
There is no way to find if video id is invalid or deleted without using Youtube API.
You can try this out:
const videoID = 'QMg39gK624';
$.ajax({
type: 'HEAD',
url: `http://gdata.youtube.com/feeds/api/videos/${videoID}`,
success: function() {
//it exists!
},
error: function(jqXhr) {
if(jqXhr.status == 400) {
//it doesn't exist
}
}
});

Michael Goldenberg
- 872
- 6
- 9
-
1There seems to be a way by checking for thumbnails of the video, https://img.youtube.com/vi/
/1.jpg, if this returns status 200, the video exists and returns 404 or any other status then the video is invalid. But I am not sure if this is the accepted way. https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api?rq=1 – Siva Bathula May 18 '20 at 12:20 -
There's a dedicated API to check this. Don't see good reason try to overpass this. – Michael Goldenberg May 18 '20 at 12:27
-
Did you solve? IS there a way to skip the removed vídeo from the list? – Guilherme Simão Couto Jul 04 '22 at 12:50