Jump to content

GUI Case, make it start the Case from the beginning


 Share

Recommended Posts

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?

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 $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 by Jos
added codebox
Link to comment
Share on other sites

@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.

#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 by Belini
Link to comment
Share on other sites

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...