Skip to content

Commit

Permalink
download: allow to specify a password
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelcadilhac authored Oct 5, 2024
1 parent 6ce8c85 commit 5ddef54
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions cli/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type args struct {
Url string
Output string
Path string
Password string
Silent bool
Force bool
Info bool
Expand Down
4 changes: 2 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -52,4 +52,4 @@ func Eval(opts map[string]interface{}) (err error) {
io.Copy(writer, resp.Body)
}
return
}
}
4 changes: 3 additions & 1 deletion transfer/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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 {
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions wedl.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ Usage:
wedl [options] <URL>
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)
Expand Down

0 comments on commit 5ddef54

Please sign in to comment.