55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
|
package srarchive
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type EventRunListing struct {
|
||
|
LastUpdatedAt time.Time `json:"lastUpdatedAt"`
|
||
|
Videos []EventRun `json:"videos"`
|
||
|
}
|
||
|
|
||
|
type SourceVideoReference struct {
|
||
|
ID string
|
||
|
UpdatedAt time.Time `json:",omitempty"`
|
||
|
Start time.Duration `json:",omitempty"`
|
||
|
End time.Duration `json:",omitempty"`
|
||
|
}
|
||
|
|
||
|
type EventRun struct {
|
||
|
Duration time.Duration `json:"duration"`
|
||
|
DownloadFileName string `json:"downloadFileName"`
|
||
|
Title string `json:"title"`
|
||
|
Thumbnails map[SourceSetSpecifier]string `json:"thumbnails"`
|
||
|
SourceVideos []SourceVideoReference `json:"sourceVideos"`
|
||
|
|
||
|
// DEPRECATED - This used to be the file name used to provide the MP4
|
||
|
// download and was also used for thumbnail URL generation via Nginx HLS
|
||
|
// module. Thumbnails are now generated differently, use the Thumbnails map
|
||
|
// for that.
|
||
|
SupposedFileName string `json:"fileName"`
|
||
|
}
|
||
|
|
||
|
func (r *EventRun) UnmarshalJSON(b []byte) error {
|
||
|
// Decode real data
|
||
|
if err := json.Unmarshal(b, r); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// Check for Twitch video reference in old format
|
||
|
var v struct {
|
||
|
SourceVideoID string
|
||
|
SourceVideoStart, SourceVideoEnd int
|
||
|
}
|
||
|
if err := json.Unmarshal(b, &v); err == nil && len(v.SourceVideoID) > 0 {
|
||
|
// Convert to new format
|
||
|
r.SourceVideos = append(r.SourceVideos, SourceVideoReference{
|
||
|
ID: v.SourceVideoID,
|
||
|
Start: time.Duration(v.SourceVideoStart) * time.Second,
|
||
|
End: time.Duration(v.SourceVideoEnd) * time.Second,
|
||
|
})
|
||
|
}
|
||
|
return nil
|
||
|
}
|