ASP script to save/download YouTube videos code only

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.

I got a couple of ideas to improve the ASP video downloader script I wrote and by the time I had the improvements completed, the script became MUCH lighter! It is now in all ASP code.

Your server must have the component ASPhttp to make this script work. If your host doesn't have it, ask support to install it for you.

The script takes a YouTube video url and teases out the actual, real url of the video flash file, then makes it into a downloadable link. It is also useful as an example of how ASPhttp component can be used in fun and creative ways to find obfuscated urls.

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.

  • ASP enabled web host (usually a Windows host).
  • Server must have component ASPhttp installed. Many have this but if yours doesn't, ask support to install it for you.

Free Flash .flv file player.

NOTE: this ASP YouTube downloader isn't very efficient for large files. PHP with Page Curl has worked better, but since YouTube changed its parameters it appears that the PHP script I copied to here is also in need of updating.


I worked very hard on this, so if you find it useful or interesting, please rate at or send me an email. I'd love to hear from you.  

by users
What do you think?






<form method="POST" action="getrealurl.asp">

<input type="text" name="v" size="20" value="">
<input type="submit" value="Submit" name="B1">



'getrealurl.asp Updated as of Oct 22, 2007.

'Script by Lil Peck -
'You may use this in your applications but please leave acknowlegement for me.
'Finds real URL of YouTube flash video file.

'---check referring form page

Dim strDuh 'declaring the variable, a good habit
strDuh = Request.ServerVariables("HTTP_REFERER")'the string we want to compare to the items in the array
'response.write strDuh

Dim sMyArray(4)'what we name our array and how many items in it
'replace following urls with your form page urls
sMyArray(0) = ""
sMyArray(1) = ""
sMyArray(2) = ""
sMyArray(3) = ""

For Each i In sMyArray 'i can be any designation for the items in the array like z or bugguts or whatever

'now we need to set up a Case with with to compare our querystring to the items in the array
Select Case MatchArray 'give your case a name for identification purposes

Case YES

if i = strDuh then
Cal = "YES"

end if
End select


If Cal = "YES" then response.write""

If NOT Cal = "YES" then

'replace following urls with your form page url
response.redirect ""
end if

'---end check referring form page

if request.form("v") = "" then
response.redirect "videoform.asp"
end if

dim strVid
strVid = request.form("v")

dim vidID
vidID = Right(strVid, Len(strVid) - InStrRev(strVid, "=") ) 'gets id number from url

Server.ScriptTimeout = 240

Set HttpObj = Server.CreateObject("AspHTTP.Conn")

HttpObj.Url = "" & vidID

HttpObj.FollowRedirects = true

HttpObj.RequestMethod = "GET"

HttpObj.UserAgent = "Mozilla/2.0 (compatible; MSIE 3.0B; Windows NT)"

strResult = HttpObj.GetURL
curURL = HttpObj.Url


InitialString = curURL

Set RegularExpressionObject = New RegExp

With RegularExpressionObject
.IgnoreCase = True
.Global = True
End With

ReplacedString = RegularExpressionObject.Replace(InitialString, "")

Set RegularExpressionObject = nothing

Set HttpObj = Server.CreateObject("AspHTTP.Conn")

HttpObj.Url = ReplacedString

HttpObj.FollowRedirects = true

HttpObj.RequestMethod = "GET"

HttpObj.UserAgent = "Mozilla/2.0 (compatible; MSIE 3.0B; Windows NT)"

strResult = HttpObj.GetURL

nextURL = HttpObj.Url


Set HttpObj = Server.CreateObject("AspHTTP.Conn")

HttpObj.Url = nextURL

HttpObj.FollowRedirects = true

HttpObj.RequestMethod = "GET"

HttpObj.UserAgent = "Mozilla/2.0 (compatible; MSIE 3.0B; Windows NT)"

strResult = HttpObj.GetURL

fnlURL = HttpObj.Url


'regex script from
'converts real flv file url from get_video to get_video_abc123.flv so user doesn't have to rename
InitialString = fnlURL

Set RegularExpressionObject = New RegExp

With RegularExpressionObject
.Pattern = "get_video?"
.IgnoreCase = True
.Global = True
End With

MyRep = "get_video_" & vidID & ".flv"

ReplacedString = RegularExpressionObject.Replace(InitialString, MyRep)

Set RegularExpressionObject = nothing



<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>asp script video downloader asphttp youtube</title>


<body style="font-family: Verdana">
<b><font size="4">ASP script to save/download YouTube videos (v. 4)</font></b><p>
<br><a href="<%
response.write ReplacedString %>">Click to download video file.</a><br>

<a href="savetosite.asp?vid=<%=vid%>&file=<% response.write ReplacedString
%>">Click to save to server.</a><br>

savetosite.asp - OPTIONAL, allows the files to be saved directly to your website

<%@ Language=VBScript %>

'change folders and urls to your own
'if you use this option you may want to put in safeguards (referer check and so on) to prevent abuse and
'also change the variable strURL to be inputted by form rather than querystring
' Set the URL of the file you want to save
strURL = request.querystring("file")
strFileExtension = ".flv"
' Set the Local path on your server
strLocalPath = "D:\Clients\public_html\aspexamples\youtu\"
strLocalFileName = request.querystring("vid")

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

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

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>" & strLocalFileName & strFileExtension &"<br>"
Response.Write("<a href=""download.asp?FileName=" &" & strLocalFileName & strFileExtension & ">" & vbNewline & _
"Download</a>" & vbNewline )



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.

If you find omissions or errors let me know. I have moved these code samples to their own domain; if you find pieces missing, please let me know.
My favorite scripts site is CODANGO.


If any the information I've posted here has been useful to you, please donate.

Quick 'n  easy  dirty PHP script code wizard-generator

Zenphoto RSS XML feed used as data source for javascript slide show with PHP

Classic ASP to archive emails into database and save attached files to folder

PHP Image GD for thumbnails and image resizing with pathing for Windows servers

ODBC database connections for Microsoft Access MDB files with Windows 7: solution posted on this forum.

HTML5 embedded video player "Projekktor" completely skinnable with hyperlinked watermark

Edit web.config to allow Windows iis7 server to handle mp4 files or other mime types as needed

URL rewrite or make friendly URLs for iis7 Windows Server 2008 by editing your web.config file


Use PHP to zip folders for backing up a website

Use PHP to archive emails in database and save attached files to folder

Use PHP with json to check how many hits left on Twitter API

PHP get single record from Access database without catchable fatal error message

PHP to make a bot to send automatic Twitter status updates with Abraham Williams' PHP Oauth Twitter Library

A way to use the PHP Oauth Twitter Library with your Classic ASP scripts for sending status updates

Get user's IP address location for your form results

Tutorial for registering an application with Twitter

Update your Twitter status with Classic ASP and Oauth seamlessly and invisibly without having to login to Twitter. Send status updates programmatically from a web page. PHP example too.

CLASSIC ASP: Cache your Twitter tweets in a database to keep your Twitter xml requests within the rate limit of 350 per hour / PHP VERSION

PHP: Use json to fetch Twitter followers' profiles

Index files content and insert into database for faster searches

Classic ASP with Ajax: secure URL check

Classic ASP with Ajax: referer check

Classic ASP with Ajax: a solution to the ampersand problem in querystrings

Very Simple Star Rating System for Classic ASP

Star Rating System uses CSS and JS adapated for Classic ASP from Yvo Schaap PHP script

XMLhttp with ASP to fetch and save photos from Photobucket account through RSS XML. Can be adapted for Youtube videos to import data to database.

NET image resize can be used to make thumbnails for Classic ASP

Track site visitors, get their ip address geographical data, count page views with Classic ASP

Javascript slideshow with Classic ASP to load image details dynamically from database photos table

Classic ASP with Ajax for rotating banners without page refresh and XML file converted to recordset as banner database
--Variation of the above but fetching a REMOTE XML file as the database
--Variation checks for secure URL and builds absolute URL and makes offsite banner links open in new window

True inline edit Classic ASP datagrid table database edit updating with Ajax SIMPLE EASY without page refresh!

Use Ajax with Classic ASP to preview data then update form with javascript url write

Yvo Schaap's easy inline edit Ajax: an example of using it to inline edit multiple rows of records in Classic ASP

Use Classic ASP to send text messages SMS from your website (Also shows how to use xmlhttp to post form data)

Ajax with Classic ASP for seamless, no page reload database record insertion

Nested SQL Statements to make temporary column names

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

These are out of date but may still be of interest:

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: can also be used for URL rewriting

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 (doesn't seem to work on Windows Server 2008)

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?

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

From Classic ASP to PHP

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

BuildApp - great old Classic ASP script generator!

Software Recommendation: bare_bones_no_bells_and_whistles_asp_code_generator_database_interface_maker (For PHP I recommend EasyGen.)

If any of this information is helpful to you, please consider donating with the button below. Thanks! ~~Lil