如果视频是 "unavailable",是否有跳过播放列表中的 YouTube 视频的修复方法
Is there a fix for skipping a YouTube video in a playlist, if video is "unavailable"
我在 HTML 5 媒体播放器播放列表中有一个 YouTube 视频的汇总列表(从 mySql db 查询)。但随着时间的推移,YouTube 会因为版权或判断问题禁用某些视频,但 link 仍然在我的列表中。任何人都可以推荐一个 JS 或其他解决方案或文章,看看视频 link 是否没有在 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 服务器上正常工作(它们总是 return 某些页面内容,即使视频本身已被删除)。
下面的可测试示例代码:
(将回显“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)"; }
?>
我在 HTML 5 媒体播放器播放列表中有一个 YouTube 视频的汇总列表(从 mySql db 查询)。但随着时间的推移,YouTube 会因为版权或判断问题禁用某些视频,但 link 仍然在我的列表中。任何人都可以推荐一个 JS 或其他解决方案或文章,看看视频 link 是否没有在 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 服务器上正常工作(它们总是 return 某些页面内容,即使视频本身已被删除)。
下面的可测试示例代码:
(将回显“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)"; }
?>