无需在PHP脚本中单击即可自动打开URL

时间:2016-07-29 15:43:08

标签: javascript php html

我写了一个用于下载任何youtube视频的php脚本,它适用于2个按钮,第一个按钮用于创建格式,第二个按钮开始下载, 我希望如果我按,第一个按钮,第二个按钮,自动完成其工作,并单击开始下载,

以下是第一个按钮的代码,

<button id="videoDownloadButton" type="button" class="btn btn-info btn-lg"          data-toggle="modal" data-target="#myModal" onClick="downloadVideo();">MP4 Quality</button>

Javssript在那个按钮上....

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脚本将工作并生成第二个按钮,这是一个HTML标记,

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>

2 个答案:

答案 0 :(得分:0)

试试这个,而不是你的第二个按钮代码。

ValueError: pattern contains no capture groups

答案 1 :(得分:0)

当相应的事件发生时,会触发附加.on()或其快捷方法之一的任何事件处理程序。但是,可以使用.trigger()方法手动触发它们。对.trigger()的调用以与用户自然触发事件时相同的顺序执行处理程序:

$( "#foo" ).on( "click", function() {
  alert( $( this ).text() );
});
if($("required-button").length>0){
$( "#foo" ).trigger( "click" );
}

这是对我example

的引用的引用