From 28eb44212e5787094399d6e0d8612e76d105189b Mon Sep 17 00:00:00 2001 From: Peteris Krumins Date: Wed, 2 Dec 2009 10:32:55 +0200 Subject: [PATCH] initial vbscript youtube downloader import --- readme.txt | 50 ++++++++++++ ytdown.vbs | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100755 readme.txt create mode 100755 ytdown.vbs diff --git a/readme.txt b/readme.txt new file mode 100755 index 0000000..15acdb2 --- /dev/null +++ b/readme.txt @@ -0,0 +1,50 @@ +This is a YouTube video downloader written in VBScript. I wrote it because +when I was a child, I did a lot of programming in Visual Basic and I wanted to +remember what it was like. + +It was written by Peteris Krumins (peter@catonmat.net). +His blog is at http://www.catonmat.net -- good coders code, great reuse. + +The code is licensed under the MIT license. + +I also wrote a tutorial on how I created this program. The tutorial is called +"Writing a YouTube Video Downloader in VBScript", and I explain what Windows +Scripting Host (WSH) is, what cscript and wscript are, how to parse command +line arguments in VBScript, and how to use XmlHttp COM object. Read the +article here: + + http://www.catonmat.net/blog/writing-a-youtube-video-downloader-in-vbscript/ + +------------------------------------------------------------------------------ + +The program is called "ytdown.vbs". It can be either be used from command line +via cscript, or as a dialog-based application via wscript. + +To run it as a dialog-based application, just double click the "ytdown.vbs" +file and it will ask you to enter the address of a YouTube video (see the +article for a screenshot). + +To run it from command line, run it via cscript as following: + + cscript ytdown.vbs "http://www.youtube.com/watch?v=ID1" "..." + +You may specify multiple video URLs and it will download all of them. + +Here is an example run: + + C:\>cscript ytdown.vbs "http://www.youtube.com/watch?v=2mTLO2F_ERY" + Microsoft (R) Windows Script Host Version 5.7 + Copyright (C) Microsoft Corporation. All rights reserved. + + Downloading video 'Mr. W' + Done downloading video. Saved to Mr__W.flv. + +------------------------------------------------------------------------------ + +Happy downloading! + + +Sincerely, +Peteris Krumins +http://www.catonmat.net + diff --git a/ytdown.vbs b/ytdown.vbs new file mode 100755 index 0000000..360a941 --- /dev/null +++ b/ytdown.vbs @@ -0,0 +1,228 @@ +' +' Peteris Krumins (peter@catonmat.net) +' http://www.catonmat.net - good coders code, great reuse +' +' 2007.08.03 v1.0 - initial release +' 2007.10.21 v1.1 - youtube changed the way it displays vids +' 2008.03.01 v1.2 - youtube changed the way it displays vids +' 2009.12.02 v1.3 - youtube changed the way it displays vids +' +Option Explicit + +Dim WscriptMode + +' Detect if we are running in WScript or CScript +If UCase(Right(WScript.Fullname, 11)) = "WSCRIPT.EXE" Then + WScriptMode = True +Else + WScriptMode = False +End If + +Dim Args: Set Args = WScript.Arguments + +If Args.Count = 0 And WScriptMode Then + ' If running in WScript and no command line args are provided + ' ask the user for a URL to a YouTube video + Dim Url: Url = InputBox("Enter a YouTube video URL to download" & vbCrLf & _ + "For example, http://youtube.com/watch?v=G1ynTV_E-5s", _ + "YouTube Downloader, http://www.catonmat.net") + If Len(Url) = 0 Then: WScript.Quit 1 + DownloadVideo Url +ElseIf Args.Count = 0 And Not WScriptMode Then + ' If running in CScript and no command line args are provided + ' show the usage and quit + WScript.Echo "Usage: " & WScript.ScriptName & "