ASP script to save/download YouTube videos

Looking for a script that allows website visitors to download Youtube videos to their own computers? This one is written in Active Server Pages for ASP enabled websites. You also have the option to allow video files to be saved directly to your own site.

If you install this script and offer this service on your website, please be respectful of copyrights. It is possible to set the script up to allow downloads only of your own video files.

Requirements:

CLICK HERE FOR COMPLETELY ASP VERSION


 

OLD VERSION BELOW (SAVES YOUTUBE VIDEO DIRECTLY TO YOUR SERVER)
OLD VERSION
TO PROMPT USER DOWNLOAD THIS LINK

ASP with a PHP script that finds the real URL of a YouTube video. This version will allow it to be remotely saved to the server then the resulting file made downloadable.

My apologies to coders whose work I have not properly credited here...I did so much searching that I forgot who did what.

This demonstration fakes the process, so as to save server bandwidth.

(Click once and wait.)

formpage.htm

<form method="POST" action="url.php">

<p>
<input type="text" name="link" size="20"><input type="submit" value="Submit" name="B1"> (Click once and wait.)</p>
</form> 

Form posts to url.php


<?php
$link = $_POST["link"];


/************************************************************************************

Script Name : Youtube Downloader 0.1
Function : To show path into FLV files located at Youtube.com
Creator : Yeni Setiawan (yeni.setiawan@yahoo.com, http://sandalian.com)
Created date : April 5, 2007
Requirement : PHP with CURL

Note:
This is a basic functions used to show real URI of FLV files at youtube.com so we can
download the file and play it offline.

Disclaimer:
You use it at your own risk. You can ask me question about this script but you shouldn't
ask me about any damaged computer caused by this script.

To do:
- Build AJAX interface.
- Put it in my homepage as public service

************************************************************************************/


// ------------------------------------ START SCRIPT --------------------------//
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 (preg_match('/\/player2\.swf\?(.*)", "movie_player"/', $string, $match)) {
$url = $match[1];
return 'http://youtube.com/get_video.php?'.$url;
}
}

function get_http_header($url){
$uh = curl_init();
curl_setopt($uh, CURLOPT_URL, $url);
curl_setopt($uh, CURLOPT_HEADER, 1);
curl_setopt($uh, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($uh);
curl_close($uh);
return $res;
}

function show_url($http_header){
$arai = explode("\n",$http_header);
foreach($arai as $ini){
if(eregi("location",$ini)) $url = $ini;
}
list($sampah,$hasil) = explode("Location:",$url);
return str_replace("\n","",trim($hasil));
}

function download_youtube($url){
$data = get_content_of_url($url);
$next_url = get_flv_link($data);
$data = get_http_header($next_url);
return show_url($data);

}
// ------------------------------------ END SCRIPT --------------------------//

// SAMPLE OF USAGE

error_reporting(0); // <-- to eliminate error report
ini_set("max_execution_time",0); // <-- to avoid operation timed out
$File = download_youtube($link);



//uncomment below to save to site
//header('Location: http://yoursiteurl/youtu/save.asp?file='.$File);


?>


<a href="<?php
echo
$File
?>.flv">Click to download/save.</a><br>

Flash .flv file is saved to folder on server with save.asp

<head>
<meta http-equiv="Content-Language" content="en-us">
</head>

<%@ Language=VBScript %>
<%

'http://www.eromandie.com/codesource/asp/save_file_from_url.asp
' Set the URL of the file you want to save
strURL = request.querystring("file")
'strFileName = "test2"
strFileExtension = ".flv"
' Set the Local path on your server
strLocalPath = "D:\yoursitepath\public_html\aspexamples\youtu"
strLocalFileName = "testvideo"

' Create Work Object
Set objXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
Set objBinaryStream = CreateObject("ADODB.Stream")

' Get the file
objXMLHTTP.Open "GET", strURL & strFileName & strFileExtension , false
objXMLHTTP.Send()
objBinaryStream.Type = 1

objBinaryStream.Open
objBinaryStream.Write objXMLHTTP.responseBody
' Save the file on the server
objBinaryStream.SaveToFile server.MapPath("./" & strLocalFileName & strFileExtension), 2

Set objXMLHTTP = Nothing
Set objBinaryStream = Nothing
response.write "Complete. <BR>http://yoursiteurl/youtu/testvideo.flv<br>"
Response.Write("<a href=""download.asp?FileName=http://yoursiteurl/youtu/testvideo.flv"">" & vbNewline & _
"Download</a>" & vbNewline )


Response.write(vbNewLine)

%>

download.asp link with script by Lewis Moten: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8528&lngWId=4
ASP Examples Menu of Active Server Pages scripts code Classic ASP

Classic ASP Active Server Pages Examples, code, tutorials, scriptsASP Examples Menu (below*)



Active Server Pages | ASP | Scripts | Tutorials | Code | Web Programming | Examples
Active Server Pages ASP code examples, tutorials, and snippets for use in Programming interactive websites.

NOTE: Recently changed hosting and url so some demos aren't working now because I haven't updated pathing; if you find omissions or errors let me know.
 

*

Multiple records per row with paging

Display multiple records per row

Get ID of newly inserted record, Classic ASP, Access Database

Javascript timer with ASP to keep track of time expired until login expires / timeout session is up

Multiple Javascript event functions triggered from single form onsubmit

Get Querystring key names along with querystring variables

ASP Youtube Downloader  Version FOUR
All ASP code. Allows user client side downloads of Youtube videos. You have the option to allow files to be saved directly to your site also.

ASP/PHP video downloader (Works better than ASP for large files)

Use ASP to dynamically parse a Youtube XML playlist to render to html.

Zip up an archive file of your site for backup if you need to restore website with ASP and free Zip Component.

Zip all files in a folder into an archive or backup file dynamically by specific file extension.

Sanitize or clean price cost field for database insertion or display.

Javascript image dimensions and image file size preview.

Put recordset into array, assign keys to the records then use record associated with specific array key as a variable elsewhere.

Access Database Interface Generator Wizard to read your table and field names and to create a table display.

Combining dropdown selection box menu with dynamic ASP database page.

How to redirect user to original page they tried to view before logging, after they are logged in.

Previous/Current/Next Records, or Buddy Ring Script

Custom ASP 404 page not found error script sends visitors to virtual folders

ASP Example: Combine ASP with Javascript for popup windows
dynamically sized to image dimensions.

ASP Example: How to use ASPJPEG to create thumbnails
Click for free Highly recommended thumbnailer for which you don't need Server access

ASPjpeg: How to re-scale aspect ratio of thumbnails by height instead of width.

ASP Example: What if your host has an older version of ASPJPEG that doesn't support gifs?

Using inline frames as "dynamic includes" (offline for updating)

Select Count Distinct Records for Access Database

Upload Image to folder and insert filename into database

Get date in such a way that it can be made part of a file name

Isolate a file name away from its path or extension or strip a path from a file name or strip characters from database field

User-customized on-the-fly stylesheet css files

Enhanced Page Hits Counter (also counts downloads and menu link hits)

Loop through array and compare to string with select case

Aphabetical Paging for your ASP scripts

Web Wiz Guide's Site Searcher Script modified as a file content indexer

Let Users Select How Many Records to View

Access Database for your PayPal IPN scripts

Miscellaneous collected code

You don't have to be a genius, just persistent, to write original Active Server Pages scripts

Software Recommendation: bare_bones_no_bells_and_whistles_asp_code_generator_database_interface_maker

--Lil at gmail.com