-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson.go
136 lines (114 loc) · 2.68 KB
/
person.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package trakt
import (
"encoding/json"
"time"
)
type Department string
const (
DepartmentProduction Department = "production"
DepartmentArt Department = "art"
DepartmentCrew Department = "crew"
DepartmentCostumeAndMakeUp Department = "costume & make-up"
DepartmentDirecting Department = "directing"
DepartmentWriting Department = "writing"
DepartmentSound Department = "sound"
DepartmentCamera Department = "camera"
DepartmentVisualEffects Department = "visual effects"
DepartmentLighting Department = "lighting"
DepartmentEditing Department = "editing"
)
type Person struct {
MediaIDs `json:"ids"`
Name string `json:"name"`
Biography string `json:"biography"`
Birthday time.Time `json:"-"`
Death time.Time `json:"-"`
Homepage string `json:"homepage"`
Birthplace string `json:"birthplace"`
}
func (p *Person) UnmarshalJSON(bytes []byte) error {
type B Person
type A struct {
B
Birthday string `json:"birthday"`
Death string `json:"death"`
}
var a = new(A)
err := json.Unmarshal(bytes, a)
if err != nil {
return err
}
var pErr error
if len(a.Birthday) > 0 {
a.B.Birthday, pErr = time.Parse(`2006-01-02`, a.Birthday)
if pErr != nil {
return pErr
}
}
if len(a.Death) > 0 {
a.B.Death, pErr = time.Parse(`2006-01-02`, a.Death)
if pErr != nil {
return pErr
}
}
*p = Person(a.B)
return nil
}
type CastEntry struct {
Characters []string `json:"characters"`
Episodes *int64 `json:"episode_count"`
Person `json:"person"`
}
type CrewEntry struct {
Jobs []string `json:"jobs"`
Episodes *int64 `json:"episode_count"`
Person `json:"person"`
}
type CastAndCrew struct {
Cast []*CastEntry `json:"cast"`
Crew map[Department][]*CrewEntry `json:"crew"`
}
type CrewCredit struct {
topLevelMediaElement
Jobs []string `json:"jobs"`
}
func (b *CrewCredit) UnmarshalJSON(bytes []byte) error {
type A CrewCredit
var a = new(A)
err := json.Unmarshal(bytes, a)
if err != nil {
return err
}
switch {
case a.Show != nil:
a.Type = TypeShow
case a.Movie != nil:
a.Type = TypeMovie
}
*b = CrewCredit(*a)
return nil
}
type CastCredit struct {
topLevelMediaElement
Characters []string `json:"characters"`
}
func (b *CastCredit) UnmarshalJSON(bytes []byte) error {
type A CastCredit
var a = new(A)
err := json.Unmarshal(bytes, a)
if err != nil {
return err
}
switch {
case a.Show != nil:
a.Type = TypeShow
case a.Movie != nil:
a.Type = TypeMovie
}
*b = CastCredit(*a)
return nil
}
type Credits struct {
Cast []*CastCredit `json:"cast"`
Crew map[Department][]*CrewCredit `json:"crew"`
}