You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, excuse my question I am still a beginner in go 馃槃
I am trying to stream the segments of the m3u8 into one file by appending to the file created, but unfortunately it's doesn't and returns empty file.
// extract the urls of the individual segment and then steam/download.funcdownloadSeg(wg*sync.WaitGroup, segment*m.MediaSegment, file*os.File, dlbar*bar.ProgressBar) {
deferwg.Done()
resp, err:=http.Get(segment.URI)
log.Println("Error : ", resp.StatusCode)
iferr!=nil {
log.Println("Error : ", err)
return
}
deferresp.Body.Close()
// append to the file_, err=io.Copy(io.MultiWriter(file, dlbar), resp.Body)
iferr!=nil {
log.Println("Error : ", err)
return
}
}
// using the goroutine to download each segment concurrently and wait till all finishedfuncdownloadM3u8(m3u8Urlstring, filepathstring) error {
resp, err:=http.Get(m3u8Url)
iferr!=nil {
returnerr
}
deferresp.Body.Close()
pl, listType, err:=m.DecodeFrom(resp.Body, true)
iferr!=nil {
returnerr
}
dlbar:=bar.DefaultBytes(resp.ContentLength, "Downloading")
// create a file to add content to// file, _ := os.OpenFile(filepath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)file, _:=os.Create(filepath)
// the go routine nowvarwg sync.WaitGroupswitchlistType {
casem.MEDIA:
mediapl:=pl.(*m.MediaPlaylist)
for_, segment:=rangemediapl.Segments {
ifsegment==nil {
continue
}
wg.Add(1)
godownloadSeg(&wg, segment, file, dlbar)
}
default:
returnerrors.New("Unsupported type!")
}
returnnil
}
I call downloadM3u8(track.Url, path) after that.
The text was updated successfully, but these errors were encountered:
I think you missed calling wg.Wait() in the end. hence , program is exiting even before all go routines are done. adding wg.Wait() before return nil, will help I guess.
Hello, excuse my question I am still a beginner in go 馃槃
I am trying to stream the segments of the
m3u8
into one file by appending to the file created, but unfortunately it's doesn't and returns empty file.I call
downloadM3u8(track.Url, path)
after that.The text was updated successfully, but these errors were encountered: