-
Notifications
You must be signed in to change notification settings - Fork 272
Open
Description
I am trying to create one bar or multiple ones for the length of the download list, I am using goroutines to download the list really fast.
as follows :
Inside the main
if soundData.Kind == "playlist" {
var wg sync.WaitGroup
plDownloadTracks := getPlaylistDownloadTracks(soundData, clientId)
for _, dlT := range plDownloadTracks {
wg.Add(1)
go func(dlT []soundcloud.DownloadTrack) {
defer wg.Done()
t := getTrack(dlT, true)
fp := soundcloud.Download(t, downloadPath)
// silent indication of already existing files
if fp == "" {
return
}
soundcloud.AddMetadata(t, fp)
}(dlT)
}
wg.Wait()
fmt.Printf("\n%s Playlist saved to : %s\n", theme.Green("[-]"), theme.Magenta(downloadPath))
return
}
and here is my Download
function :
func Download(track DownloadTrack, dlpath string) string {
trackName := track.SoundData.Title + "[" + track.Quality + "]." + track.Ext
path := validateDownload(dlpath, trackName)
resp, err := http.Get(track.Url)
if err != nil {
return ""
}
defer resp.Body.Close()
// check if the file exists
f, _ := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644)
defer f.Close()
// here I am using the progress bar from "github.com/schollz/progressbar/v3" but it doesn't support pools
bar := bar.DefaultBytes(
resp.ContentLength,
"Downloading",
)
io.Copy(io.MultiWriter(f, bar), resp.Body)
return path
}
Sorry for such a question but I searched the docs and I found nothing, I would really appreciate your help 😃
Metadata
Metadata
Assignees
Labels
No labels