mpvipc/chapter.go

27 lines
439 B
Go

package mpvipc
import (
"encoding/json"
"time"
)
type Chapter struct {
Title string `json:"title"`
Time time.Duration `json:"time"`
}
func (c *Chapter) UnmarshalJSON(data []byte) error {
m := &struct {
Title string `json:"title"`
Time float64 `json:"time"`
}{}
if err := json.Unmarshal(data, m); err != nil {
return err
}
c.Title = m.Title
c.Time = time.Duration(m.Time * float64(time.Second))
return nil
}