package xvideos import ( "fmt" "strings" "sync" "github.com/iawia002/annie/downloader" "github.com/iawia002/annie/request" "github.com/iawia002/annie/utils" ) const ( lowFlag = "html5player.setVideoUrlLow('" lowFinalFlag = `'); html5player.setVideoUrlHigh(` highFlag = "html5player.setVideoUrlHigh('" highFinalFlag = `'); html5player.setVideoHLS(` qualityLow = "low" qualityHigh = "high" ) var ( lowFlagLength = len(lowFlag) highFlagLength = len(highFlag) ) type src struct { url string quality string } func getSrc(html string) []*src { var wg sync.WaitGroup wg.Add(4) startIndexLow := 0 go func() { startIndexLow = strings.Index(html, lowFlag) startIndexLow += lowFlagLength wg.Done() }() endIndexLow := 0 go func() { endIndexLow = strings.Index(html, lowFinalFlag) wg.Done() }() startIndexHigh := 0 go func() { startIndexHigh = strings.Index(html, highFlag) startIndexHigh += highFlagLength wg.Done() }() endIndexHigh := 0 go func() { endIndexHigh = strings.Index(html, highFinalFlag) wg.Done() }() wg.Wait() var srcs []*src if startIndexLow != -1 { srcs = append(srcs, &src{ url: html[startIndexLow:endIndexLow], quality: qualityLow, }) } if startIndexHigh != -1 { srcs = append(srcs, &src{ url: html[startIndexHigh:endIndexHigh], quality: qualityHigh, }) } return srcs } // Extract is the main function for extracting data func Extract(url string) ([]downloader.Data, error) { html, err := request.Get(url, url, nil) if err != nil { return nil, err } var title string desc := utils.MatchOneOf(html, `