gpt4 book ai didi

video - 如果视频是 “unavailable”,是否有修复程序可跳过播放列表中的YouTube视频

转载 作者:行者123 更新时间:2023-12-03 05:30:45 26 4
gpt4 key购买 nike

我在HTML 5媒体播放器播放列表中有YouTube视频的汇总列表(从mySql数据库查询)。但是随着时间的流逝,由于版权或判断问题,YouTube将禁用某些视频,但是这些链接仍在我的列表中。任何人都可以推荐JS或其他解决方案或文章,以查看视频链接是否在x时间内开始启动跳过或下一步操作。请指教。

没有解决方案,因为广泛的谷歌搜索没有建议。

我的基本逻辑是,如果x秒钟后视频无法播放,则跳过,否则播放。

// THIS ACTUALLY CHECKS PLAYTIME AND ADD TO A COUNTER - CAN I USE SOMETHING SIMILAR?

var counter = 0;
var currentIndex_inc = 0;
function onProgress() {

if(player.currentTime() <= 1){
counter = 0;
}

//-- ------------------------------------- -->
// ----- COUNTER - If track plays longer than 30 seconds - add 1 --------
//-- ------------------------------------- -->
if(player.currentTime() >= 30 && trackURL != ''){
if(counter==0){
counter = 1;
var playlist_name = "<?php echo $playlist ; ?>";
var play_type = "<?php echo $type ; ?>";
var trackURL = player.currentSrc();
track_source = trackURL.src ;

if(typeof(track_source)==="undefined"){
track_source = trackURL;
};

$.ajax({
type: "POST",
url: "_inc/2018_process_counter.php",
dataType: "text",
data: {
playlist_name: playlist_name,track_source:track_source }
}).done(function( data ) {
});
}
return false;
}

Logic:
If (video link does not start || video link == live){
skip
} else if (video link does start || video link == dead) {
play
}

使用Queru列出代码-基于成功的答复。答案仅适用于单个ID,而不适用于列表...请参见下面的代码:
if ($result_a->num_rows > 0) {
// output data of each row
while($row = $result_a->fetch_assoc()) {
$id = $row['id'];
$share_key = $row['share_key'];
echo $row['id'];
echo '<br>';
echo $row['artist'];
echo '<br>';
echo $row['title'];
echo '<br>';
echo $row['source_url'];
echo '<br>';
$my_link = $row['source_url'];

$testlink = substr($my_link, strrpos($my_link, '/' )+1)."\n";

echo '<p style="color:#ff0000">';
echo $testlink;
echo '</p>';

//# is ERROR = https://www.youtube.com/watch?v=R5mpcDWpYSA
// $url = "https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=R5mpcDWpYSA"; //# test video deleted.

//# is OK = https://www.youtube.com/watch?v=mLuh_O4mYbA
$url = "https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=".$testlink; //# test working (not deleted).
echo $url;
echo '<br>';
try
{
set_error_handler(function() { /* # temp ignore Warnings/Errors */ });

$fop = fopen($url, "rb");
if ( !$fop && $fop==false) { throw new Exception(); }

restore_error_handler(); //# restore Warnings/Errors

echo "OK 200 ::: Youtube video was found";
}
catch ( Exception $e )
{ echo "Error 404 ::: Youtube video not found (deleted or bad link)"; }




echo '<hr>';









}
} else {
// echo "0 results";
}

最佳答案

"...YouTube will disable certain videos due to copyright or judgement issues, but the links are still in my list. Can anyone recommend a JS or other solution or article that sees if the video link does not start in x amount of time to initiate a skip or next action. Please advise."



由于您已经在使用PHP代码,因此以下步骤是一种可能的选择:

1)向 https://www.youtube.com/oembed? + Youtube video URL发出请求。

请求示例:
https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=R5mpcDWpYSA

2)使用 fopen检查视频可用性。请注意, file_exists($url)在Youtube服务器上无法正常使用(即使视频本身已被删除,它们也总是返回某些页面内容)。

以下是可测试的示例代码:
(将根据视频状态回显“ OK 200”或“ ERROR 404”)
<?php

//# is ERROR = https://www.youtube.com/watch?v=R5mpcDWpYSA
$url = "https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=R5mpcDWpYSA"; //# test video deleted.

//# is OK = https://www.youtube.com/watch?v=mLuh_O4mYbA
//$url = "https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=mLuh_O4mYbA"; //# test working (not deleted).

try
{
set_error_handler(function() { /* # temp ignore Warnings/Errors */ });

$fop = fopen($url, "rb");
if ( !$fop && $fop==false) { throw new Exception(); }

restore_error_handler(); //# restore Warnings/Errors

echo "OK 200 ::: Youtube video was found";
}
catch ( Exception $e )
{ echo "Error 404 ::: Youtube video not found (deleted or bad link)"; }

?>

选项2:

您还可以通过将 file_get_contents与对Youtube的 get_video_info?的请求一起使用来获得相同的结果。

请求示例:
https://www.youtube.com/get_video_info?video_id=R5mpcDWpYSA

示例代码:
<?php

//# ERROR = https://www.youtube.com/watch?v=R5mpcDWpYSA
$url = "https://www.youtube.com/get_video_info?video_id=R5mpcDWpYSA"; //# test video deleted.

//# OK = https://www.youtube.com/watch?v=mLuh_O4mYbA
//$url = "https://www.youtube.com/get_video_info?video_id=mLuh_O4mYbA"; //# test working (not deleted).

$src = file_get_contents($url);

//# find text... playabilityStatus%22%3A%7B%22status%22%3A%22OK ...
$str1 = "playabilityStatus%22%3A%7B%22status%22%3A%22";
$pos = strpos($src, $str1);

$result = substr( $src, $pos + (strlen($str1)), 5);

if( $result{0} == "O" && $result{1} == "K" )
{ echo "OK 200 ::: Youtube video was found"; }
else
{ echo "Error 404 ::: Youtube video not found (deleted or bad link)"; }

?>

关于video - 如果视频是 “unavailable”,是否有修复程序可跳过播放列表中的YouTube视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56975082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com