This script will search Youtube and return the results to the dialog along with information about them and a preview image. At this point you can select the quality/file type to download
to download the selected video with your default browser.
Alternately, if you know the link for a video you want, you can enter it in the search box and when you click [Search / Get] to download the video.
Example:
Put this in the search box and click [Search / Get] to download with the direct link.
http://www.youtube.com/watch?v=YgH5W-h00NQ&feature=popular
Getting started:
Load the script into remotes.
Right click the screen or any menu and select Youtube Video Downloader.
Enter some words in the search box and click search.
Click Play to Play the selected video.
Click Download to see the download selection.
Click a selection to download.
Videos are downloaded to $mircdirYoutube
Easy way to view the directory.
//run $mircdirYoutube
Updated 12-27-2011
This script now uses wget and will download the needed files on first use.
http://gnuwin32.sourceforge.net/packages/wget.htm
;Youtube Video Downloader by Ford_Lawnmower irc.Geekshed.net #Script-Help
menu * {
Youtube Video Downloader: dialog $iif($dialog(Y_V_D),-v,-md) Y_V_D Y_V_D
}
alias -l YoutubeSearch {
if ($sock(YoutubeSearch)) { sockclose YoutubeSearch }
sockopen YoutubeSearch www.youtube.com 80
sockmark YoutubeSearch $+(/results?search_type=videos&aq=f&search_query=,$replace($1-,$chr(32),+))
}
On *:sockopen:YoutubeSearch: {
if (!$sockerr) {
did -r Y_V_D 3,13,17-20
sockwrite -nt $sockname GET $sock($sockname).mark 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:YoutubeSearch: {
if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
else {
var %Youtube | sockread %Youtube
if (No video results isin %Youtube) {
did -a Y_V_D 3,13 No results were found for your search!
if ($hget($sockname)) hfree $sockname
sockclose $sockname
}
elseif (<h3 class="yt-lockup-title"> isin %Youtube && __title__ !isin %Youtube) {
if ($regex(%Youtube,/title="([^"]*)"/i)) did -a Y_V_D 3,13 $fix($regml(1))
if ($regex(%Youtube,/\/watch\?v=([^"]*)"/i)) {
did -a Y_V_D 20 $regml(1)
GetThumb i3.ytimg.com $+(/vi/,$regml(1),/default.jpg) YouTubeThumbs $+($calc($did(Y_V_D,13).lines),.jpg)
}
}
elseif (by <a href=" isin %Youtube && __channel_url__ !isin %Youtube) {
if ($regex(%Youtube,/>([^<]+)<\/a><\/li><li>([^<]+)<\/li><li>([^<]+)\sviews/i)) {
did -a Y_V_D 19 $regml(1)
did -a Y_V_D 18 $regml(2)
did -a Y_V_D 17 $regml(3)
}
elseif ($regex(%Youtube,/data-name="">([^<]*)<\/a>/i)) {
did -a Y_V_D 19 $regml(1)
}
}
elseif ($regex(%Youtube,/<\/li><li>([^<]+)<\/li><li>([^<]+)\sviews/i)) {
did -a Y_V_D 18 $regml(1)
did -a Y_V_D 17 $regml(2)
}
}
}
On *:sockclose:YoutubeSearch: {
did -c Y_V_D 3,13,17-20 1
if ($hget($sockname)) hfree $sockname
sockclose $sockname
.timer 1 3 did -g Y_V_D 5 youtubethumbs/1.jpg
}
alias -l fix { return $regsubex($remove($replace($1-,&,&,","),amp;),/&#([0-9]{2});/gi,$chr(\t)) }
dialog Y_V_D {
title "Youtube Video Downloader"
size -1 -1 231 238
option dbu
edit "", 1, 4 11 173 10, autohs
button "Search / Get", 2, 181 9 46 12
combo 3, 2 40 90 9
text "Results", 4, 100 31 127 8, center
icon 5, 7 55 79 69
text "Views:", 9, 4 134 25 8, right
text "Added:", 10, 4 149 25 8, right
text "User:", 11, 4 163 25 8, right
text "Video ID:", 12, 4 177 25 8, right
list 13, 100 40 126 175
combo 17, 33 133 60 9
combo 18, 33 148 60 9
combo 19, 33 162 60 9
combo 20, 33 176 60 9
button "Download", 22, 144 219 39 12
button "Play", 23, 188 219 39 12
text "Video Title", 24, 2 31 90 8, center
}
On *:dialog:Y_V_D:Sclick:2,13,21-23: {
if ($did == 2) && ($did($dname,1).text) {
tokenize 32 $v1
if ($regex($1,/v=([\S]{11})/Si)) { YTubeGetDownloadLinks $regml(1) $regml(1) }
else { YoutubeSearch $1- }
}
elseif ($did == 13) {
did -c $dname 3,17-20 $did(Y_V_D,13).sel
did -g $dname 5 $+(youtubethumbs/,$did(Y_V_D,13).sel,.jpg)
}
elseif ($did == 22) && ($did(20)) { YTubeGetDownloadLinks $v1 $did(3).seltext }
elseif ($did == 23) { url -an $+(http://www.youtube.com/watch?v=,$did($dname,20).seltext) }
}
alias -l GetWget {
$iif(!$isdir(wget),mkdir wget)
if (!$exists(wget/wget.exe)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/wget wget/wget.exe
if (!$exists(wget/libssl32.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libssl32 wget/libssl32.dll
if (!$exists(wget/libintl3.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libintl3 wget/libintl3.dll
if (!$exists(wget/libiconv2.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libiconv2 wget/libiconv2.dll
if (!$exists(wget/libeay32.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libeay32 wget/libeay32.dll
}
alias -l GetThumb {
if ($isfile($qt($+($3,\,$4)))) { .remove $qt($+($3,\,$4)) }
var %sockname $+(GetThumb,$ticks,$r(1,$ticks))
if (!$isdir($qt($3))) { mkdir $qt($3) }
sockopen %sockname $1 80
sockmark %sockname $1-
}
On *:sockopen:GetThumb*:{
sockwrite -nt $sockname GET $gettok($sock($sockname).mark,2,32) HTTP/1.0
sockwrite -n $sockname Host: $gettok($sock($sockname).mark,1,32) $+ $crlf $+ $crlf
}
On *:sockread:GetThumb*:{
if (!$gettok($sock($sockname).mark,5,32)) {
var %GetThumb | sockread %GetThumb
if (!%GetThumb) { sockmark $sockname $addtok($sock($sockname).mark,1,32) }
}
else {
sockread &GetThumb
bwrite -s $qt($+($gettok($sock($sockname).mark,3,32),\,$gettok($sock($sockname).mark,4,32))) -1 -1 &GetThumb
}
}
;Link select and download starts here.
alias -l YTubeGetDownloadLinks {
var %sockname $+(YtubeGetDownLoadLinks,$network,$2,$ticks)
sockopen %sockname www.youtube.com 80
svar %sockname url $+(/watch?v=,$1)
svar %sockname dname $+(YTubeGetDownloadLinks,~,$1)
svar %sockname filename $2-
svar %sockname file $+($1,.text)
}
On *:sockopen:YtubeGetDownloadLinks*: {
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:YtubeGetDownloadLinks*: {
if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
else {
sockread -f &YtubeGetDownloadLinks
if ($bintween(&YtubeGetDownloadLinks,<title>,</title>,1)) svar $sockname filename $v1
var %YtubeGetDownloadLinks $decodeuri($bvar(&YtubeGetDownloadLinks,1-).text)
write -n $svar($sockname,file) %YtubeGetDownloadLinks
}
}
On *:sockclose:YtubeGetDownloadLinks*: {
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)
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, $+(</script>)), %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 {
var %key 5,6,13,17,18,22,34,35,36,37,38,43,44,45,46,82,83,84,85,100,101,102,120, $&
133,134,135,136,137,138,139,140,141,160,171,172,242,243,244,245,246,247,248,264
var %itag FLV 240p,FLV 270p,3GP n/a,3GP 144p,MP4 360p, $&
MP4 720p,FLV 360p,FLV 480p,3GP 240p,MP4 1080p, $&
MP4 3072p,WebM 360p,WebM 480p,WebM 720p,$&
WebM 1080p,MP4 360p,MP4 240p,MP4 720p,MP4 520p, $&
WebM 360p,WebM 360p,WebM 720p,FLV 720p, $&
MP4 320p,MP4 480p,MP4 640x480,MP4 1280x720,MP4 1920x1080,MP4 Low, $&
MP4 Med,MP4 Hi,MP4 256x144,WebM Med,WebM Hi, $&
WebM 320x240,WebM 480x360,WebM 640x480,WebM 640x480,WebM 640x480,WebM 1280x720, $&
WebM 1920x1080,WebM 1920x1080
if ($findtok($remove(%key,$chr(32)),$1,44)) return $gettok(%itag,$v1,44)
}
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)) }
}
}
;$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,&)
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)
;$iif(!$isid,noop $tip(download,File Download,$qt(Downloading $1 $bytes($evaluate(%comname,AdodbStream.Size)).suf),3,,,,))
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,noop $tip(download,File Download,$qt($1 Complete),3,,,,))
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: {
echo -ga Downloading the needed files for this script, please wait .....
getwget
}
On *:dialog:YTubeGetDownloadLinks~*:close:*: hfree $dname
On *:dialog:YTubeGetDownloadLinks~*:Sclick:1-16: {
$iif(!$isdir(Youtube),mkdir Youtube)
$iif(!$isdir(wget),mkdir wget)
if (!$exists(wget\wget.exe)) {
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),2,45), %id $gettok($dname,2,126), %idext $+(%id,%ext)
run -n wget\wget.exe -bo $qt($+($mircdir,wget\,%id,%ext)) -O $qt($+($mircdir,Youtube,\,%fn,.,%ext)) $hget($dname,$did)
dialog $iif($dialog(%idext),-v,-md) %idext YTDownloadProgress
did -a %idext 1 %fn
YTProgressCheck %idext
}
}
alias -l YTProgressCheck {
var %file $+(wget\,$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 %file
}
}
}
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
}
dialog 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
}
Updated 12-27-2011
This script now uses wget and will download the needed files on first use.
http://gnuwin32.sourceforge.net/packages/wget.htm
Tested and working on mIRC 6.35 & 7.x on both 32 & 64 bit machines.
I'm going to try to quickly explain how this works because I'm getting a lot of questions from people wanting to make a youtube downloader in another language.
First : They keep changing it , but the solution can always be found in the source ; in the flash player section.
<div id="watch-player" class="flash-player">
fmt_url_map=
&
/fmt_url_map=(.*?)&/
35%7Chttp%3A%2F%2Fv6.lscache4.c.youtube.com%2Fvideoplayback%3Fsparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D35%26ipbits%3D8%26burst%3D40%26sver%3D3%26signature%3DA9B7F2AC733E05D7369DF0C6B2C0A802B6D9C8ED.92042D6A86879855EB9FB1B107AC53C5C5626953%26expire%3D1304308800%26key%3Dyt1%26ip%3D174.0.0.0%26factor%3D1.25%26id%3D11afdc068b4f226d%2C34%7Chttp%3A%2F%2Fv23.lscache4.c.youtube.com%2Fvideoplayback%3Fsparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D34%26ipbits%3D8%26burst%3D40%26sver%3D3%26signature%3D4CE3A0C2E09B92A066F824B006801FF41E0FA636.1701E51A241559F14A57B37F1AC9A8E0B1C7D9DA%26expire%3D1304308800%26key%3Dyt1%26ip%3D174.0.0.0%26factor%3D1.25%26id%3D11afdc068b4f226d%2C18%7Chttp%3A%2F%2Fv9.lscache2.c.youtube.com%2Fvideoplayback%3Fsparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D18%26ipbits%3D8%26burst%3D40%26sver%3D3%26signature%3D84306C633F7DC4FD7D0751304B7EC81260254E3D.59959ED5D66A41F49C53AC860EF2C025121C64E9%26expire%3D1304308800%26key%3Dyt1%26ip%3D174.0.0.0%26factor%3D1.25%26id%3D11afdc068b4f226d%2C5%7Chttp%3A%2F%2Fv16.lscache1.c.youtube.com%2Fvideoplayback%3Fsparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D5%26ipbits%3D8%26burst%3D40%26sver%3D3%26signature%3D0F05799111FFBCC21278F2D345FD4F331DA61BB8.94D4070F6869448CAED16803C48CB2EDF5F44F3B%26expire%3D1304308800%26key%3Dyt1%26ip%3D174.0.0.0%26factor%3D1.25%26id%3D11afdc068b4f226d
Crazy ;/ I know.
After you run it through urldecode it will look something like this:
35|http://v6.lscache4.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor&algorithm=throttle-factor&itag=35&ipbits=8&burst=40&sver=3&signature=A9B7F2AC733E05D7369DF0C6B2C0A802B6D9C8ED.92042D6A86879855EB9FB1B107AC53C5C5626953&expire=1304308800&key=yt1&ip=174.0.0.0&factor=1.25&id=11afdc068b4f226d,34|http://v23.lscache4.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor&algorithm=throttle-factor&itag=34&ipbits=8&burst=40&sver=3&signature=4CE3A0C2E09B92A066F824B006801FF41E0FA636.1701E51A241559F14A57B37F1AC9A8E0B1C7D9DA&expire=1304308800&key=yt1&ip=174.0.0.0&factor=1.25&id=11afdc068b4f226d,18|http://v9.lscache2.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor&algorithm=throttle-factor&itag=18&ipbits=8&burst=40&sver=3&signature=84306C633F7DC4FD7D0751304B7EC81260254E3D.59959ED5D66A41F49C53AC860EF2C025121C64E9&expire=1304308800&key=yt1&ip=174.0.0.0&factor=1.25&id=11afdc068b4f226d,5|http://v16.lscache1.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor&algorithm=throttle-factor&itag=5&ipbits=8&burst=40&sver=3&signature=0F05799111FFBCC21278F2D345FD4F331DA61BB8.94D4070F6869448CAED16803C48CB2EDF5F44F3B&expire=1304308800&key=yt1&ip=174.0.0.0&factor=1.25&id=11afdc068b4f226d
Still pretty crazy looking, but if you study it you will see a patern.