-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook_event.go
439 lines (410 loc) · 15.5 KB
/
webhook_event.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
package eventt
import "time"
type WebhookEvent struct {
EventType string `json:"eventType"`
}
type eventType interface {
eventName() string
}
// WebhookEventTypes
// see: https://github.com/Sonarr/Sonarr/blob/v3.0.9.1549/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs#L9
const (
// see GrabEvent
grab = "Grab"
// see DownloadEvent
download = "Download"
// see RenameEvent
rename = "Rename"
// see EpisodeFileDeleteEvent
episodeFileDelete = "EpisodeFileDelete"
// see SeriesDeleteEvent
seriesDelete = "SeriesDelete"
// see HealthIssueEvent
health = "Health"
// see ApplicationUpdateEvent
applicationUpdate = "ApplicationUpdate"
// see TestEvent
test = "Test"
)
// GrabEvent webhook grab payload
// see: https://github.com/Sonarr/Sonarr/blob/v3.0.9.1549/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs#L23
type GrabEvent struct {
Series struct {
ID int `json:"id"`
Title string `json:"title"`
Path string `json:"path"`
TvdbID int `json:"tvdbId"`
TvMazeID int `json:"tvMazeId"`
ImdbID string `json:"imdbId"`
Type string `json:"type"`
} `json:"series"`
Episodes []struct {
ID int `json:"id"`
EpisodeNumber int `json:"episodeNumber"`
SeasonNumber int `json:"seasonNumber"`
Title string `json:"title"`
AirDate string `json:"airDate"`
AirDateUtc time.Time `json:"airDateUtc"`
} `json:"episodes"`
Release struct {
Quality string `json:"quality"`
QualityVersion int `json:"qualityVersion"`
ReleaseGroup string `json:"releaseGroup"`
ReleaseTitle string `json:"releaseTitle"`
Indexer string `json:"indexer"`
Size int `json:"size"`
} `json:"release"`
DownloadClient string `json:"downloadClient"`
DownloadClientType string `json:"downloadClientType"`
DownloadID string `json:"downloadId"`
EventType string `json:"eventType"`
}
func (e GrabEvent) eventName() string {
return grab
}
// DownloadEvent webhook download payload
// see: https://github.com/Sonarr/Sonarr/blob/v3.0.9.1549/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs#L42
type DownloadEvent struct {
Series struct {
ID int `json:"id"`
Title string `json:"title"`
Path string `json:"path"`
TvdbID int `json:"tvdbId"`
TvMazeID int `json:"tvMazeId"`
ImdbID string `json:"imdbId"`
Type string `json:"type"`
} `json:"series"`
Episodes []struct {
ID int `json:"id"`
EpisodeNumber int `json:"episodeNumber"`
SeasonNumber int `json:"seasonNumber"`
Title string `json:"title"`
AirDate string `json:"airDate"`
AirDateUtc time.Time `json:"airDateUtc"`
} `json:"episodes"`
EpisodeFile struct {
ID int `json:"id"`
RelativePath string `json:"relativePath"`
Path string `json:"path"`
Quality string `json:"quality"`
QualityVersion int `json:"qualityVersion"`
ReleaseGroup string `json:"releaseGroup"`
Size int `json:"size"`
} `json:"episodeFile"`
IsUpgrade bool `json:"isUpgrade"`
EventType string `json:"eventType"`
}
func (e DownloadEvent) eventName() string {
return download
}
// RenameEvent webhook rename payload
// see: https://github.com/Sonarr/Sonarr/blob/v3.0.9.1549/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs#L71
type RenameEvent struct {
Series struct {
ID int `json:"id"`
Title string `json:"title"`
Path string `json:"path"`
TvdbID int `json:"tvdbId"`
TvMazeID int `json:"tvMazeId"`
ImdbID string `json:"imdbId"`
Type string `json:"type"`
} `json:"series"`
RenamedEpisodeFiles []struct {
PreviousRelativePath string `json:"previousRelativePath"`
PreviousPath string `json:"previousPath"`
ID int `json:"id"`
RelativePath string `json:"relativePath"`
Quality string `json:"quality"`
QualityVersion int `json:"qualityVersion"`
ReleaseGroup string `json:"releaseGroup"`
SceneName string `json:"sceneName"`
Size int `json:"size"`
} `json:"renamedEpisodeFiles"`
EventType string `json:"eventType"`
}
func (e RenameEvent) eventName() string {
return rename
}
// EpisodeFileDeleteEvent webhook episode file delete payload
// see: https://github.com/Sonarr/Sonarr/blob/v3.0.9.1549/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs#L83
type EpisodeFileDeleteEvent struct {
Series struct {
ID int `json:"id"`
Title string `json:"title"`
Path string `json:"path"`
TvdbID int `json:"tvdbId"`
TvMazeID int `json:"tvMazeId"`
ImdbID string `json:"imdbId"`
Type string `json:"type"`
} `json:"series"`
Episodes []struct {
ID int `json:"id"`
EpisodeNumber int `json:"episodeNumber"`
SeasonNumber int `json:"seasonNumber"`
Title string `json:"title"`
AirDate string `json:"airDate"`
AirDateUtc time.Time `json:"airDateUtc"`
} `json:"episodes"`
EpisodeFile struct {
SeriesID int `json:"seriesId"`
SeasonNumber int `json:"seasonNumber"`
RelativePath string `json:"relativePath"`
Path string `json:"path"`
Size int `json:"size"`
DateAdded time.Time `json:"dateAdded"`
ReleaseGroup string `json:"releaseGroup"`
Quality struct {
Quality struct {
ID int `json:"id"`
Name string `json:"name"`
Source string `json:"source"`
Resolution int `json:"resolution"`
} `json:"quality"`
Revision struct {
Version int `json:"version"`
Real int `json:"real"`
IsRepack bool `json:"isRepack"`
} `json:"revision"`
} `json:"quality"`
MediaInfo struct {
ContainerFormat string `json:"containerFormat"`
VideoFormat string `json:"videoFormat"`
VideoCodecID string `json:"videoCodecID"`
VideoProfile string `json:"videoProfile"`
VideoCodecLibrary string `json:"videoCodecLibrary"`
VideoBitrate int `json:"videoBitrate"`
VideoBitDepth int `json:"videoBitDepth"`
VideoMultiViewCount int `json:"videoMultiViewCount"`
VideoColourPrimaries string `json:"videoColourPrimaries"`
VideoTransferCharacteristics string `json:"videoTransferCharacteristics"`
VideoHdrFormat string `json:"videoHdrFormat"`
VideoHdrFormatCompatibility string `json:"videoHdrFormatCompatibility"`
Width int `json:"width"`
Height int `json:"height"`
AudioFormat string `json:"audioFormat"`
AudioCodecID string `json:"audioCodecID"`
AudioCodecLibrary string `json:"audioCodecLibrary"`
AudioAdditionalFeatures string `json:"audioAdditionalFeatures"`
AudioBitrate int `json:"audioBitrate"`
RunTime string `json:"runTime"`
AudioStreamCount int `json:"audioStreamCount"`
AudioChannelsContainer int `json:"audioChannelsContainer"`
AudioChannelsStream int `json:"audioChannelsStream"`
AudioChannelPositions string `json:"audioChannelPositions"`
AudioChannelPositionsTextContainer string `json:"audioChannelPositionsTextContainer"`
AudioChannelPositionsTextStream string `json:"audioChannelPositionsTextStream"`
AudioProfile string `json:"audioProfile"`
VideoFps float64 `json:"videoFps"`
AudioLanguages string `json:"audioLanguages"`
Subtitles string `json:"subtitles"`
ScanType string `json:"scanType"`
SchemaRevision int `json:"schemaRevision"`
} `json:"mediaInfo"`
Episodes struct {
Value []struct {
SeriesID int `json:"seriesId"`
TvdbID int `json:"tvdbId"`
EpisodeFileID int `json:"episodeFileId"`
SeasonNumber int `json:"seasonNumber"`
EpisodeNumber int `json:"episodeNumber"`
Title string `json:"title"`
AirDate string `json:"airDate"`
AirDateUtc time.Time `json:"airDateUtc"`
Overview string `json:"overview"`
Monitored bool `json:"monitored"`
AbsoluteEpisodeNumber int `json:"absoluteEpisodeNumber"`
SceneAbsoluteEpisodeNumber int `json:"sceneAbsoluteEpisodeNumber"`
SceneSeasonNumber int `json:"sceneSeasonNumber"`
SceneEpisodeNumber int `json:"sceneEpisodeNumber"`
UnverifiedSceneNumbering bool `json:"unverifiedSceneNumbering"`
Ratings struct {
Votes int `json:"votes"`
Value float64 `json:"value"`
} `json:"ratings"`
Images []struct {
CoverType string `json:"coverType"`
URL string `json:"url"`
} `json:"images"`
EpisodeFile struct {
IsLoaded bool `json:"isLoaded"`
} `json:"episodeFile"`
HasFile bool `json:"hasFile"`
ID int `json:"id"`
} `json:"value"`
IsLoaded bool `json:"isLoaded"`
} `json:"episodes"`
Series struct {
Value struct {
TvdbID int `json:"tvdbId"`
TvRageID int `json:"tvRageId"`
TvMazeID int `json:"tvMazeId"`
ImdbID string `json:"imdbId"`
Title string `json:"title"`
CleanTitle string `json:"cleanTitle"`
SortTitle string `json:"sortTitle"`
Status string `json:"status"`
Overview string `json:"overview"`
AirTime string `json:"airTime"`
Monitored bool `json:"monitored"`
QualityProfileID int `json:"qualityProfileId"`
LanguageProfileID int `json:"languageProfileId"`
SeasonFolder bool `json:"seasonFolder"`
LastInfoSync time.Time `json:"lastInfoSync"`
Runtime int `json:"runtime"`
Images []struct {
CoverType string `json:"coverType"`
URL string `json:"url"`
} `json:"images"`
SeriesType string `json:"seriesType"`
Network string `json:"network"`
UseSceneNumbering bool `json:"useSceneNumbering"`
TitleSlug string `json:"titleSlug"`
Path string `json:"path"`
Year int `json:"year"`
Ratings struct {
Votes int `json:"votes"`
Value float64 `json:"value"`
} `json:"ratings"`
Genres []string `json:"genres"`
Actors []struct {
Name string `json:"name"`
Character string `json:"character"`
Images []interface{} `json:"images"`
} `json:"actors"`
Certification string `json:"certification"`
Added time.Time `json:"added"`
FirstAired time.Time `json:"firstAired"`
QualityProfile struct {
Value struct {
Name string `json:"name"`
UpgradeAllowed bool `json:"upgradeAllowed"`
Cutoff int `json:"cutoff"`
Items []struct {
Quality struct {
ID int `json:"id"`
Name string `json:"name"`
Source string `json:"source"`
Resolution int `json:"resolution"`
} `json:"quality,omitempty"`
Items []interface{} `json:"items"`
Allowed bool `json:"allowed"`
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
} `json:"items"`
ID int `json:"id"`
} `json:"value"`
IsLoaded bool `json:"isLoaded"`
} `json:"qualityProfile"`
LanguageProfile struct {
Value struct {
Name string `json:"name"`
Languages []struct {
Language struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"language"`
Allowed bool `json:"allowed"`
} `json:"languages"`
UpgradeAllowed bool `json:"upgradeAllowed"`
Cutoff struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"cutoff"`
ID int `json:"id"`
} `json:"value"`
IsLoaded bool `json:"isLoaded"`
} `json:"languageProfile"`
Seasons []struct {
SeasonNumber int `json:"seasonNumber"`
Monitored bool `json:"monitored"`
Images []struct {
CoverType string `json:"coverType"`
URL string `json:"url"`
} `json:"images"`
} `json:"seasons"`
Tags []int `json:"tags"`
ID int `json:"id"`
} `json:"value"`
IsLoaded bool `json:"isLoaded"`
} `json:"series"`
Language struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"language"`
ID int `json:"id"`
} `json:"episodeFile"`
DeleteReason string `json:"deleteReason"`
EventType string `json:"eventType"`
}
func (e EpisodeFileDeleteEvent) eventName() string {
return episodeFileDelete
}
// SeriesDeleteEvent webhook series delete payload
// see: https://github.com/Sonarr/Sonarr/blob/v3.0.9.1549/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs#L97
type SeriesDeleteEvent struct {
Series struct {
ID int `json:"id"`
Title string `json:"title"`
Path string `json:"path"`
TvdbID int `json:"tvdbId"`
TvMazeID int `json:"tvMazeId"`
ImdbID string `json:"imdbId"`
Type string `json:"type"`
} `json:"series"`
DeletedFiles bool `json:"deletedFiles"`
EventType string `json:"eventType"`
}
func (e SeriesDeleteEvent) eventName() string {
return seriesDelete
}
// Health webhook health payload
// see: https://github.com/Sonarr/Sonarr/blob/v3.0.9.1549/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs#L109
type HealthEvent struct {
Level string `json:"level"`
Message string `json:"message"`
Type string `json:"type"`
WikiURL string `json:"wikiUrl"`
EventType string `json:"eventType"`
}
func (e HealthEvent) eventName() string {
return health
}
// ApplicationUpdateEvent webhook application update payload
// see: https://github.com/Sonarr/Sonarr/blob/v3.0.9.1549/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs#L123
type ApplicationUpdateEvent struct {
Message string `json:"message"`
PreviousVersion string `json:"previousVersion"`
NewVersion string `json:"newVersion"`
EventType string `json:"eventType"`
}
func (e ApplicationUpdateEvent) eventName() string {
return applicationUpdate
}
// TestEvent webhook test payload
// see: https://github.com/Sonarr/Sonarr/blob/v3.0.9.1549/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs#L153
type TestEvent struct {
Series struct {
ID int `json:"id"`
Title string `json:"title"`
Path string `json:"path"`
TvdbID int `json:"tvdbId"`
TvMazeID int `json:"tvMazeId"`
Type string `json:"type"`
} `json:"series"`
Episodes []struct {
ID int `json:"id"`
EpisodeNumber int `json:"episodeNumber"`
SeasonNumber int `json:"seasonNumber"`
Title string `json:"title"`
} `json:"episodes"`
EventType string `json:"eventType"`
}
func (e TestEvent) eventName() string {
return test
}
// UnknownEvent parse any unknown events, this could happened if Sonarr update or add
// new webhook events or change them, like what happened when OnImport and OnDownload.
type UnknownEvent map[string]interface{}
func (e UnknownEvent) eventName() string {
return "Unknown"
}