From ca0d96bab04ce36abe001fb07cf2c821568b4526 Mon Sep 17 00:00:00 2001 From: ByteDream Date: Fri, 27 Nov 2020 22:29:31 +0100 Subject: [PATCH] Added support for embedded videos --- vivo.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vivo.go b/vivo.go index 5dc0c83..1f9882b 100644 --- a/vivo.go +++ b/vivo.go @@ -10,10 +10,11 @@ import ( "strings" ) -//Vivo is the base struct where all information about a vivo.x video are saved +//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 @@ -22,10 +23,14 @@ type Vivo struct { // GetVideo extracts the video url and some other nice information from a vivo.sx page func GetVideo(URL string) (Vivo, error) { - if !regexp.MustCompile("(vivo\\.sx/)(.{10}$)").MatchString(URL) { + 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 := http.Get(URL) if err != nil { return Vivo{}, err @@ -42,6 +47,7 @@ func GetVideo(URL string) (Vivo, error) { 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(`

(.*?)`).FindString(bodyAsString), " "), "

Watch ")} for _, info := range strings.Split(parameter, ",") {