-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.go
102 lines (90 loc) · 2.66 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"fmt"
"time"
)
type AppConfig struct {
duration int // in days
libretimeURL string
websiteURL string
listenAddr string
}
type LocalTime struct {
time.Time
}
func (t *LocalTime) UnmarshalJSON(b []byte) error {
_, offset := time.Now().Local().Zone()
s := string(b)
// get rid of leading and trailing " from JSON"
s = s[1 : len(s)-1]
// replace " " with "T" so it works for LibreTime as well as web
s = s[0:10] + `T` + s[11:]
// add local zone to the end ssince we always work with local time
s = fmt.Sprintf("%s+%02d00", s, offset/3600)
p, err := time.Parse(`2006-01-02T15:04:05Z0700`, s)
if err != nil {
return err
}
t.Time = p
return nil
}
func (t *LocalTime) GetTime() time.Time {
return time.Time(t.Time)
}
type WebsiteEventOrganizerCalendarEvent struct {
AllDay bool `json:"allDay"`
Category []string `json:"category"`
ClassName []string `json:"className"`
Description string `json:"description"`
End LocalTime `json:"end"`
Organiser int `json:"organiser"`
Start LocalTime `json:"start"`
Tags []string `json:"tags"`
TextColor string `json:"textColor"`
Title string `json:"title"`
URL string `json:"url"`
}
type LibreTimeLiveInfoV2Show struct {
Name string `json:"name"`
Description string `json:"description"`
Genre string `json:"genre"`
ID int `json:"id"`
InstanceID int `json:"instance_id"`
Record int `json:"record"`
URL string `json:"url"`
ImagePath string `json:"image_path"`
Starts LocalTime `json:"starts"`
Ends LocalTime `json:"ends"`
}
type LibreTimeLiveInfoV2Shows struct {
Previous []interface{} `json:"previous"`
Current LibreTimeLiveInfoV2Show `json:"current"`
Next []LibreTimeLiveInfoV2Show `json:"next"`
}
type LibreTimeLiveInfoV2 struct {
Station map[string]string `json:"station"`
Tracks interface{} `json:"tracks"`
Shows LibreTimeLiveInfoV2Shows `json:"shows"`
Sources map[string]string `json:"sources"`
}
type gridSlot struct {
WebsiteEventOrganizerCalendarEvent WebsiteEventOrganizerCalendarEvent
LibreTimeLiveInfoV2Show LibreTimeLiveInfoV2Show
}
// gridError is a single error at a specific time with a message and a pointer to the grid slot.
type gridError struct {
Message string
Time time.Time
Slot gridSlot
}
// gridErrors are sortable collections of gridError.
type gridErrors []gridError
func (g gridErrors) Len() int {
return len(g)
}
func (g gridErrors) Less(i, j int) bool {
return g[i].Time.Before(g[j].Time)
}
func (g gridErrors) Swap(i, j int) {
g[i], g[j] = g[j], g[i]
}