Little script does nothing probably syntax error

I wrote a little script because my girlfriend recently switched to linux and I wanted to make it easy for her to use youtube-dl. Anyways trying to make a little go script I met a roadblock that is probably just my stupidity, because the code does nothing. I suspect that the problem is me trying to add the name variable to the command and doing it wrong

package main 

    import ( "os"
     "os/exec"
     "log" 
    "http://github.com/tcnksm/go-input"
     )

         func main() {
         ui := &input.UI{
         Writer: os.Stdout, 
         Reader: os.Stdin, 
        } 
        query := "Please paste the link of the playlist" 
        name, err := ui.Ask(query, &input.Options{ 
        Required: true,
         }) if err != nil {
         log.Fatal(err)} 
        exec.Command("youtube-dl -v -x -i --yes-playlist " + name ) 
        }
  1. Import pathes do not require a schema, so its just github.com/tcnksm/go-input
  2. There are some & where you only need to have a &
  3. Before the if err != nil … a line break was missing

All of these are hinted at when reading the error messages spit out by the compiler.

actually I just pasted wrong the line brake was there, and I am not actually getting an error by the compiler, it works, it just does nothing

Assuming there are no syntax errors (not even the HTTP one), then your program (not script) does create a command, but never Run()s it.

1 Like

Hi Jonathan,

This may help:

package main 

import (
        "os"
        "os/exec"
        "log" 
        "github.com/tcnksm/go-input"
)

func main() {
        ui := &input.UI {
                Writer: os.Stdout, 
                Reader: os.Stdin, 
        } 
        query := "Please paste the link of the playlist" 
        name, err := ui.Ask(query, &input.Options{ Required: true, })
        if err != nil {
                log.Fatal(err)
        }

        command_name := "youtube-dl"

        command_args := []string {
                "-v",
                "-x",
                "-i",
                "--yes-playlist",
                name,
                }

        cmd := exec.Command(command_name, command_args...) 
        err = cmd.Run()
        if err != nil { log.Printf("err = %v\n",err) }
}

I tried it with the arguments you used, and got a video with just audio, no picture. So if that happens, try different arguments for the youtube-dl command.