mpvipc/chapter.go

27 lines
439 B
Go
Raw Normal View History

2023-12-20 20:50:11 +01:00
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
}