package vivo import ( "errors" "fmt" "io" "io/ioutil" "net/http" "net/url" "regexp" "strings" ) //Vivo is the base struct where all information about a vivo.sx video are saved type Vivo struct { VivoURL string VideoURL string ID string Title string Mime string Quality string Length int64 client *http.Client } // GetVideo extracts the video url and some other nice information from a vivo.sx page func GetVideo(URL string) (*Vivo, error) { return GetVideoWithProxy(URL, http.DefaultClient) } // GetVideoWithProxy extracts the video url and some other nice information from a vivo.sx page with a pre defined proxy func GetVideoWithProxy(URL string, proxy *http.Client) (*Vivo, error) { if !regexp.MustCompile("(vivo\\.sx/)(.*)(.{10}$)").MatchString(URL) { return &Vivo{}, errors.New("Not a valid vivo.sx url") } if strings.Contains(URL, "/embed/") { URL = strings.ReplaceAll(URL, "/embed/", "/") } response, err := proxy.Get(URL) if err != nil { return &Vivo{}, err } defer response.Body.Close() bodyAsBytes, err := ioutil.ReadAll(response.Body) if err != nil { return &Vivo{}, err } bodyAsString := string(bodyAsBytes) fmt.Println(bodyAsString) parameter := regexp.MustCompile("(?s)InitializeStream\\s*\\(\\s*({.+?})\\s*\\)\\s*;").FindString(bodyAsString) parameter = strings.NewReplacer("\n", "", "\t", "", "InitializeStream ({", "", "});", "", "'", "\"").Replace(strings.TrimSpace(parameter)) vivo := &Vivo{client: proxy, VivoURL: URL, ID: URL[strings.LastIndex(URL, "/")+1:], Title: strings.TrimPrefix(strings.TrimSuffix(regexp.MustCompile(`