Via the Youtube API, how can I detect if a video Youtube is unavailable (ex : https://www.youtube.com/watch?v=5nRZlcB2jPY) ?
Thanks
Via the Youtube API, how can I detect if a video Youtube is unavailable (ex : https://www.youtube.com/watch?v=5nRZlcB2jPY) ?
Thanks
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
}
"status": { "uploadStatus": "processed", "privacyStatus": "public", "license": "youtube", "embeddable": true, "publicStatsViewable": true }
. What should be the correct status for an available video ? –
Sedgewake This is also partially possible without API. Let's say you want to see if the following video is available:
The ID of the video is shown as the GET parameter v
. Use this one to request the following thumbnail:
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.
You can check it without API.
const https = require('https');
// Change your videoId that you want to check here
const url = 'https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=videoID&format=json';
https.get(url, (response) => {
if (response.statusCode === 200) {
console.log('Video available');
} else {
console.log('Video not available');
}
}).on('error', (error) => {
console.error('Error:', error);
});
If you get a response of 200, the video is available. If not, the video is unavailable
© 2022 - 2024 — McMap. All rights reserved.