I had posted an article explaining how to download YouTube videos by knowing its URL. This technique can be implemented in any language, however I chose to make it in PHP.
This enables you to have it on your own sites.
The regular readers of DOL might have noticed a little iFrame, at the bottom right of the blog, that hosted the PHP scripts in my home machine. However, sometimes I have to go to sleep and sometimes I tend to shut the PC down. Also, my connection is a miserable 2M ADSL line so my home network usually was crumbed by heavy traffic. As a result the YouTube download tool was not always working and this was frustrating to many people. I agree and I apologize.
So, under popular demand here are is the source code. Enjoy!
iFrame HTML code (trivial):
<html>
<head>
<form action="dnlUTube.php" method="post">
<p><b>YouTube URL:</b> <input size= 28 type="text" name="name" /></p>
<p><input type="submit" value="Get it!" /></p>
</form>
<i>Example: http://www.youtube.com/watch?v=319hsZ12TAE</i>
</head>
<body>
</body>
</html>
Now this refers to the PHP file dnlUTube.php, that actually retrieves the download URL of the video. The source code is:
dnlUTube.php : extracts YouTube download link
<html>
<?php
#
# Script to download YouTube videos
# Originally crafted by panefsky on Developer On Line- Salonica,Greece 2008
# Use free. Credits welcome.#
# Input: Post parameter 'name' is the YouTube URL
# Known issues: sometimes the parsing fails either because
#YouTube does not send the proper format or
#whatever.. However 2nd invocation of script always succeeds! You might contribute at that.
#
# Enjoy!
if(!empty($_POST['name'])) {
$location = htmlspecialchars($_POST['name']);
try {
$handle = fopen($location, "r");
if($handle) {
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$result1 = preg_match("/&t=([\w]*)&/",$contents,$tickets);
$result2 = preg_match("/v=(\w*)/",$location,$video_id);
if($result1) {
echo "<a href = \"http://www.youtube.com/get_video?video_id=";
echo $video_id[1];
echo "&t=";
echo $tickets[1];
echo "\">Download link.</a>";
echo "<br>";
echo "Click n Save with flv extension";
}
else echo "Damn! Click Back and try again..Sorry :(";
}
else echo "\nYou liked that? Ha?";
}
catch(Exception $e) {echo "I made an error. So what?";}
}
else echo "Empty input! Bad boy...!";
?>
<br><br>
<a href="dolUTubeFrame.html">Back</a>
</hmtl>
That's it! Happy downloading!