diff --git a/vivo.go b/vivo.go index d82c03b..061504f 100644 --- a/vivo.go +++ b/vivo.go @@ -1,7 +1,8 @@ -package vivo +package main import ( "errors" + "fmt" "io" "io/ioutil" "net/http" @@ -19,10 +20,17 @@ type Vivo struct { 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") } @@ -31,7 +39,7 @@ func GetVideo(URL string) (*Vivo, error) { URL = strings.ReplaceAll(URL, "/embed/", "/") } - response, err := http.Get(URL) + response, err := proxy.Get(URL) if err != nil { return &Vivo{}, err } @@ -42,13 +50,15 @@ func GetVideo(URL string) (*Vivo, error) { 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{VivoURL: URL, - ID: URL[strings.LastIndex(URL, "/")+1:], - Title: strings.TrimPrefix(strings.TrimSuffix(regexp.MustCompile(`