I made this simple Youtube to MP3 downloader and decided to share it
Note: Works only with IE 11 or newer
Code: Select all
#NoEnv
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := false
Gui, +AlwaysOnTop
Gui, Show, x200 y750 w465 h153, Youtube downloader by kovacevica00
Gui, Color, White
Gui, Font, s15, Courier New
Gui, Add, Text, x21 y16 w422 h27 +0x200, Please enter youtube song URL below:
Gui, Add, StatusBar
Gui, Font
Gui, Add, Edit, x11 y73 w442 h21 vURL,
Gui, Add, Button, Default x178 y107 w109 h22, OK
Gui, Add, Progress, vDProgress x11 y96 w442 h9 -Smooth
GuiControl, Focus, URL
Return
GuiClose:
pwb.quit()
ExitApp
return
F9:: ; To automatically select and copy URL from browser
clipboard =
Send, ^l
Sleep, 300
Send, ^c
If Clipboard =
{
Send, ^l
Sleep, 500
Send, ^c
}
ControlClick, OK, Youtube downloader by kovacevica00
Return
OnClipboardChange:
if RegExMatch(Clipboard, "^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/watch\?v=([^&]+)")
{
GuiControl,, URL, %Clipboard%
GuiControl, Focus, OK
}
Return
ButtonOK:
Gui, Submit, NoHide
if RegExMatch(URL, "^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/watch\?v=([^&]+)")
{
If IsObject(pwb)
{
GuiControl, Disable, URL
GuiControl, Disable, OK
SB_SetText("preparing download..")
GuiControl, , DProgress, 10
pwb.Navigate("https://ytmp3.cc/")
while pwb.busy or pwb.ReadyState !=4
sleep, 100
pwb.document.getElementById("input").value := URL
pwb.document.getElementById("submit").click()
while ((Inprogress := pwb.document.getElementById("file").href) = "https://ytmp3.cc/")
{
if ((CurrentStatus := pwb.document.getElementById("progress").innertext) = "checking video ")
{
SB_SetText(CurrentStatus)
GuiControl, , DProgress, 20
}
else if ((CurrentStatus := pwb.document.getElementById("progress").innertext) = "loading video ")
{
SB_SetText(CurrentStatus)
GuiControl, , DProgress, 30
}
else if ((CurrentStatus := pwb.document.getElementById("progress").innertext) = "converting video ")
{
SB_SetText(CurrentStatus)
GuiControl, , DProgress, 40
}
sleep, 100
}
GuiControl, , DProgress, 50
DirectUrl := pwb.document.getElementById("file").href
SongName := pwb.document.getElementById("title").innertext
SongName := strReplace(SongName,"|") ; Removes "|" as it is unsupported character
SongName := strReplace(SongName,":") ; Removes ":" as it is unsupported character
GuiControl, , DProgress, 70
SB_SetText("downloading, please wait...")
IfNotExist, %A_MyDocuments%\Music
FileCreateDir, %A_MyDocuments%\Music
URLDownloadToFile, %DirectUrl%,%A_MyDocuments%\Music\%SongName%.mp3
SB_SetText("download successful!")
GuiControl, , DProgress, 100
GuiControl,, URL
GuiControl, Enable, URL
GuiControl, Enable, OK
GuiControl, Focus, URL
}
else
{
MsgBox,0, Error. Internet explorer failed to initialize. Relaunching.
Reload
}
}
else
{
SB_SetText("Invalid URL")
GuiControl,,URL
GuiControl, Focus, URL
}
Sleep, 1500
GuiControl, , DProgress, 0
SB_SetText("")
return