func GetPlaylist(c *http.Client, urlStr string, recTime time.Duration, useLocalTime bool, dlc chan *Download, wg *sync.WaitGroup) {
	startTime := time.Now()
	var recDuration time.Duration = 0
	cache, _ := lru.New(1024)
	playlistURL, err := url.Parse(urlStr)
	if err != nil {
		log.Fatal(err)
	}
	for {
		req, err := http.NewRequest("GET", urlStr, nil)
		if err != nil {
			log.Fatal(err)
		}
		resp, err := c.Do(req)
		if err != nil {
			log.Print(err)
			time.Sleep(time.Duration(3) * time.Second)
		}
		playlist, listType, err := m3u8.DecodeFrom(resp.Body, true)
		if err != nil {
			log.Fatal(err)
		}
		resp.Body.Close()
		if listType == m3u8.MEDIA {
			mpl := playlist.(*m3u8.MediaPlaylist)

			for segmentIndex, v := range mpl.Segments {
				if v != nil {
					var msURI string
					if strings.HasPrefix(v.URI, "http") {
						msURI, err = url.QueryUnescape(v.URI)
						if err != nil {
							log.Fatal(err)
						}
					} else {
						msURL, err := playlistURL.Parse(v.URI)
						if err != nil {
							log.Print(err)
							continue
						}
						msURI, err = url.QueryUnescape(msURL.String())
						if err != nil {
							log.Fatal(err)
						}
					}
					_, hit := cache.Get(msURI)
					if !hit {
						cache.Add(msURI, nil)
						if useLocalTime {
							recDuration = time.Now().Sub(startTime)
						} else {
							recDuration += time.Duration(int64(v.Duration * 1000000000))
						}
						dlc <- &Download{
							URI:           msURI,
							ExtXKey:       mpl.Key,
							SeqNo:         uint64(segmentIndex) + mpl.SeqNo,
							totalDuration: recDuration,
						}
					}
					if recTime != 0 && recDuration != 0 && recDuration >= recTime {
						close(dlc)
						return
					}
				}
			}
			if mpl.Closed {
				close(dlc)
				return
			}
			time.Sleep(time.Duration(int64(mpl.TargetDuration * 1000000000)))

		} else {
			log.Fatal("Not a valid media playlist")
		}
	}
}
// GetPlaylist gets the playlist data
GetPlaylist gets the playlist data
// GetPlaylist gets the playlist data
func GetPlaylist(c *http.Client, urlStr string, recTime time.Duration, useLocalTime bool, dlc chan *Download, wg *sync.WaitGroup) {
	startTime := time.Now()
	var recDuration time.Duration = 0
	cache, _ := lru.New(1024)
	playlistURL, err := url.Parse(urlStr)
	if err != nil {
		log.Fatal(err)
	}
	for {
		req, err := http.NewRequest("GET", urlStr, nil)
		if err != nil {
			log.Fatal(err)
		}
		resp, err := c.Do(req)
		if err != nil {
			log.Print(err)
			time.Sleep(time.Duration(3) * time.Second)
		}
		playlist, listType, err := m3u8.DecodeFrom(resp.Body, true)
		if err != nil {
			log.Fatal(err)
		}
		resp.Body.Close()
		if listType == m3u8.MEDIA {
			mpl := playlist.(*m3u8.MediaPlaylist)
			for segmentIndex, v := range mpl.Segments {
				if v != nil {
					var msURI string
					if strings.HasPrefix(v.URI, "http") {
						msURI, err = url.QueryUnescape(v.URI)
						if err != nil {
							log.Fatal(err)
						}
					} else {
						msURL, err := playlistURL.Parse(v.URI)
						if err != nil {
							log.Print(err)
							continue
						}
						msURI, err = url.QueryUnescape(msURL.String())
						if err != nil {
							log.Fatal(err)
						}
					}
					_, hit := cache.Get(msURI)
					if !hit {
						cache.Add(msURI, nil)
						if useLocalTime {
							recDuration = time.Now().Sub(startTime)
						} else {
							recDuration += time.Duration(int64(v.Duration * 1000000000))
						}
						dlc <- &Download{
							URI:           msURI,
							ExtXKey:       mpl.Key,
							SeqNo:         uint64(segmentIndex) + mpl.SeqNo,
							totalDuration: recDuration,
						}
					}
					if recTime != 0 && recDuration != 0 && recDuration >= recTime {
						close(dlc)
						return
					}
				}
			}
			if mpl.Closed {
				close(dlc)
				return
			}
			time.Sleep(time.Duration(int64(mpl.TargetDuration * 1000000000)))
		} else {
			log.Fatal("Not a valid media playlist")
		}
	}
}
func GetPlaylist ( c * http . Client , urlStr string , recTime time . Duration , useLocalTime bool , dlc chan * Download , wg * sync . WaitGroup ) { startTime := time . Now ( ) var recDuration time . Duration = 0 cache , _ := lru . New ( 1024 ) playlistURL , err := url . Parse ( urlStr ) if err != nil { log . Fatal ( err ) } for { req , err := http . NewRequest ( " " , urlStr , nil ) if err != nil { log . Fatal ( err ) } resp , err := c . Do ( req ) if err != nil { log . Print ( err ) time . Sleep ( time . Duration ( 3 ) * time . Second ) } playlist , listType , err := m3u8 . DecodeFrom ( resp . Body , true ) if err != nil { log . Fatal ( err ) } resp . Body . Close ( ) if listType == m3u8 . MEDIA { mpl := playlist . ( * m3u8 . MediaPlaylist ) for segmentIndex , v := range mpl . Segments { if v != nil { var msURI string if strings . HasPrefix ( v . URI , " " ) { msURI , err = url . QueryUnescape ( v . URI ) if err != nil { log . Fatal ( err ) } } else { msURL , err := playlistURL . Parse ( v . URI ) if err != nil { log . Print ( err ) continue } msURI , err = url . QueryUnescape ( msURL . String ( ) ) if err != nil { log . Fatal ( err ) } } _ , hit := cache . Get ( msURI ) if ! hit { cache . Add ( msURI , nil ) if useLocalTime { recDuration = time . Now ( ) . Sub ( startTime ) } else { recDuration += time . Duration ( int64 ( v . Duration * 1000000000 ) ) } dlc <- & Download { URI : msURI , ExtXKey : mpl . Key , SeqNo : uint64 ( segmentIndex ) + mpl . SeqNo , totalDuration : recDuration , } } if recTime != 0 && recDuration != 0 && recDuration >= recTime { close ( dlc ) return } } } if mpl . Closed { close ( dlc ) return } time . Sleep ( time . Duration ( int64 ( mpl . TargetDuration * 1000000000 ) ) ) } else { log . Fatal ( " " ) } } }
GetPlaylist gets the playlist data
GetPlaylist gets the playlist data