mirror of
https://github.com/bytedream/vivo.git
synced 2025-05-09 20:25:09 +02:00
Updated regex to validate url and added vivo.st support
This commit is contained in:
parent
18472ec3d0
commit
7213c78bf5
@ -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
22
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("^(?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/", "/")
|
||||
|
Loading…
x
Reference in New Issue
Block a user