The idea for this script came from mentok.
mentok , Thank You for this idea and your help testing.
Description:
Simple Youtube Downloader will download a youtube video based on the link that you enter and place it in the folder you select. The default download location is $mircdirYoutube. //run $mircdirYoutube to see them.
Options:
You can select Audio Only, Video Only or Both.
Audio only will download the video, convert it to audio and remove the video file.
Video only will download the video file.
Both will make two files, one for audio and one for video.

After clicking download you will have a second set of options.
Medium mpg seems to be the fastest to me but select whatever you like.
This should have no effect on the audio track. Just select one of the lower ones if you are doing audio only.
Again, medium mpg seems to download the fastest.
After the selection you will see the download progress for the video.
If you have selected Audio only or Both you will now see the Audio Quality selection screen.
160 will probably give you the best balance of size and quality but feel free to adjust this to your liking.
This setting will have on effect on the downloaded video, just the audio.
You will now see the final conversion dialog.
How it works:
**Note** This script will download all the needed files on it's own. There is no need to download anything to use this.
Special thanks to all the folks who have contributed code to both the ffmpeg and wget projects.
Two awesome command line apps.
If you have any issues running this code, try this version:
http://pastebin.com/06CrHNsm
Thanks to Abcdefmonkey & Fuzionx for their input on this edit.
;Youtube Simple Downloader by Ford_Lawnmower irc.Geekshed.net #Script-Help
menu channel,status,menubar {
Youtube Simple Downloader: dialog $iif(!$dialog(YTSimpleDownloader),-m YTSimpleDownloader,-v) YTSimpleDownloader
}
alias -l DSleep {
return $WshRunitSilent(choice /c "10" /n /d "1" /t $1)
}
alias -l WshRunitSilent {
var %comname $+(WshRunSilent,$ticks)
.comopen %comname WScript.Shell
if ($com(%comname)) {
if (!$com(%comname,run,3,bstr,$1-,uint,0,string,true)) {
echo -st *error* WshRunSilent $com(%comname).error
var %return 0
}
else var %return 1
.comclose %comname
return %return
}
}
;VideoToAudio ffmpeg.exeDirectory;infile;outfile;cleanup command here
alias -l VideoToAudio {
tokenize 59 $1-
var %start $ctime, %dname $replace($+(YTVideoToAudio,$mkfn($3)),$chr(32),_), %cleanup $4, %temp $+($wshgetvar(temp),\,$nopath($3))
var %quality $input(Please select an audio quality,omr,Quality Settings Needed,160,64,128,160,192,224,256,320)
if (%quality) {
dialog $iif($dialog(%dname),-v,-md) %dname YTVideoToAudio
dcheck did -a %dname 8 $nopath($2)
dcheck did -a %dname 9 $nopath($3)
dcheck did -a %dname 11 Conversion in progress......
ShowProgress %dname
.timer $+ %dname 0 1 ShowProgress %dname
if ($exists($qt($3))) .remove $qt($3)
if ($WshRunitSilent($1 -i $qt($2) -vn -ar 44100 -ac 2 -ab $+(%quality,k) -f mp3 $qt(%temp))) {
dcheck did -a %dname 11 Conversion Complete in $duration($calc($ctime - %start))
.timer $+ %dname off
.copy $qt(%temp) $qt($3)
.remove $qt(%temp)
%cleanup
}
else dcheck did -a %dname Conversion Failed!
}
}
alias -l ShowProgress {
var %count $iif($calc($gettok($nopath($did($1,1)),1,46) + 1) > 8,1,$calc($gettok($nopath($did($1,1)),1,46) + 1))
dcheck did -g $1 1-7 $+(FFmpeg\,%count,.ico)
return
}
alias -l dcheck {
if ($dialog($3)) $1-
}
dialog -l YTVideoToAudio {
title "Video to Audio Conversion"
size -1 -1 132 56
option dbu
icon 1, 2 24 17 19
icon 2, 20 24 17 19
icon 3, 38 24 17 19
icon 4, 56 24 17 19
icon 5, 74 24 17 19
icon 6, 92 24 17 19
icon 7, 110 24 17 19
text "", 8, 0 1 132 8, center
text "", 9, -2 16 134 8, center
text "TO", 10, 51 8 25 8, center
text "", 11, 0 46 132 8, center
text "", 12, 0 0 0 0
}
dialog -l YTSimpleDownloader {
title "Youtube Downloader"
size -1 -1 202 51
option dbu
text "Link:", 1, 0 4 25 8, right
text "Save to:", 2, 0 15 25 8, right
edit "", 3, 26 3 175 10
edit "", 4, 26 14 151 10
button "Browse", 5, 179 14 22 10
radio "Audio Only", 6, 8 38 42 10
radio "Video Only", 7, 54 38 38 10
button "Download", 8, 163 37 37 12
text "", 9, 0 27 201 8
radio "Both", 10, 97 38 31 10
}
on *:dialog:YTSimpleDownloader:Sclick:5,8: {
getwget
if ($did == 5) did -ra $dname 4 $sdir($mircdir,Select a Directory)
else {
tokenize 32 $did(3) $did(4) $iif($did(6).state,Audio,$iif($did(8).state,Both,Video)) $did(4)
if ($regex($1,/v=([\S]{11})/Si)) {
YTGetDownloadLinks $regml(1) $regml(1)
}
}
}
;$bintween by Ford_Lawnmower Syntax = $bintween(&binvar,starttext,endtext,matchnum)
alias -l bintween {
var %count = 1, %mark = 0, %mark2 = 0
while (%count <= $4) {
if ($bfind($1, %mark2, $2).text) {
%mark = $calc($bfind($1, %mark2, $2).text + $len($2))
if ($bfind($1, %mark, $3).text) {
%mark2 = $bfind($1, %mark, $3).text
}
else { return 0 }
}
else { return 0 }
inc %count
}
return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text
}
alias -l DecodeUri return $replace($regsubex($1-,/\%([0-9a-f]{2})/gi,$chr($base(\t,16,10))),\u0026,&,sig,signature)
alias -l WshVbscriptDownload {
var %comname $+(WshVbscriptDownload,$ticks,$r(1,1000))
.comopen %comname MSScriptControl.ScriptControl
if ($com(%comname)) {
var %Success $com(%comname,language,4,string,vbscript)
inc %Success $Execute(%comname,Set MicrosoftXmlhttp = CreateObject("Microsoft.Xmlhttp"))
inc %Success $Execute(%comname,$+(MicrosoftXmlhttp.Open "GET",$chr(44),$qt($1),$chr(44),False))
inc %Success $Execute(%comname,MicrosoftXmlhttp.Send)
if ($evaluate(%comname,MicrosoftXmlhttp.Status)) {
inc %Success $Execute(%comname,set AdodbStream = CreateObject("Adodb.Stream"))
inc %Success $Execute(%comname,AdodbStream.type = 1)
inc %Success $Execute(%comname,AdodbStream.open)
inc %Success $Execute(%comname,AdodbStream.write MicrosoftXmlhttp.responseBody)
inc %Success $Execute(%comname,AdodbStream.savetofile $+($qt($2),$chr(44),2))
inc %Success $Execute(%comname,AdodbStream.close)
if (%Success != 10) echo -st *error* WshVbscriptDownload Download Failed!
else {
$iif(!$isid,echo 09 -sat Download $1 Complete)
var %return 1
}
}
.comclose %comname
return %return
}
}
alias -l Execute return $com($1,executestatement,3,bstr,$2-)
alias -l Evaluate {
noop $com($1,eval,3,bstr,$2-)
return $com($1).result
}
On *:start: {
if (!$exists(wget\wget.exe)) getwget
}
On *:dialog:YT_GetDownloadLinks~*:close:*: if ($hget($dname)) hfree $dname
On *:dialog:YT_GetDownloadLinks~*:Sclick:1-16: {
$iif(!$isdir(Youtube),mkdir Youtube)
$iif(!$isdir(wget),mkdir wget)
if ((!$exists(wget\wget.exe)) || (!$exists($ffmpeg))) {
echo -gat I am missing some of the files needed to download your video.
echo -gat Please try your download after I gather the missing files.
getwget
}
else {
var %fn $mkfn($did(18)), %ext $gettok($did($did),1,32), %id $gettok($dname,2,126), %idext $+(%id,%ext), %type $gettok($did($did),1,32)
var %dir $did(19)
var %selection $did(20)
run -n wget\wget.exe -bo $qt($+($wshgetvar(temp),\,%id,%ext)) -O $qt($+(%dir,%fn,.,%type)) $qt($hget($dname,$did))
dialog $iif($dialog(%idext),-v,-md) %idext YTDownloadProgress
did -a %idext 1 %fn
did -a %idext 10 %selection
did -a %idext 11 %dir
did -a %idext 12 %ext
.timer 1 2 YTProgressCheck %idext
dialog -x $dname
}
}
alias -l YTProgressCheck {
var %file $+($wshgetvar(temp),\,$1), %dname $1, %data $remove($read(%file,$calc($lines(%file) - 1)),..)
if ($dialog(%dname)) {
tokenize 32 %data
if (!$5) {
did -a %dname 2 $bytes($calc($remove($1,k) * 1000)).suf
did -a %dname 3 $2
did -a %dname 4 $3
did -a %dname 5 $4
.timer $+ %dname 1 1 YTProgressCheck %dname
}
else {
did -a %dname 2,3,5 Complete
did -a %dname 4 $3-4
.remove $qt(%file)
if ($did(%dname,10) != Video) {
var %sel $did(%dname,10), %dir $did(%dname,11), %ext $did(%dname,12), %fn $did(%dname,1)
var %command $iif($did(%dname,10) == Audio,.remove $qt($+(%dir,%fn,.,%ext)))
var %fn2 $iif($exists($qt($+(%dir,$did(%dname,1),.mp3))), $input($did(%dname,1) already exists.$&
$crlf Please enter a new file name.,eoq,FileName Conflict,$did(%dname,1),),$did(%dname,1))
if (%fn) VideoToAudio $+($qt($ffmpeg),;,$qt($+(%dir,%fn,.,%ext)),;,$qt($+(%dir,%fn2,.,mp3)),;,%command)
}
dialog -x %dname
}
}
}
alias -l GetWget {
if (!$isdir(wget)) {
if ($input(You must download some files to continue. $crlf Dowload them now ?,yq,Youtube Simple DownloaderMissing Files,,)) {
mkdir wget
}
else halt
}
if (!$exists(wget/wget.exe)) DownloadTransfer http://fordlawnmower.googlecode.com/files/wget wget.exe wget
if (!$exists(wget/libssl32.dll)) DownloadTransfer http://fordlawnmower.googlecode.com/files/libssl32 libssl32.dll wget
if (!$exists(wget/libintl3.dll)) DownloadTransfer http://fordlawnmower.googlecode.com/files/libintl3 libintl3.dll wget
if (!$exists(wget/libiconv2.dll)) DownloadTransfer http://fordlawnmower.googlecode.com/files/libiconv2 libiconv2.dll wget
if (!$exists(wget/libeay32.dll)) DownloadTransfer http://fordlawnmower.googlecode.com/files/libeay32 libeay32.dll wget
GetFFmpeg
}
alias -l DownloadTransfer {
var %tempfile $+($wshgetvar(temp),/,$2), %destfile $+($3,/,$2)
if (!$isdir($3)) mkdir $3
if ($WshVbscriptDownload($1, %tempfile)) {
.copy %tempfile %destfile
.remove %tempfile
echo 04 -ga Transfer of %destfile complete.
}
}
alias -l GetFFmpeg {
$iif(!$isdir(FFmpeg),mkdir FFmpeg)
if (!$exists($ffmpeg)) DownloadTransfer http://fordlawnmower.googlecode.com/files/ffmpeg ffmpeg.exe ffmpeg
var %count 1
while (%count <= 8) {
if (!$exists($+(ffmpeg/,%count,.ico))) DownloadTransfer $+(http://fordlawnmower.googlecode.com/files/,%count,.ico) $+(%count,.ico) ffmpeg
inc %count
}
}
alias -l FFmpeg return $mircdirFFmpeg\ffmpeg.exe
alias -l WshGetVar {
var %comname $+(WinGetVar,$ticks)
.comopen %comname Wscript.Shell
if ($com(%comname)) {
if (!$com(%comname,ExpandEnvironmentStrings,3,bstr,$+(%,$1,%))) {
echo -st *error* WinGetVar $com(%comname).error
}
var %return $com(%comname).result
.comclose %comname
return %return
}
}
alias -l fix&# {
return $regsubex($replace($regsubex($1-,/\&\#([0-9]{1,});/g,$utf8(\t)),",",&,&,>,>,<,<,',',$chr(9),$chr(32)),$&
/([$\|%\[\]\}\{][^\s]*)/g,$+($chr(2),$chr(2),\t))
}
alias -l UTF8 {
if ($version >= 7) return $chr($1)
elseif ($1 < 255) { return $chr($1) }
elseif ($1 >= 256) && ($1 < 2048) { return $+($chr($calc(192 + $div($1,64))),$chr($calc(128 + $mod($1,64)))) }
elseif ($1 >= 2048) && ($1 < 65536) { return $+($chr($calc(224 + $div($1,4096))),$chr($calc(128 + $mod($div($1,64),64))),$chr($calc(128 + $mod($1,64)))) }
elseif ($1 >= 65536) && ($1 < 2097152) {
return $+($chr($calc(240 + $div($1,262144))),$chr($calc(128 + $mod($div($1,4096),64))),$chr($calc(128 + $mod($div($1,64),64))),$&
$chr($calc(128 + $mod($1,64))))
}
}
alias -l div { return $int($calc($1 / $2)) }
alias -l mod {
var %int $int($calc($1 / $2))
return $calc($1 - (%int * $2))
}
alias -l H2U { return $utf8($base($1,16,10)) }
dialog YT_Download_Selector {
title "Youtube Download Selector"
size -1 -1 159 70
option dbu
button "", 1, 2 4 37 12, hide disable
button "", 2, 41 4 37 12, hide disable
button "", 3, 80 4 37 12, hide disable
button "", 4, 119 4 37 12, hide disable
button "", 5, 2 17 37 12, hide disable
button "", 6, 41 17 37 12, hide disable
button "", 7, 80 17 37 12, hide disable
button "", 8, 119 17 37 12, hide disable
button "", 9, 2 30 37 12, hide disable
button "", 10, 41 30 37 12, hide disable
button "", 11, 80 30 37 12, hide disable
button "", 12, 119 30 37 12, hide disable
text "", 18, 2 59 154 8, center
button "", 13, 2 44 37 12, hide disable
button "", 14, 41 44 37 12, hide disable
button "", 15, 80 44 37 12, hide disable
button "", 16, 119 44 37 12, hide disable
text "", 19, 0 0 0 0
text "", 20, 0 0 0 0
}
dialog -l YTDownloadProgress {
title "Youtube Downloads"
size -1 -1 98 54
option dbu
text "", 1, 1 2 96 8, center
text "", 2, 37 15 58 8
text "", 3, 37 24 59 8
text "", 4, 37 33 59 8
text "", 5, 37 42 59 8
text "Size:", 6, 2 15 32 8, right
text "Complete:", 7, 2 24 32 8, right
text "Speed:", 8, 2 33 32 8, right
text "Remaining:", 9, 2 42 32 8, right
text "", 10, 1 10 0 6, center
text "", 11, 1 10 0 6, center
text "", 12, 1 10 0 6, center
}
alias -l YTGetDownloadLinks {
var %sockname $+(YtGetDownLoadLinks,$network,$2,$ticks)
sockopen %sockname www.youtube.com 80
svar %sockname url $+(/watch?v=,$1)
svar %sockname dname $+(YT_GetDownloadLinks,~,$1)
svar %sockname filename $2-
svar %sockname file $+($1,.text)
}
On *:sockopen:YtGetDownLoadLinks*: {
if (!$sockerr) {
sockwrite -nt $sockname GET $svar($sockname,url) HTTP/1.0
sockwrite -n $sockname Host: www.youtube.com
sockwrite -n $sockname $crlf
}
else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:YtGetDownLoadLinks*: {
if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
else {
sockread -f &YtGetDownLoadLinks
if ($bintween(&YtGetDownLoadLinks,<title>,</title>,1)) svar $sockname filename $v1
var %YtGetDownLoadLinks $decodeuri($bvar(&YtGetDownLoadLinks,1-).text)
write -n $svar($sockname,file) %YtGetDownLoadLinks
}
}
On *:sockclose:YtGetDownLoadLinks*: {
var %file $svar($sockname,file), %count 1, %dname $svar($sockname,dname)
dialog $iif($dialog(%dname),-v,-m) %dname YT_Download_Selector
did -a %dname 18 $svar($sockname,filename)
did -a %dname 19 $iif($isdir($did(YTSimpleDownloader,4)),$did(YTSimpleDownloader,4),$mircdirYoutube\)
did -a %dname 20 $iif($did(YTSimpleDownloader,6).state,Audio,$iif($did(YTSimpleDownloader,10).state,Both,Video))
dialog -x YTSimpleDownloader
bread $svar($sockname,file) 1 $file(%file).size &parse
var %start $calc($bfind(&parse, 1, "url_encoded_fmt_stream_map") + 28), %end $bfind(&parse, %start, $+(",:)), %dif $calc(%end - %start)
bcopy &file 1 &parse %start %dif
while ($bintween(&file,signature=,&,%count)) {
var %signature $+(&signature=,$gettok($v1,1,44))
if ($bintween(&file,url=,$chr(44),%count)) {
var %url $v1
noop $regex(%url,/itag=(\d+)/i)
var %itag $+(&itag=,$regml(1)), %videotype $YoutubeGetQuality($regml(1))
var %url $regsubex($replace($gettok(%url,1,34),sig=,signature=),/(\&itag=\d+)/gi,$null)
hadd -m %dname %count $+(%url,$iif(signature= !isin %url,%signature),$iif(itag= !isin %url,%itag))
if ($dialog(%dname) && $hget(%dname,%count).data) { did -eva %dname %count %videotype }
}
inc %count
}
.remove $svar($sockname,file)
}
alias -l YoutubeGetQuality {
if ($1 == 5) return FLV 240p
elseif ($1 == 6) return FLV 270p
elseif ($1 == 13) return 3GP n/a
elseif ($1 == 17) return 3GP 144p
elseif ($1 == 18) return MP4 360p
elseif ($1 == 22) return MP4 720p
elseif ($1 == 34) return FLV 360p
elseif ($1 == 35) return FLV 480p
elseif ($1 == 36) return 3GP 240p
elseif ($1 == 37) return MP4 1080p
elseif ($1 == 38) return MP4 3072p
elseif ($1 == 43) return WebM 360p
elseif ($1 == 44) return WebM 480p
elseif ($1 == 45) return WebM 720p
elseif ($1 == 46) return WebM 1080p
elseif ($1 == 82) return MP4 360p
elseif ($1 == 83) return MP4 240p
elseif ($1 == 84) return MP4 720p
elseif ($1 == 85) return MP4 520p
elseif ($1 == 100) return WebM 360p
elseif ($1 == 101) return WebM 360p
elseif ($1 == 102) return WebM 720p
elseif ($1 == 120) return FLV 720p
}
alias -l Svar {
var %sockname $1, %item $2
if ($isid) {
if ($regex($sock(%sockname).mark,/ $+ %item $+ \x01([^\x01]*)/i)) return $regml(1)
}
elseif ($3) {
var %value $3-
if (!$regex($sock(%sockname).mark,/ $+ %item $+ \x01/i)) { sockmark %sockname $+($sock(%sockname).mark,$chr(1),%item,$chr(1),%value) }
else { sockmark %sockname $regsubex($sock(%sockname).mark,/( $+ %item $+ \x01[^\x01]*)/i,$+(%item,$chr(1),%value)) }
}
}