如何检查 youtube 中的视频是实时的还是使用 youtube iframe 上传的 api
how to check video in youtube is live or uploaded using youtube iframe api
我有 'Youtube' 个视频 link。
那么如何使用 'Youtube api' 或 'Youtube iframe api' 使用视频 ID 或 'Youtube' 视频 link 来直播或上传此视频?
您可以为此使用 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
}
<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' 个视频 link。
那么如何使用 'Youtube api' 或 'Youtube iframe api' 使用视频 ID 或 'Youtube' 视频 link 来直播或上传此视频?
您可以为此使用 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
}
<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");
}
});
这是我使用视频时长检查直播与否的解决方案