如何在YouTube中检查视频是实时的还是使用YouTube iframe API上传的



我有'Youtube'视频链接。

那么,如何使用视频ID或"Youtube"视频链接使用"Youtube api"或"Youtube iframe api"直播或上传此视频?

<script>
$.getJSON('https://www.googleapis.com/youtube/v3/videos?id=F5xx0NDcO7s&part=contentDetails&key={api key}', function(data) {
var data1 = data["items"][0]["contentDetails"]["duration"];
var data2 = data1.substring(2);
var data3 = data2.substring(0, data2.length - 1);
console.log(data3);
if (data3.includes('M')) {
var array = data3.split("M");
if (array[0].includes('H')) {
var hours = array[0].split("H").map(Number);
console.log(array);
var second = hours[0] * 60 * 60 + hours[1] * 60 + array[1];
} else {
var second = array[0] * 60 + array[1];
}
} else {
var second = data3;
}
if (second == 0) {
console.log("video is live or not uploded");
} else {
console.log("video uploded");
}
});

这是我检查实时或不使用视频持续时间的解决方案

您可以使用Youtube oEmbed 格式。这是一个简单的函数

function yt_exists($videoID) {
$theURL = "http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=".$videoID."&format=json";
$headers = get_headers($theURL);
return (substr($headers[0], 9, 3) !== "404");
}
$id = 'yyDUC1LUXSU'; //Video ID
if (yt_exists($id)) {
//  Video is working and uploaded
} else {
//  Video is not uploaded or live
}

最新更新