2016-07-29 14 views
1

Ich habe ein PHP-Skript geschrieben, das zum Herunterladen von Youtube-Video verwendet wird, es funktioniert auf 2 Tasten, erste Schaltfläche wird zum Erstellen der Formate verwendet und zweite Schaltfläche startet Download, ich will dass, wenn ich drücken, erste Taste, 2. Taste, tat automatisch seine Arbeit, und zum Download auf Klick starten,URL automatisch ohne Klicken in PHP-Skript öffnen

Hier ist der Code für die erste Schaltfläche,

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

Javssript auf diese Schaltfläche ist ...

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(); 

} 

und danach PHP-Skript funktioniert und dass die zweite Schaltfläche erzeugen, die ein HTML-Tag ist,

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 
} 
?> 

die Taste Dies ist, dass i

<a href="<?php 
    echo $avail_formats[$i]['url']; 
?> '&title='<?php 
echo $cleanedtitle; 
?>'" class="downloadButton">Record Video</a> 
+0

Verwendung von JavaScript zu überprüfen, ob Dieses DOM-Element bedeutet, dass diese Schaltfläche vorhanden ist, und feuere ein Click-Ereignis dagegen ab. Wenn Sie irgendwelche Verwirrung haben, kann ich Code dafür schreiben. –

+0

oh bitte, ich bin dankbar für dich, schreibe es –

Antwort

0

try automatisch tat seine Arbeit zu wollen dies anstelle Ihres zweiten Tastencodes.

+0

nein, es funktioniert nicht ... –

+0

überprüfen Sie es jetzt. es funktioniert wahrscheinlich. –

+0

nop ...., es funktioniert immer noch nicht –

0

Alle Event-Handler, die mit .on() oder einer der Shortcut-Methoden verbunden sind, werden beim Auftreten des entsprechenden Ereignisses ausgelöst. Sie können jedoch manuell mit der Methode .trigger() ausgelöst werden. Ein Aufruf von .trigger() führt die Handler in der gleichen Reihenfolge, wie sie sein würde, wenn das Ereignis natürlich durch den Benutzer ausgelöst wurden:

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

hier ist der Verweis auf die Referenz meines example

+0

Lassen Sie mich das überprüfen, und dann werde ich mit dir reden –

+0

wie, ich füge es, mit diesem Knopf.? –

+0

geben Sie eine ID zum Knopf, dann werden Sie es bekommen. –

Verwandte Themen