Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'by Flammrock
- call downloadVideoYouTube()
- Public function downloadVideoYouTube()
- dim video_url,video_title,data,windowWait,ws,itag,info,video_filename,link
- video_url = InputBox("Please enter Youtube link: ", "Download Video YouTube")
- video_id = getID(video_url)
- if video_id <> "0" Then
- data = URLDecode(file_get_contents("http://www.youtube.com/get_video_info?video_id=" & video_id))
- video_title = GetVideoTitle(file_get_contents(video_url))
- link = getLinks(video_title,data)
- if link <> "0" Then
- itag = Mid(ExtractMatch(link,"[?&]itag(=([^&#]*)|&|#|$)"),2)
- info = Split(getInfoVideo(itag),";")
- video_filename = MkFileName(video_title) & "." & info(0)
- windowWait = createWindow("Please wait, downloading of in progress..",200,100,"Download of "&video_title)
- openWindow windowWait,False
- call downloadFile(video_filename,link)
- Set ws = CreateObject("wscript.shell")
- ws.Run "Taskkill /im ""mshta.exe"" /f",0,True
- else
- Msgbox "Could not extract video Links"
- end if
- else
- Msgbox "Could not extract video ID"
- end if
- end function
- Public function downloadFile(filename,url_link)
- dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
- dim bStrm: Set bStrm = createobject("Adodb.Stream")
- xHttp.Open "GET", url_link, False
- xHttp.Send
- with bStrm
- .type = 1 '//binary
- .open
- .write xHttp.responseBody
- .savetofile filename, 2 '//overwrite
- end with
- downloadFile = True
- end function
- Public function getID(url)
- id = ExtractMatch(url, "v=([A-Za-z0-9-_]+)")
- if Len(id) = 0 Then
- getID = "0"
- Exit Function
- end if
- getID = id
- end function
- Public function ExtractMatch(Text, Pattern)
- Dim Regex, Matches
- Set Regex = New RegExp
- Regex.Pattern = Pattern
- Set Matches = Regex.Execute(Text)
- If Matches.Count = 0 Then
- ExtractMatch = ""
- Exit Function
- End If
- ExtractMatch = Matches(0).SubMatches(0)
- End Function
- Public function getLinks(title,queryString)
- dim Matches,itag,url,info,listFormatAvailable,itagselect
- Set objRegEx = CreateObject("VBScript.RegExp")
- objRegEx.Global = True
- objRegEx.IgnoreCase = True
- objRegEx.Pattern = "[?&]url(=([^&#]*)|&|#|$)"
- Set Matches = objRegEx.Execute(queryString)
- if Matches.Count = 0 Then
- getLinks = "0"
- Exit Function
- end if
- listFormatAvailable = "<script>var index=0;</script><center><h1 style=""font:15px Verdana;"">Download of <b style=""color:red;"">" & title & "</b></h1><br /><br /><select onchange=""index=this.options[this.selectedIndex].getAttribute('data-i');"" style=""width:50%;padding: 10px;"">"
- for i = 0 to Matches.Count-1
- url = (Split(URLDecode(Mid(Matches.Item(i),6)),","))(0)
- itag = Mid(ExtractMatch(url,"[?&]itag(=([^&#]*)|&|#|$)"),2)
- info=Split(getInfoVideo(itag),";")
- 'listFormatAvailable = listFormatAvailable & info(0) & " (" & info(1) & ") " & info(2) & vbCrLf
- listFormatAvailable = listFormatAvailable & "<option data-i=""" & i & """>" & info(0) & " (" & info(1) & ") " & info(2) & "</option><br />"
- next
- Set environmentVars = WScript.CreateObject("WScript.Shell").Environment("Process")
- tempFolder = environmentVars("TEMP")
- listFormatAvailable = listFormatAvailable & "</select><br /><button style=""border:0;width:50%;padding: 10px;background:#0d0;font:15px Verdana;color:#fff;margin:3px;"" onclick=""var fso = new ActiveXObject('Scripting.FileSystemObject');var file = fso.CreateTextFile('" & Replace(tempFolder,"\","\\") & "\\index.youtube.tmp', true);file.write(index);file.Close();setTimeout(function(){window.close();},200);"">Select!</button></center>"
- selectionWindow = createWindow("Selection.. - "&title,500,300,listFormatAvailable)
- openWindow selectionWindow,True
- Set fso = CreateObject("Scripting.FileSystemObject")
- If (fso.FileExists(tempFolder & "\\index.youtube.tmp")) Then
- Set file = fso.OpenTextFile(tempFolder & "\\index.youtube.tmp", 1)
- itagselect = file.ReadAll
- file.Close
- fso.DeleteFile tempFolder & "\\index.youtube.tmp"
- getLinks = (Split(URLDecode(Mid(Matches.Item(itagselect),6)),","))(0)
- Exit Function
- Else
- getLinks = "0"
- Exit Function
- End If
- if Matches.Count > 0 Then
- end if
- getLinks = "0"
- end function
- Public function createWindow(title,width,height,body)
- createWindow = Join(Array("<!doctype html>","<html>","<head>","<meta charset=""UTF-8"">","<meta http-equiv=""X-UA-Compatible"" content=""IE=edge,chrome=1"">","<script>window.resizeTo(" & width & "," & height & ");window.moveTo(screen.width/2-" & width & "/2,screen.height/2-" & height & "/2);</script>","<title>" & title & "</title>","</head>","<body>",body,"</body>","</html>"),vbCrLf)
- end function
- Public function openWindow(a,b)
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- tempname = objFSO.GetTempName
- Set environmentVars = WScript.CreateObject("WScript.Shell").Environment("Process")
- tempFolder = environmentVars("TEMP")
- Set objFileToWrite = objFSO.CreateTextFile(tempFolder & "\" & tempname & ".hta",True)
- objFileToWrite.Write(a)
- objFileToWrite.Close
- Set objFileToWrite = Nothing
- Set objShell = CreateObject("WScript.Shell")
- objShell.Run tempFolder & "\" & tempname & ".hta",1,b
- end function
- Public function getInfoVideo(itag)
- dim data
- data = "Unknown Type"
- if itag = 5 Then
- data = "flv;audio/video;240p;;"
- ElseIf itag = 6 Then
- data = "flv;audio/video;270p;;"
- ElseIf itag = 17 Then
- data = "3gp;audio/video;144p;;"
- ElseIf itag = 18 Then
- data = "mp4;audio/video;360p;;"
- ElseIf itag = 22 Then
- data = "mp4;audio/video;720p;;"
- ElseIf itag = 34 Then
- data = "flv;audio/video;360p;;"
- ElseIf itag = 35 Then
- data = "flv;audio/video;480p;;"
- ElseIf itag = 36 Then
- data = "3gp;audio/video;180p;;"
- ElseIf itag = 37 Then
- data = "mp4;audio/video;1080p;;"
- ElseIf itag = 38 Then
- data = "mp4;audio/video;3072p;;"
- ElseIf itag = 43 Then
- data = "webm;audio/video;360p;;"
- ElseIf itag = 44 Then
- data = "webm;audio/video;480p;;"
- ElseIf itag = 45 Then
- data = "webm;audio/video;720p;;"
- ElseIf itag = 46 Then
- data = "webm;audio/video;1080p;;"
- ElseIf itag = 82 Then
- data = "mp4;audio/video;360p;;3D"
- ElseIf itag = 83 Then
- data = "mp4;audio/video;480p;;3D"
- ElseIf itag = 84 Then
- data = "mp4;audio/video;720p;;3D"
- ElseIf itag = 85 Then
- data = "mp4;audio/video;1080p;;3D"
- ElseIf itag = 92 Then
- data = "hls;audio/video;240p;;3D"
- ElseIf itag = 93 Then
- data = "hls;audio/video;360p;;3D"
- ElseIf itag = 94 Then
- data = "hls;audio/video;480p;;3D"
- ElseIf itag = 95 Then
- data = "hls;audio/video;720p;;3D"
- ElseIf itag = 96 Then
- data = "hls;audio/video;1080p;;"
- ElseIf itag = 100 Then
- data = "webm;audio/video;360p;;3D"
- ElseIf itag = 101 Then
- data = "webm;audio/video;480p;;3D"
- ElseIf itag = 102 Then
- data = "webm;audio/video;720p;;3D"
- ElseIf itag = 132 Then
- data = "hls;audio/video;240p;;"
- ElseIf itag = 133 Then
- data = "mp4;video;240p;;"
- ElseIf itag = 134 Then
- data = "mp4;video;360p;;"
- ElseIf itag = 135 Then
- data = "mp4;video;480p;;"
- ElseIf itag = 136 Then
- data = "mp4;video;720p;;"
- ElseIf itag = 137 Then
- data = "mp4;video;1080p;;"
- ElseIf itag = 138 Then
- data = "mp4;video;2160p60;;"
- ElseIf itag = 139 Then
- data = "m4a;audio;48k;;"
- ElseIf itag = 140 Then
- data = "m4a;audio;128k;;"
- ElseIf itag = 141 Then
- data = "m4a;audio;256k;;"
- ElseIf itag = 151 Then
- data = "hls;audio/video;72p;;"
- ElseIf itag = 160 Then
- data = "mp4;video;144p;;"
- ElseIf itag = 167 Then
- data = "webm;video;360p;;"
- ElseIf itag = 168 Then
- data = "webm;video;480p;;"
- ElseIf itag = 169 Then
- data = "webm;video;1080p;;"
- ElseIf itag = 171 Then
- data = "webm;audio;128k;;"
- ElseIf itag = 218 Then
- data = "webm;video;480p;;"
- ElseIf itag = 219 Then
- data = "webm;video;144p;;"
- ElseIf itag = 242 Then
- data = "webm;video;240p;;"
- ElseIf itag = 243 Then
- data = "webm;video;360p;;"
- ElseIf itag = 244 Then
- data = "webm;video;480p;;"
- ElseIf itag = 245 Then
- data = "webm;video;480p;;"
- ElseIf itag = 246 Then
- data = "webm;video;480p;;"
- ElseIf itag = 247 Then
- data = "webm;video;720p;;"
- ElseIf itag = 248 Then
- data = "webm;video;1080p;;"
- ElseIf itag = 249 Then
- data = "webm;audio;50k;;"
- ElseIf itag = 250 Then
- data = "webm;audio;70k;;"
- ElseIf itag = 251 Then
- data = "webm;audio;160k;;"
- ElseIf itag = 264 Then
- data = "mp4;video;1440p;;"
- ElseIf itag = 266 Then
- data = "mp4;video;2160p60;;"
- ElseIf itag = 271 Then
- data = "webm;video;1440p;;"
- ElseIf itag = 272 Then
- data = "webm;video;4320p;;"
- ElseIf itag = 278 Then
- data = "webm;video;144p;;"
- ElseIf itag = 298 Then
- data = "mp4;video;720p60;;"
- ElseIf itag = 299 Then
- data = "mp4;video;1080p60;;"
- ElseIf itag = 302 Then
- data = "webm;video;720p60;;"
- ElseIf itag = 303 Then
- data = "webm;video;1080p60;;"
- ElseIf itag = 308 Then
- data = "webm;video;1440p60;;"
- ElseIf itag = 313 Then
- data = "webm;video;2160p;;"
- ElseIf itag = 315 Then
- data = "webm;video;2160p60;;"
- ElseIf itag = 330 Then
- data = "webm;video;144p60;hdr;"
- ElseIf itag = 331 Then
- data = "webm;video;240p60;hdr;"
- ElseIf itag = 332 Then
- data = "webm;video;360p60;hdr;"
- ElseIf itag = 333 Then
- data = "webm;video;480p60;hdr;"
- ElseIf itag = 334 Then
- data = "webm;video;720p60;hdr;"
- ElseIf itag = 335 Then
- data = "webm;video;1080p60;hdr;"
- ElseIf itag = 336 Then
- data = "webm;video;1440p60;hdr;"
- ElseIf itag = 337 Then
- data = "webm;video;2160p60;hdr;"
- end if
- getInfoVideo = data
- end function
- Public function file_get_contents(filename)
- Dim objWinHttp: Set objWinHttp = createObject("MSXML2.ServerXMLHTTP")
- objWinHttp.Open "GET", filename, false
- objWinHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- objWinHttp.Send
- 'Response.Write objWinHttp.Status & " " & objWinHttp.StatusText
- file_get_contents = objWinHttp.ResponseText
- Set objWinHttp = Nothing
- end function
- Public function URLDecode(str)
- set list = CreateObject("System.Collections.ArrayList")
- strLen = Len(str)
- for i = 1 to strLen
- sT = mid(str, i, 1)
- if sT = "%" then
- if i + 2 <= strLen then
- list.Add cbyte("&H" & mid(str, i + 1, 2))
- i = i + 2
- end if
- else
- list.Add asc(sT)
- end if
- next
- depth = 0
- for each by in list.ToArray()
- if by and &h80 then
- if (by and &h40) = 0 then
- if depth = 0 then Err.Raise 5
- val = val * 2 ^ 6 + (by and &h3f)
- depth = depth - 1
- if depth = 0 then
- sR = sR & chrw(val)
- val = 0
- end if
- elseif (by and &h20) = 0 then
- if depth > 0 then Err.Raise 5
- val = by and &h1f
- depth = 1
- elseif (by and &h10) = 0 then
- if depth > 0 then Err.Raise 5
- val = by and &h0f
- depth = 2
- else
- Err.Raise 5
- end if
- else
- if depth > 0 then Err.Raise 5
- sR = sR & chrw(by)
- end if
- next
- if depth > 0 then Err.Raise 5
- URLDecode = sR
- End Function
- Public function HTMLDecode(encodedstring)
- Dim tmp, i
- tmp = encodedstring
- tmp = Replace( tmp, """, chr(34) )
- tmp = Replace( tmp, "<" , chr(60) )
- tmp = Replace( tmp, ">" , chr(62) )
- tmp = Replace( tmp, "&" , chr(38) )
- tmp = Replace( tmp, " ", chr(32) )
- For i = 1 to 255
- tmp = Replace( tmp, "&#" & i & ";", chr( i ) )
- Next
- HTMLDecode = tmp
- End Function
- Public function GetVideoTitle(Html)
- ' get rid of all tabs
- Html = Replace(Html, Chr(9), "")
- ' get rid of all newlines (vbscript regex engine doesn't like them)
- Html = Replace(Html, vbCrLf, "")
- Html = Replace(Html, vbLf, "")
- Html = Replace(Html, vbCr, "")
- GetVideoTitle = HTMLDecode(Replace(ExtractMatch(Html, "<title>([^<]+)<")," - YouTube",""))
- End Function
- Public function MkFileName(Titletm)
- dim Title
- Title = Replace(Titletm, "(", "")
- Title = Replace(Title, ")", "")
- Dim Regex
- Set Regex = New RegExp
- With Regex
- .Pattern = "[^A-Za-z0-9-_]"
- .Global = True
- End With
- Title = Regex.Replace(Title, "_")
- MkFileName = Title
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement