Wat heb ik hier fout gedaan ??
hij download niet....
Javascript:
<!--
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(random_key) {
var youtube_url = document.getElementById('q').value;
if(youtube_url.length>8){
// disable both text and button field
document.getElementById("q").disabled = true;
document.getElementById("b").disabled = true;
// display loading things
loading();
// okay, send request to starfleet
http.open('get', 'robot.php?key='+random_key+'&url='+youtube_url);
http.onreadystatechange = handleResponse;
http.send(null);
}
else{
// yeah, at least please tell me what to download :P
alert('Please enter video URL you wish to download.');
}
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
document.getElementById("result").innerHTML = response;
// undisabled all disabled items
document.getElementById("q").disabled = false;
document.getElementById("b").disabled = false;
document.getElementById("q").value = '';
return false;
//}
}
}
function loading(){
document.getElementById("result").innerHTML = "<p><img src='img/o.gif' alt='loading..' /></p>";
return false;
}
// this is a hack for IE T_T
var newdiv = document.createElement("div");
var container = document.getElementById("result");
container.appendChild(newdiv);
-->
index:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> Youtube Downloader</title>
<meta name="keywords" content="Video downloader, download youtube, video download, youtube video, youtube downloader, download youtube FLV, download youtube MP4, download youtube 3GP, php video downloader" />
<meta name="description" content="This video downloader is able to download video from youtube.com in 3 different format. For high quality choose MP4, medium choose FLV and for low quality (and play on your cellphone) please choose 3GP." />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/youtube.js"></script>
</head>
<body>
<div id="container">
<h1> Youtube Downloader</h1>
<!--
I must add time() function to trick the bad IE's cache.
-->
<form method="get" id="form" onsubmit="sndReq('<?php echo time();?>');return false;">
<input type="text" name="q" id="q" size="40" /> <input type="submit" name="b" id="b" value="Download" />
</form>
<div id="result"><blockquote>Example: http://www.youtube.com/watch?v=Y_xhRQXobG0</blockquote></div>
</div>
<p id="power">powered by <a href="#/">Kenzey!!</a></p>
</body>
</html>
Robot.php
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
require_once('lib/youtube.lib.php');
if(eregi('youtube.com|localhost',$_GET['url'])){
if(!eregi('www.',$_GET['url'])){
$_GET['url'] = str_replace('http://','http://www.',$_GET['url';]);
}
list($video_id,$download_link) = get_youtube($_GET['url']);
?>
<p>
<img src="http://img.youtube.com/vi/<?php echo trim($video_id);?>/1.jpg" alt="Preview 1" class="ythumb" />
<img src="http://img.youtube.com/vi/<?php echo trim($video_id);?>/2.jpg" alt="Preview 2" class="ythumb" />
<img src="http://img.youtube.com/vi/<?php echo trim($video_id);?>/3.jpg" alt="Preview 3" class="ythumb" />
</p>
<p>
<a href="<?php echo trim($download_link);?>" class="ydl" title="Download as FLV">Download FLV</a>
<a href="<?php echo trim($download_link);?>&fmt=18" class="ydl" title="Download as MP4">Download MP4</a>
<a href="<?php echo trim($download_link);?>&fmt=17" class="ydl" title="Download as 3GP">Download 3GP</a>
</p>
<?php
}
else{
die('<span style="color:red;">Sorry, the URL is not recognized..</span>');
}
?>
youtube.lib.php7
<?php
function get_content_of_url($url){
$ohyeah = curl_init();
curl_setopt($ohyeah, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ohyeah, CURLOPT_URL, $url);
$data = curl_exec($ohyeah);
curl_close($ohyeah);
return $data;
}
function get_flv_link($string) {
if (eregi("watch_fullscreen(.*)plid", $string, $out)) {
$outdata = $out[1];
}
$arrs = (explode('&',$outdata));
foreach($arrs as $arr){
list($i,$x) = explode("=",$arr);
$$i = $x;
}
$link = 'http://www.youtube.com/get_video?video_id='.$video_id.'&t='.$t;
return array($video_id,$link);
}
function get_youtube($url){
$stream = get_content_of_url($url);
return get_flv_link($stream);
}
/*
* <?php
* require_once('youtube.lib.php');
* echo get_youtube($youtube_url);
* ?>
*
*/
2.689 views