mirror of
https://github.com/bytedream/vivo.git
synced 2025-05-10 04:35:08 +02:00
Added GetVideoWithProxy to obtain the video with a proxy
This commit is contained in:
parent
da5f7ef4a2
commit
4a22c18548
20
vivo.go
20
vivo.go
@ -1,7 +1,8 @@
|
|||||||
package vivo
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -19,10 +20,17 @@ type Vivo struct {
|
|||||||
Mime string
|
Mime string
|
||||||
Quality string
|
Quality string
|
||||||
Length int64
|
Length int64
|
||||||
|
|
||||||
|
client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVideo extracts the video url and some other nice information from a vivo.sx page
|
// GetVideo extracts the video url and some other nice information from a vivo.sx page
|
||||||
func GetVideo(URL string) (*Vivo, error) {
|
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) {
|
if !regexp.MustCompile("(vivo\\.sx/)(.*)(.{10}$)").MatchString(URL) {
|
||||||
return &Vivo{}, errors.New("Not a valid vivo.sx 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/", "/")
|
URL = strings.ReplaceAll(URL, "/embed/", "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := http.Get(URL)
|
response, err := proxy.Get(URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &Vivo{}, err
|
return &Vivo{}, err
|
||||||
}
|
}
|
||||||
@ -42,11 +50,13 @@ func GetVideo(URL string) (*Vivo, error) {
|
|||||||
return &Vivo{}, err
|
return &Vivo{}, err
|
||||||
}
|
}
|
||||||
bodyAsString := string(bodyAsBytes)
|
bodyAsString := string(bodyAsBytes)
|
||||||
|
fmt.Println(bodyAsString)
|
||||||
|
|
||||||
parameter := regexp.MustCompile("(?s)InitializeStream\\s*\\(\\s*({.+?})\\s*\\)\\s*;").FindString(bodyAsString)
|
parameter := regexp.MustCompile("(?s)InitializeStream\\s*\\(\\s*({.+?})\\s*\\)\\s*;").FindString(bodyAsString)
|
||||||
parameter = strings.NewReplacer("\n", "", "\t", "", "InitializeStream ({", "", "});", "", "'", "\"").Replace(strings.TrimSpace(parameter))
|
parameter = strings.NewReplacer("\n", "", "\t", "", "InitializeStream ({", "", "});", "", "'", "\"").Replace(strings.TrimSpace(parameter))
|
||||||
|
|
||||||
vivo := &Vivo{VivoURL: URL,
|
vivo := &Vivo{client: proxy,
|
||||||
|
VivoURL: URL,
|
||||||
ID: URL[strings.LastIndex(URL, "/")+1:],
|
ID: URL[strings.LastIndex(URL, "/")+1:],
|
||||||
Title: strings.TrimPrefix(strings.TrimSuffix(regexp.MustCompile(`<h1>(.*?)<strong>`).FindString(bodyAsString), " <strong>"), "<h1>Watch ")}
|
Title: strings.TrimPrefix(strings.TrimSuffix(regexp.MustCompile(`<h1>(.*?)<strong>`).FindString(bodyAsString), " <strong>"), "<h1>Watch ")}
|
||||||
|
|
||||||
@ -69,7 +79,7 @@ func GetVideo(URL string) (*Vivo, error) {
|
|||||||
videoURL := rot47(decodedURL)
|
videoURL := rot47(decodedURL)
|
||||||
vivo.VideoURL = videoURL
|
vivo.VideoURL = videoURL
|
||||||
|
|
||||||
video, err := http.Get(videoURL)
|
video, err := proxy.Get(videoURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vivo, nil
|
return vivo, nil
|
||||||
}
|
}
|
||||||
@ -83,7 +93,7 @@ func GetVideo(URL string) (*Vivo, error) {
|
|||||||
|
|
||||||
// Download downloads the video
|
// Download downloads the video
|
||||||
func (v Vivo) Download(destination io.Writer) error {
|
func (v Vivo) Download(destination io.Writer) error {
|
||||||
response, err := http.Get(v.VideoURL)
|
response, err := v.client.Get(v.VideoURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user