Chantaro Posted February 8, 2021 Share Posted February 8, 2021 (edited) Hello Everyone, first time poster here. I'm trying to make a GUI for youtube-dl and I'm stuck with the error handling for when the Input is empty. What I want to happen is, when there's an Empty URL it gives a MsgBox with "please insert a link" and execute the download when a url is in place. But for some reason when the url is empty and I click the button to run the command, it gives me the error over and over even though I enter something into the URL after the first Error message. What is wrong here? expandcollapse popupGlobal $ytdl_path = (@ScriptDir & "\youtube-dl.exe") Global $argsmp3 = (' --extract-audio --format=bestaudio --audio-format mp3 --audio-quality=320k --output "%(title)s.%(ext)s" --cookies .\cookies.txt') Global $argsmp4 = (' --format=bestaudio --output "%(title)s.%(ext)s" --cookies .\cookies.txt') Global $empty = "" ;https://youtu.be/HQnC1UHBvWA #Region GUI YoutubeDL() Func YoutubeDL() ; Create a GUI with various controls. Global $hGUI = GUICreate("YouTube Downloader",400, 200,1000,500) Global $Label1 = GUICtrlCreateLabel("Insert Youtube link here", 10, 45, 461, 24) GUICtrlSetFont(-1, 10, 200, 0, "Arial") Global $Pic1 = GUICtrlCreatePic(@ScriptDir & "\eXLs5Hw.jpg", 10, 10, 120, 30) Global $video_url = GUICtrlCreateInput("", 10, 70, 370, 20) Global $idConvertMP3 = GUICtrlCreateButton("Convert to MP3", 10, 100, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idConvertMP3 $video_url = GUICtrlRead($video_url) If $video_url = $empty Then MsgBox(0, "Error", "Please insert a Link") EndIf If $video_url <> $empty Then ConvertMP3() EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc #EndRegion ;Run Conversion Func ConvertMP3() Run($ytdl_path & " " & $video_url & $argsmp3) EndFunc Edited February 8, 2021 by Jos added codebox Link to comment Share on other sites More sharing options...
Belini Posted February 8, 2021 Share Posted February 8, 2021 (edited) @Chantaro welcome to the forum, the problem is that you used the same variable to identify the input and to read its content, use another name to get the link. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $ytdl_path = (@ScriptDir & "\youtube-dl.exe") Global $argsmp3 = (' --extract-audio --format=bestaudio --audio-format mp3 --audio-quality=320k --output "%(title)s.%(ext)s" --cookies .\cookies.txt') Global $argsmp4 = (' --format=bestaudio --output "%(title)s.%(ext)s" --cookies .\cookies.txt') Global $link = "https://youtu.be/HQnC1UHBvWA" #region GUI YoutubeDL() Func YoutubeDL() Local $empty = "" ; Create a GUI with various controls. Local $hGUI = GUICreate("YouTube Downloader", 400, 200, 1000, 500) Local $Label1 = GUICtrlCreateLabel("Insert Youtube link here", 10, 45, 461, 24) GUICtrlSetFont(-1, 10, 200, 0, "Arial") Local $Pic1 = GUICtrlCreatePic(@ScriptDir & "\eXLs5Hw.jpg", 10, 10, 120, 30) Local $video_url = GUICtrlCreateInput($link, 10, 70, 370, 20) Local $idConvertMP3 = GUICtrlCreateButton("Convert to MP3", 10, 100, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idConvertMP3 $link = GUICtrlRead($video_url) If $link = $empty Then MsgBox(0, "Error", "Please insert a Link") Else ConvertMP3() EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>YoutubeDL #endregion GUI ;Run Conversion Func ConvertMP3() Run($ytdl_path & " " & $link & $argsmp3) EndFunc ;==>ConvertMP3 Edited February 8, 2021 by Belini Subz 1 My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ Link to comment Share on other sites More sharing options...
Chantaro Posted February 8, 2021 Author Share Posted February 8, 2021 You're a life saver, thank you! And excuse the formatting I found out how to do that after posting ^^' Link to comment Share on other sites More sharing options...
Belini Posted February 8, 2021 Share Posted February 8, 2021 (edited) I'm glad I helped you. Edited February 8, 2021 by Belini My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now