func DownloadStream(c *http.Client, auth AuthConfig, url string, resolution string, ep Episode, wg *sync.WaitGroup) error {
	defer wg.Done()
	req, err := http.NewRequest(http.MethodGet, url, nil)

	if err != nil {
		return err
	}

	req.Header.Add("User-Agent", common.UserAgent)

	resp, err := c.Do(req)

	if err != nil {
		return err
	}

	defer resp.Body.Close()

	os.Mkdir("./downloads", 0755)
	os.Mkdir("./downloads/"+common.FormatTitle(ep.SeriesTitle), 0755)
	os.Mkdir("./downloads/"+common.FormatTitle(ep.SeriesTitle)+"/"+common.FormatTitle(ep.SeasonTitle), 0755)
	filePath := "./downloads/" + common.FormatTitle(ep.SeriesTitle) + "/" + common.FormatTitle(ep.SeasonTitle) + "/" + common.FormatTitle(ep.SeriesTitle) + ".s" + strconv.Itoa(ep.SeasonNumber) + ".e" + strconv.Itoa(ep.EpisodeNumber) + "." + common.FormatTitle(ep.Title) + ".ts"

	p, listType, err := m3u8.DecodeFrom(bufio.NewReader(resp.Body), true)

	if err != nil {
		return err
	}

	if listType == m3u8.MASTER {
		masterpl := p.(*m3u8.MasterPlaylist)

		if resolution != "" {
			for i, variant := range masterpl.Variants {
				if variant.Resolution == resolution {
					msChan := make(chan *Download, 1024)
					go GetPlaylist(c, masterpl.Variants[i].URI, 0, true, msChan, wg)
					DownloadSegment(c, filePath, msChan, 0)
					break
				}
			}
		} else {
			msChan := make(chan *Download, 1024)
			go GetPlaylist(c, masterpl.Variants[0].URI, 0, true, msChan, wg)
			DownloadSegment(c, filePath, msChan, 0)
		}

	}
	return nil
}
// DownloadStream downloads the given stream url
DownloadStream downloads the given stream url
// DownloadStream downloads the given stream url
func DownloadStream(c *http.Client, auth AuthConfig, url string, resolution string, ep Episode, wg *sync.WaitGroup) error {
	defer wg.Done()
	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		return err
	}
	req.Header.Add("User-Agent", common.UserAgent)
	resp, err := c.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	os.Mkdir("./downloads", 0755)
	os.Mkdir("./downloads/"+common.FormatTitle(ep.SeriesTitle), 0755)
	os.Mkdir("./downloads/"+common.FormatTitle(ep.SeriesTitle)+"/"+common.FormatTitle(ep.SeasonTitle), 0755)
	filePath := "./downloads/" + common.FormatTitle(ep.SeriesTitle) + "/" + common.FormatTitle(ep.SeasonTitle) + "/" + common.FormatTitle(ep.SeriesTitle) + ".s" + strconv.Itoa(ep.SeasonNumber) + ".e" + strconv.Itoa(ep.EpisodeNumber) + "." + common.FormatTitle(ep.Title) + ".ts"
	p, listType, err := m3u8.DecodeFrom(bufio.NewReader(resp.Body), true)
	if err != nil {
		return err
	}
	if listType == m3u8.MASTER {
		masterpl := p.(*m3u8.MasterPlaylist)
		if resolution != "" {
			for i, variant := range masterpl.Variants {
				if variant.Resolution == resolution {
					msChan := make(chan *Download, 1024)
					go GetPlaylist(c, masterpl.Variants[i].URI, 0, true, msChan, wg)
					DownloadSegment(c, filePath, msChan, 0)
					break
				}
			}
		} else {
			msChan := make(chan *Download, 1024)
			go GetPlaylist(c, masterpl.Variants[0].URI, 0, true, msChan, wg)
			DownloadSegment(c, filePath, msChan, 0)
		}
	}
	return nil
}
func DownloadStream ( c * http . Client , auth AuthConfig , url string , resolution string , ep Episode , wg * sync . WaitGroup ) error { defer wg . Done ( ) req , err := http . NewRequest ( http . MethodGet , url , nil ) if err != nil { return err } req . Header . Add ( " " , common . UserAgent ) resp , err := c . Do ( req ) if err != nil { return err } defer resp . Body . Close ( ) os . Mkdir ( " " , 0755 ) os . Mkdir ( " " + common . FormatTitle ( ep . SeriesTitle ) , 0755 ) os . Mkdir ( " " + common . FormatTitle ( ep . SeriesTitle ) + " " + common . FormatTitle ( ep . SeasonTitle ) , 0755 ) filePath := " " + common . FormatTitle ( ep . SeriesTitle ) + " " + common . FormatTitle ( ep . SeasonTitle ) + " " + common . FormatTitle ( ep . SeriesTitle ) + " " + strconv . Itoa ( ep . SeasonNumber ) + " " + strconv . Itoa ( ep . EpisodeNumber ) + " " + common . FormatTitle ( ep . Title ) + " " p , listType , err := m3u8 . DecodeFrom ( bufio . NewReader ( resp . Body ) , true ) if err != nil { return err } if listType == m3u8 . MASTER { masterpl := p . ( * m3u8 . MasterPlaylist ) if resolution != " " { for i , variant := range masterpl . Variants { if variant . Resolution == resolution { msChan := make ( chan * Download , 1024 ) go GetPlaylist ( c , masterpl . Variants [ i ] . URI , 0 , true , msChan , wg ) DownloadSegment ( c , filePath , msChan , 0 ) break } } } else { msChan := make ( chan * Download , 1024 ) go GetPlaylist ( c , masterpl . Variants [ 0 ] . URI , 0 , true , msChan , wg ) DownloadSegment ( c , filePath , msChan , 0 ) } } return nil }
DownloadStream downloads the given stream url
DownloadStream downloads the given stream url