Skip to content

Commit

Permalink
main: 🔧 exit code, close #406 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
iawia002 committed Jun 7, 2019
1 parent 453c98c commit 80ccc1d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func printError(url string, err error) {
)
}

func download(videoURL string) {
func download(videoURL string) bool {
var (
domain string
err error
Expand All @@ -108,7 +108,7 @@ func download(videoURL string) {
u, err := url.ParseRequestURI(videoURL)
if err != nil {
printError(videoURL, err)
return
return true
}
domain = utils.Domain(u.Host)
}
Expand Down Expand Up @@ -162,19 +162,24 @@ func download(videoURL string) {
// if this error occurs, it means that an error occurred before actually starting to extract data
// (there is an error in the preparation step), and the data list is empty.
printError(videoURL, err)
return true
}
var isErr bool
for _, item := range data {
if item.Err != nil {
// if this error occurs, the preparation step is normal, but the data extraction is wrong.
// the data is an empty struct.
printError(item.URL, item.Err)
isErr = true
continue
}
err = downloader.Download(item, videoURL, config.ChunkSizeMB)
if err != nil {
printError(item.URL, err)
isErr = true
}
}
return isErr
}

func main() {
Expand Down Expand Up @@ -223,7 +228,13 @@ func main() {
config.Cookie = string(data)
}
}
var isErr bool
for _, videoURL := range args {
download(strings.TrimSpace(videoURL))
if err := download(strings.TrimSpace(videoURL)); err {
isErr = true
}
}
if isErr {
os.Exit(1)
}
}

0 comments on commit 80ccc1d

Please sign in to comment.