我有“ Youtube”视频链接。
那么如何使用视频ID或'Youtube'视频链接使用'Youtube api'或'Youtube iframe api'直播或上传此视频?
答案 0 :(得分:0)
您可以为此使用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
}
答案 1 :(得分:0)
<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");
}
});
这是我使用视频时长检查直播或不直播的解决方案