我有一个文件,我使用一个名为MP4质量的按钮,当我点击该按钮时,它会打开一个弹出窗口并要求按下另一个按钮,下载视频,有第一个按钮的javascript ,当它点击时,打开弹出窗口并给出第二个按钮,从那里使用PHP,现在我想让它一键下载,
以下是第一个按钮的代码......
<button id="videoDownloadButton" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" onClick="downloadVideo();">MP4 Quality</button>
单击时,将运行以下javascript代码
function downloadVideo() {
var videoID = player.getVideoData()['video_id']
document.getElementById("downloadFormatList").innerHTML="Please wait. Processing...";
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp3 = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp3.onreadystatechange=function() {
if (xmlhttp3.readyState==4 && xmlhttp3.status==200) {
document.getElementById("downloadFormatList").innerHTML=xmlhttp3.responseText;
}
}
//keyword = keyword.replace(/ /g, '%2B');
xmlhttp3.open("GET","TMB/download.php?videoid="+videoID,true);
xmlhttp3.send();
}
然后运行PHP代码,PHP代码就是这个......
if(isset($_REQUEST['videoid'])) {
$my_id = $_REQUEST['videoid'];
if(strpos($my_id,"https://youtu.be/") !== false)
{
$my_id = str_replace("https://youtu.be/","",$my_id);
}
}
<?php
//$my_video_info = 'http://www.youtube.com/get_video_info?&video_id='. $my_id;
$my_video_info = 'http://www.youtube.com/get_video_info?&video_id=' . $my_id . '&asv=3&el=detailpage&hl=en_US'; //video details fix *1
$my_video_info = curlGet($my_video_info);
/* TODO: Check return from curl for status code */
$thumbnail_url = $title = $url_encoded_fmt_stream_map = $type = $url = '';
parse_str($my_video_info);
?>
<?php
$my_title = $title;
$cleanedtitle = clean($title);
if (isset($url_encoded_fmt_stream_map)) {
/* Now get the url_encoded_fmt_stream_map, and explode on comma */
$my_formats_array = explode(',', $url_encoded_fmt_stream_map);
if ($debug) {
echo '<pre>';
print_r($my_formats_array);
echo '</pre>';
}
} else {
echo '<p>No encoded format stream found.</p>';
echo '<p>Here is what we got from YouTube:</p>';
echo $my_video_info;
}
if (count($my_formats_array) == 0) {
echo '<p>No format stream map found - was the video id correct?</p>';
exit;
}
/* create an array of available download formats */
$avail_formats[] = '';
$i = 0;
$ipbits = $ip = $itag = $sig = $quality = '';
$expire = time();
foreach ($my_formats_array as $format) {
parse_str($format);
$avail_formats[$i]['itag'] = $itag;
$avail_formats[$i]['quality'] = $quality;
$type = explode(';', $type);
$avail_formats[$i]['type'] = $type[0];
$avail_formats[$i]['url'] = urldecode($url) . '&signature=' . $sig;
parse_str(urldecode($url));
$avail_formats[$i]['expires'] = date("G:i:s T", $expire);
$avail_formats[$i]['ipbits'] = $ipbits;
$avail_formats[$i]['ip'] = $ip;
$i++;
}
echo '<div class="format_list">';
echo '<br>';
echo '<table>';
/* now that we have the array, print the options */
for ($i = 0; $i < 1; $i++) {
if ($config['VideoLinkMode'] == 'direct' || $config['VideoLinkMode'] == 'both')
?> <tr><td><?php
echo $avail_formats[$i]['type'];
?></td>
<td><small>(<?php
echo $avail_formats[$i]['quality'];
?>)</small> </td>
<td><small><span class="size"><?php
echo formatBytes(get_size($avail_formats[$i]['url']));
?></span></small>
</td>
<td><a href="<?php
echo $avail_formats[$i]['url'];
?> '&title='<?php
echo $cleanedtitle;
?>'" class="downloadButton">Record Video</a></td>
</tr>
<?php
}
?>
点击第一个按钮后,将出现此按钮,
<a href="<?php echo $avail_formats[$i]['url']; ?> '&title='<?php echo $cleanedtitle; ?>'" class="downloadButton">Record Video</a>
现在我只想点击一下,我该怎么做...... ??
答案 0 :(得分:0)
尝试在弹出页面的底部添加:
<script>
window.location = '<?php echo $avail_formats[$i]['url']; ?>';
</script>
答案 1 :(得分:0)
根据你的php代码,&#34;第二个按钮&#34;术语不正确。 您可能有一些具有不同质量的第二个按钮。
这就是PHP代码和第二次点击的原因。
如果您想立即下载视频,请在php代码中替换您的foreach循环
foreach ($my_formats_array as $format) {
parse_str($format);
$avail_formats[$i]['itag'] = $itag;
$avail_formats[$i]['quality'] = $quality;
$type = explode(';', $type);
$avail_formats[$i]['type'] = $type[0];
$avail_formats[$i]['url'] = urldecode($url) . '&signature=' . $sig;
parse_str(urldecode($url));
$avail_formats[$i]['expires'] = date("G:i:s T", $expire);
$avail_formats[$i]['ipbits'] = $ipbits;
$avail_formats[$i]['ip'] = $ip;
$i++;
}
上的
if (isset($my_formats_array[0])) {
parse_str($my_formats_array[0]);
header("Location: " . urldecode($url) . '&signature=' . $sig);
die();
}
摆脱其他不必要的事情