Hulp bij download script
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('');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
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
<?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']);
?>
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//1.jpg" alt="Preview 1" class="ythumb" />
<img src="http://img.youtube.com/vi//2.jpg" alt="Preview 2" class="ythumb" />
<img src="http://img.youtube.com/vi//3.jpg" alt="Preview 3" class="ythumb" />
</p>
<p>
<a href="" class="ydl" title="Download as FLV">Download FLV</a>
<a href="&fmt=18" class="ydl" title="Download as MP4">Download MP4</a>
<a href="&fmt=17" class="ydl" title="Download as 3GP">Download 3GP</a>
</p>
Code (php)
youtube.lib.php7
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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);
* ?>
*
*/
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);
* ?>
*
*/
Beperk je code tot uitsluitend relevante code.
@aar pak gewoon je glazen bol?
... is naar de glasblazer toe, voor garantie-nawerk :-(
Wat bedoel je ?
Quote:
This function (eregi) has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
Gebruik dus: http://nl.php.net/manual/en/function.preg-match.php
Gewijzigd op 28/02/2012 18:23:46 door - Ariën -