videopage/video.go

40 lines
859 B
Go

package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
)
type Video struct {
Name string `json:"name"`
DisplayName string `json:"display_name"`
ID string `json:"id"`
Size int64 `json:"size"`
}
type VideoIndex struct {
Success bool `json:"success"`
Generation int `json:"generation"`
Count int `json:"count"`
Videos []Video `json:"videos"`
}
func readVideoInfo(filepath string) (video Video, err error) {
if !strings.HasSuffix(filepath, ".json") {
filepath = filepath + ".json"
}
infoRaw, err := ioutil.ReadFile(filepath)
if err != nil {
err = fmt.Errorf("can't read infofile \"%s\": %s", filepath, err.Error())
return
}
err = json.Unmarshal(infoRaw, &video)
if err != nil {
err = fmt.Errorf("can't read infofile \"%s\": %s", filepath, err.Error())
return
}
return
}