Check streams response for videoplayback.

This commit is contained in:
Kavin 2023-08-20 20:13:36 +01:00
parent f822a8213d
commit fa6de143d9
No known key found for this signature in database
GPG Key ID: 6E4598CA5C92C41F
1 changed files with 36 additions and 2 deletions

38
main.go
View File

@ -48,6 +48,14 @@ type FrontendConfig struct {
RegistrationDisabled bool `json:"registrationDisabled"`
}
type PipedStreams struct {
Url string `json:"url"`
}
type Streams struct {
VideoStreams []PipedStreams `json:"videoStreams"`
}
var client = http.Client{
Timeout: 10 * time.Second,
}
@ -95,6 +103,23 @@ func getConfig(ApiUrl string) (FrontendConfig, error) {
return config, nil
}
func getStreams(ApiUrl string, VideoId string) (Streams, error) {
resp, err := testUrl(ApiUrl + "/streams/" + VideoId)
if err != nil {
return Streams{}, err
}
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return Streams{}, err
}
var streams Streams
err = json.Unmarshal(bytes, &streams)
if err != nil {
return Streams{}, err
}
return streams, nil
}
func getInstanceDetails(split []string, latest string) (Instance, error) {
ApiUrl := strings.TrimSpace(split[1])
@ -176,7 +201,16 @@ func getInstanceDetails(split []string, latest string) (Instance, error) {
go func() {
defer wg.Done()
// check if instance can fetch videos
if _, err := testUrl(ApiUrl + "/streams/jNQXAC9IVRw"); err != nil {
streams, err := getStreams(ApiUrl, "jNQXAC9IVRw")
if err != nil {
errorChannel <- err
return
}
if len(streams.VideoStreams) == 0 {
errorChannel <- errors.New("no streams")
}
// head request to check first stream
if _, err := testUrl(streams.VideoStreams[0].Url); err != nil {
errorChannel <- err
}
}()
@ -293,7 +327,7 @@ func monitorInstances() {
// update the global instances variable
monitored_instances = instances
}
resp.Body.Close()
_ = resp.Body.Close()
time.Sleep(time.Minute)
}
}