From 5ddef543f270adaa0bf855aa364a22b8d1d2c1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Cadilhac?= Date: Sat, 5 Oct 2024 11:14:37 -0500 Subject: [PATCH] download: allow to specify a password --- cli/args.go | 1 + cli/cli.go | 4 ++-- transfer/download.go | 4 +++- wedl.go | 15 ++++++++------- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cli/args.go b/cli/args.go index 88e11fc..539bb0c 100644 --- a/cli/args.go +++ b/cli/args.go @@ -8,6 +8,7 @@ type args struct { Url string Output string Path string + Password string Silent bool Force bool Info bool diff --git a/cli/cli.go b/cli/cli.go index 3ef8969..47ff2b8 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -16,7 +16,7 @@ func Eval(opts map[string]interface{}) (err error) { if err != nil { return } - resp, r, err := transfer.GetDlResponse(parsed.Url) + resp, r, err := transfer.GetDlResponse(parsed.Url, parsed.Password) if err != nil { return } @@ -52,4 +52,4 @@ func Eval(opts map[string]interface{}) (err error) { io.Copy(writer, resp.Body) } return -} \ No newline at end of file +} diff --git a/transfer/download.go b/transfer/download.go index be14390..b3d478b 100644 --- a/transfer/download.go +++ b/transfer/download.go @@ -19,6 +19,7 @@ type headers map[string]string type requestData struct { SecurityHash string `json:"security_hash"` + Password string `json:"password"` RecipientId string `json:"recipient_id,omitempty"` Intent string `json:"intent"` } @@ -35,7 +36,7 @@ type DlResponse struct { DlFilename string `json:"dl_filename"` } -func GetDlResponse(URL string) (resp *http.Response, r DlResponse, err error) { +func GetDlResponse(URL string, password string) (resp *http.Response, r DlResponse, err error) { client := &http.Client{} req, err := createRequest("GET", URL, nil, nil) if err != nil { @@ -49,6 +50,7 @@ func GetDlResponse(URL string) (resp *http.Response, r DlResponse, err error) { if err != nil { return } + data.reqData.Password = password link, err := getDownloadLink(client, data) if err != nil { return diff --git a/wedl.go b/wedl.go index addd831..9a3a809 100644 --- a/wedl.go +++ b/wedl.go @@ -35,13 +35,14 @@ Usage: wedl [options] Options: - -h --help Show this screen. - -v --version Print version and exit. - -o FILE --output=FILE Output file. Use - for stdout. - -p PATH --path=PATH Downloaded files directory. - -s --silent Silent. Do not output anything to stderr. - -f --force Overwrite files if needed. - -i --info Write download info to stdout and exit. + -h --help Show this screen. + -v --version Print version and exit. + -o FILE --output=FILE Output file. Use - for stdout. + -p PATH --path=PATH Downloaded files directory. + -P PASS --password=PASS Use a password. + -s --silent Silent. Do not output anything to stderr. + -f --force Overwrite files if needed. + -i --info Write download info to stdout and exit. ` opts, _ := docopt.ParseArgs(usage, os.Args[1:], resolveVersion()) err := cli.Eval(opts)