Updated regex to validate url and added vivo.st support

This commit is contained in:
ByteDream 2021-05-05 18:04:36 +02:00
parent 18472ec3d0
commit 7213c78bf5
2 changed files with 23 additions and 2 deletions

View File

@ -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
This project is licensed under the Mozilla Public Licence 2.0 (MPL-2.0) licence - see the [LICENSE](LICENCE) file for more details

22
vivo.go
View File

@ -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("^(?P<scheme>http(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/", "/")