func DownloadSegment(c *http.Client, fn string, dlc chan *Download, recTime time.Duration) {
	var out, err = os.Create(fn)
	defer out.Close()

	if err != nil {
		log.Fatal(err)
		return
	}
	var (
		data       []byte
		aes128Keys = &map[string][]byte{}
	)

	for v := range dlc {
		req, err := http.NewRequest("GET", v.URI, nil)
		if err != nil {
			log.Fatal(err)
		}
		resp, err := c.Do(req)
		if err != nil {
			log.Print(err)
			continue
		}
		if resp.StatusCode != 200 {
			log.Printf("Received HTTP %v for %v\n", resp.StatusCode, v.URI)
			continue
		}

		data, _ = ioutil.ReadAll(resp.Body)
		resp.Body.Close()

		DecryptData(c, data, v, aes128Keys)

		_, err = out.Write(data)

		// _, err = io.Copy(out, resp.Body)
		if err != nil {
			log.Fatal(err)
		}

		log.Printf("Downloaded %v\n", v.URI)
		if recTime != 0 {
			log.Printf("Recorded %v of %v\n", v.totalDuration, recTime)
		} else {
			log.Printf("Recorded %v\n", v.totalDuration)
		}
	}
}
// DownloadSegment downloads the segment of the file
DownloadSegment downloads the segment of the file
// DownloadSegment downloads the segment of the file
func DownloadSegment(c *http.Client, fn string, dlc chan *Download, recTime time.Duration) {
	var out, err = os.Create(fn)
	defer out.Close()
	if err != nil {
		log.Fatal(err)
		return
	}
	var (
		data       []byte
		aes128Keys = &map[string][]byte{}
	)
	for v := range dlc {
		req, err := http.NewRequest("GET", v.URI, nil)
		if err != nil {
			log.Fatal(err)
		}
		resp, err := c.Do(req)
		if err != nil {
			log.Print(err)
			continue
		}
		if resp.StatusCode != 200 {
			log.Printf("Received HTTP %v for %v\n", resp.StatusCode, v.URI)
			continue
		}
		data, _ = ioutil.ReadAll(resp.Body)
		resp.Body.Close()
		DecryptData(c, data, v, aes128Keys)
		_, err = out.Write(data)
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("Downloaded %v\n", v.URI)
		if recTime != 0 {
			log.Printf("Recorded %v of %v\n", v.totalDuration, recTime)
		} else {
			log.Printf("Recorded %v\n", v.totalDuration)
		}
	}
}
func DownloadSegment ( c * http . Client , fn string , dlc chan * Download , recTime time . Duration ) { var out , err = os . Create ( fn ) defer out . Close ( ) if err != nil { log . Fatal ( err ) return } var ( data [ ] byte aes128Keys = & map [ string ] [ ] byte { } ) for v := range dlc { req , err := http . NewRequest ( " " , v . URI , nil ) if err != nil { log . Fatal ( err ) } resp , err := c . Do ( req ) if err != nil { log . Print ( err ) continue } if resp . StatusCode != 200 { log . Printf ( " \n " , resp . StatusCode , v . URI ) continue } data , _ = ioutil . ReadAll ( resp . Body ) resp . Body . Close ( ) DecryptData ( c , data , v , aes128Keys ) _ , err = out . Write ( data ) if err != nil { log . Fatal ( err ) } log . Printf ( " \n " , v . URI ) if recTime != 0 { log . Printf ( " \n " , v . totalDuration , recTime ) } else { log . Printf ( " \n " , v . totalDuration ) } } }
DownloadSegment downloads the segment of the file
DownloadSegment downloads the segment of the file
// _, err = io.Copy(out, resp.Body)