diff --git a/README.md b/README.md index fe9b702..91bf3f1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # vivo A very simple tool to get the video url and some other stuff from a [vivo.sx](https://vivo.sx) video. +The alternative domain [vivo.st](https://vivo.st) is also supported. Only tested on linux, but should work on Mac and Windows too. @@ -35,4 +36,4 @@ func main() { ## License -This project is licensed under the Mozilla Public Licence 2.0 (MPL-2.0) licence - see the [LICENSE](LICENCE) file for more details \ No newline at end of file +This project is licensed under the Mozilla Public Licence 2.0 (MPL-2.0) licence - see the [LICENSE](LICENCE) file for more details diff --git a/vivo.go b/vivo.go index ae3dc8a..4c9a1a5 100644 --- a/vivo.go +++ b/vivo.go @@ -30,9 +30,29 @@ func GetVideo(URL string) (*Vivo, error) { // 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) { + var scheme string + + re := regexp.MustCompile("^(?Phttp(s?)://)?vivo\\.(sx|st)/(|embed/).{10}(/|$)") + groupNames := re.SubexpNames() + reMatch := re.FindAllStringSubmatch(URL, 1) + + if len(reMatch) == 0 { return &Vivo{}, errors.New("Not a valid vivo.sx url") + } else { + for _, match := range reMatch { + for i, content := range match { + if groupNames[i] == "scheme" { + scheme = content + break + } + } + } } + if scheme == "" { + URL = "https://" + URL + } + + //return &Vivo{}, errors.New("Not a valid vivo.sx url") if strings.Contains(URL, "/embed/") { URL = strings.ReplaceAll(URL, "/embed/", "/")