-
Notifications
You must be signed in to change notification settings - Fork 1
/
methods.go
465 lines (380 loc) · 15 KB
/
methods.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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
package nzbget
import (
"context"
"time"
)
// Version returns the NZBGet Version.
// https://nzbget.net/api/version
func (n *NZBGet) Version() (string, error) {
return n.VersionContext(context.Background())
}
// VersionContext returns the NZBGet Version.
// https://nzbget.net/api/version
func (n *NZBGet) VersionContext(ctx context.Context) (string, error) {
var output string
err := n.GetInto(ctx, "version", &output)
return output, err
}
// ListFiles returns the NZBGet Files for a download.
// https://nzbget.net/api/listfiles
// nzbID is the NZBID of the group to be returned. Use 0 for all file groups.
func (n *NZBGet) ListFiles(nzbID int64) (*File, error) {
return n.ListFilesContext(context.Background(), nzbID)
}
// ListFilesContext returns the NZBGet Files for a download.
// https://nzbget.net/api/listfiles
// nzbID is the NZBID of the group to be returned. Use 0 for all file groups.
func (n *NZBGet) ListFilesContext(ctx context.Context, nzbID int64) (*File, error) {
var output File
err := n.GetInto(ctx, "listfiles", &output, 0, 0, nzbID)
return &output, err
}
// Status returns the NZBGet Status.
// https://nzbget.net/api/status
func (n *NZBGet) Status() (*Status, error) {
return n.StatusContext(context.Background())
}
// StatusContext returns the NZBGet Status.
// https://nzbget.net/api/status
func (n *NZBGet) StatusContext(ctx context.Context) (*Status, error) {
var output Status
err := n.GetInto(ctx, "status", &output)
return &output, err
}
// History returns the NZBGet Download History.
// https://nzbget.net/api/history
func (n *NZBGet) History(hidden bool) ([]*History, error) {
return n.HistoryContext(context.Background(), hidden)
}
// HistoryContext returns the NZBGet Download History.
// https://nzbget.net/api/history
func (n *NZBGet) HistoryContext(ctx context.Context, hidden bool) ([]*History, error) {
var output []*History
err := n.GetInto(ctx, "history", &output, hidden)
return output, err
}
// ListGroups returns the NZBGet Download list.
// https://nzbget.net/api/listgroups
func (n *NZBGet) ListGroups() ([]*Group, error) {
return n.ListGroupsContext(context.Background())
}
// ListGroupsContext returns the NZBGet Download list.
// https://nzbget.net/api/listgroups
func (n *NZBGet) ListGroupsContext(ctx context.Context) ([]*Group, error) {
var output []*Group
err := n.GetInto(ctx, "listgroups", &output, 0)
return output, err
}
// Log returns the NZBGet Logs.
// NOTE: only one parameter - either startID or limit - can be specified. The other parameter must be 0.
// https://nzbget.net/api/log
func (n *NZBGet) Log(startID, limit int64) ([]*LogEntry, error) {
return n.LogContext(context.Background(), startID, limit)
}
// LogContext returns the NZBGet Logs.
// NOTE: only one parameter - either startID or limit - can be specified. The other parameter must be 0.
// https://nzbget.net/api/log
func (n *NZBGet) LogContext(ctx context.Context, startID, limit int64) ([]*LogEntry, error) {
var output []*LogEntry
err := n.GetInto(ctx, "log", &output, startID, limit)
return output, err
}
// LoadLog returns the NZBGet log for a specific download.
// NOTE: only one of either startID or limit - can be specified. The other parameter must be 0.
// https://nzbget.net/api/loadlog
func (n *NZBGet) LoadLog(nzbID, startID, limit int64) ([]*LogEntry, error) {
return n.LoadLogContext(context.Background(), nzbID, startID, limit)
}
// LoadLogContext returns the NZBGet log for a specific download.
// NOTE: only one of either startID or limit - can be specified. The other parameter must be 0.
// https://nzbget.net/api/loadlog
func (n *NZBGet) LoadLogContext(ctx context.Context, nzbID, startID, limit int64) ([]*LogEntry, error) {
var output []*LogEntry
err := n.GetInto(ctx, "loadlog", &output, nzbID, startID, limit)
return output, err
}
// Config returns the loaded and active NZBGet configuration parameters.
// https://nzbget.net/api/config
func (n *NZBGet) Config() ([]*Parameter, error) {
return n.ConfigContext(context.Background())
}
// ConfigContext returns the loaded and active NZBGet configuration parameters.
// https://nzbget.net/api/config
func (n *NZBGet) ConfigContext(ctx context.Context) ([]*Parameter, error) {
var output []*Parameter
err := n.GetInto(ctx, "config", &output)
return output, err
}
// LoadConfig returns the configuration from disk.
// https://nzbget.net/api/loadconfig
func (n *NZBGet) LoadConfig() ([]*Parameter, error) {
return n.LoadConfigContext(context.Background())
}
// LoadConfigContext returns the configuration from disk.
// https://nzbget.net/api/loadconfig
func (n *NZBGet) LoadConfigContext(ctx context.Context) ([]*Parameter, error) {
var output []*Parameter
err := n.GetInto(ctx, "loadconfig", &output)
return output, err
}
// SaveConfig writes new configuration parameters to disk.
// https://nzbget.net/api/saveconfig
func (n *NZBGet) SaveConfig(configs []*Parameter) (bool, error) {
return n.SaveConfigContext(context.Background(), configs)
}
// SaveConfigContext writes new configuration parameters to disk.
// https://nzbget.net/api/saveconfig
func (n *NZBGet) SaveConfigContext(ctx context.Context, configs []*Parameter) (bool, error) {
var output bool
err := n.GetInto(ctx, "saveconfig", &output, configs)
return output, err
}
// Shutdown makes NZBGet exit.
// https://nzbget.net/api/shutdown
func (n *NZBGet) Shutdown() (bool, error) {
return n.ShutdownContext(context.Background())
}
// ShutdownContext makes NZBGet exit.
// https://nzbget.net/api/shutdown
func (n *NZBGet) ShutdownContext(ctx context.Context) (bool, error) {
var output bool
err := n.GetInto(ctx, "shutdown", &output)
return output, err
}
// Reload makes NZBGet stop all activities and reinitialize.
// https://nzbget.net/api/reload
func (n *NZBGet) Reload() (bool, error) {
return n.ReloadContext(context.Background())
}
// ReloadContext makes NZBGet stop all activities and reinitialize.
// https://nzbget.net/api/reload
func (n *NZBGet) ReloadContext(ctx context.Context) (bool, error) {
var output bool
err := n.GetInto(ctx, "reload", &output)
return output, err
}
// Rate sets download speed limit.
// https://nzbget.net/api/rate
func (n *NZBGet) Rate(limit int64) (bool, error) {
return n.RateContext(context.Background(), limit)
}
// RateContext sets download speed limit.
// https://nzbget.net/api/rate
func (n *NZBGet) RateContext(ctx context.Context, limit int64) (bool, error) {
var output bool
err := n.GetInto(ctx, "rate", &output, limit)
return output, err
}
// PausePost pauses post processing.
// https://nzbget.net/api/pausepost
func (n *NZBGet) PausePost() (bool, error) {
return n.PausePostContext(context.Background())
}
// PausePostContext pauses post processing.
// https://nzbget.net/api/pausepost
func (n *NZBGet) PausePostContext(ctx context.Context) (bool, error) {
var output bool
err := n.GetInto(ctx, "pausepost", &output)
return output, err
}
// ResumePost resumes post processing.
// https://nzbget.net/api/resumepost
func (n *NZBGet) ResumePost() (bool, error) {
return n.ResumePostContext(context.Background())
}
// ResumePostContext resumes post processing.
// https://nzbget.net/api/resumepost
func (n *NZBGet) ResumePostContext(ctx context.Context) (bool, error) {
var output bool
err := n.GetInto(ctx, "resumepost", &output)
return output, err
}
// PauseDownload pauses downloads.
// https://nzbget.net/api/pausedownload
func (n *NZBGet) PauseDownload() (bool, error) {
return n.PauseDownloadContext(context.Background())
}
// PauseDownloadContext pauses downloads.
// https://nzbget.net/api/pausedownload
func (n *NZBGet) PauseDownloadContext(ctx context.Context) (bool, error) {
var output bool
err := n.GetInto(ctx, "pausedownload", &output)
return output, err
}
// ResumeDownload resumes downloads.
// https://nzbget.net/api/resumedownload
func (n *NZBGet) ResumeDownload() (bool, error) {
return n.ResumeDownloadContext(context.Background())
}
// ResumeDownloadContext resumes downloads.
// https://nzbget.net/api/resumedownload
func (n *NZBGet) ResumeDownloadContext(ctx context.Context) (bool, error) {
var output bool
err := n.GetInto(ctx, "resumedownload", &output)
return output, err
}
// PauseScan pauses scanning of directory with incoming nzb-files.
// https://nzbget.net/api/pausescan
func (n *NZBGet) PauseScan() (bool, error) {
return n.PauseScanContext(context.Background())
}
// PauseScanContext pauses scanning of directory with incoming nzb-files.
// https://nzbget.net/api/pausescan
func (n *NZBGet) PauseScanContext(ctx context.Context) (bool, error) {
var output bool
err := n.GetInto(ctx, "pausescan", &output)
return output, err
}
// ResumeScan resumes scanning of directory with incoming nzb-files.
// https://nzbget.net/api/resumescan
func (n *NZBGet) ResumeScan() (bool, error) {
return n.ResumeScanContext(context.Background())
}
// ResumeScanContext resumes scanning of directory with incoming nzb-files.
// https://nzbget.net/api/resumescan
func (n *NZBGet) ResumeScanContext(ctx context.Context) (bool, error) {
var output bool
err := n.GetInto(ctx, "resumescan", &output)
return output, err
}
// ScheduleResume schedules resuming of all activities after wait duration elapses.
// Wait duration is rounded to nearest second.
// https://nzbget.net/api/scheduleresume
func (n *NZBGet) ScheduleResume(wait time.Duration) (bool, error) {
return n.ScheduleResumeContext(context.Background(), wait)
}
// ScheduleResumeContext schedules resuming of all activities after wait duration elapses.
// Wait duration is rounded to nearest second.
// https://nzbget.net/api/scheduleresume
func (n *NZBGet) ScheduleResumeContext(ctx context.Context, wait time.Duration) (bool, error) {
var output bool
err := n.GetInto(ctx, "scheduleresume", &output, wait.Seconds())
return output, err
}
// Scan requests rescanning of incoming directory for nzb-files.
// https://nzbget.net/api/scheduleresume
func (n *NZBGet) Scan() (bool, error) {
return n.ScanContext(context.Background())
}
// ScanContext requests rescanning of incoming directory for nzb-files.
// https://nzbget.net/api/scheduleresume
func (n *NZBGet) ScanContext(ctx context.Context) (bool, error) {
var output bool
err := n.GetInto(ctx, "scan", &output)
return output, err
}
// WriteLog appends a log entry to th server's log and on-screen log buffer.
// https://nzbget.net/api/writelog
func (n *NZBGet) WriteLog(kind LogKind, text string) (bool, error) {
return n.WriteLogContext(context.Background(), kind, text)
}
// WriteLogContext appends a log entry to th server's log and on-screen log buffer.
// https://nzbget.net/api/writelog
func (n *NZBGet) WriteLogContext(ctx context.Context, kind LogKind, text string) (bool, error) {
var output bool
err := n.GetInto(ctx, "writelog", &output, kind, text)
return output, err
}
// ConfigTemplates returns NZBGet configuration file template and
// also extracts configuration sections from all post-processing files.
// This information is for example used by web-interface to build settings
// page or page “Postprocess” in download details dialog.
// https://nzbget.net/api/configtemplates
func (n *NZBGet) ConfigTemplates(loadFromDisk bool) ([]*ConfigTemplate, error) {
return n.ConfigTemplatesContext(context.Background(), loadFromDisk)
}
// ConfigTemplatesContext returns NZBGet configuration file template and
// also extracts configuration sections from all post-processing files.
// This information is for example used by web-interface to build settings
// page or page “Postprocess” in download details dialog.
// https://nzbget.net/api/configtemplates
func (n *NZBGet) ConfigTemplatesContext(ctx context.Context, loadFromDisk bool) ([]*ConfigTemplate, error) {
var output []*ConfigTemplate
err := n.GetInto(ctx, "configtemplates", &output, loadFromDisk)
return output, err
}
// ServerVolumes returns download volume statistics per news-server.
// https://nzbget.net/api/servervolumes
// NOTE: The first record (serverid=0) are totals for all servers.
func (n *NZBGet) ServerVolumes() ([]*ServerVolume, error) {
return n.ServerVolumesContext(context.Background())
}
// ServerVolumesContext returns download volume statistics per news-server.
// https://nzbget.net/api/servervolumes
// NOTE: The first record (serverid=0) are totals for all servers.
func (n *NZBGet) ServerVolumesContext(ctx context.Context) ([]*ServerVolume, error) {
var output []*ServerVolume
err := n.GetInto(ctx, "servervolumes", &output)
return output, err
}
// ResetServerVolume resets download volume statistics for a specified news-server.
// https://nzbget.net/api/resetservervolume
func (n *NZBGet) ResetServerVolume(serverID int64, sounter string) (bool, error) {
return n.ResetServerVolumeContext(context.Background(), serverID, sounter)
}
// ResetServerVolumeContext resets download volume statistics for a specified news-server.
// https://nzbget.net/api/resetservervolume
func (n *NZBGet) ResetServerVolumeContext(ctx context.Context, serverID int64, sounter string) (bool, error) {
var output bool
err := n.GetInto(ctx, "resetservervolume", &output, serverID, sounter)
return output, err
}
// AppendInput is the input data for the append method.
// See https://nzbget.net/api/append for more information about this data.
type AppendInput struct {
Filename string
Content string
Category string
Priority int64
AddToTop bool
AddPaused bool
DupeKey string // See: https://nzbget.net/rss#duplicate-keys
DupeScore int64 // See: https://nzbget.net/rss#duplicate-scores
DupeMode string // See: https://nzbget.net/rss#duplicate-modes
Parameters []*Parameter
}
// Append adds a nzb-file or URL to the download queue.
// https://nzbget.net/api/append
func (n *NZBGet) Append(input *AppendInput) (int64, error) {
return n.AppendContext(context.Background(), input)
}
// AppendContext adds a nzb-file or URL to the download queue.
// https://nzbget.net/api/append
func (n *NZBGet) AppendContext(ctx context.Context, input *AppendInput) (int64, error) {
var output int64
err := n.GetInto(ctx, "append", &output,
input.Filename,
input.Content,
input.Category,
input.Priority,
input.AddToTop,
input.AddPaused,
input.DupeKey,
input.DupeScore,
input.DupeMode,
ppparameters(input.Parameters),
)
return output, err
}
// ppparameters turns input Parameters into an RPC-compatible format.
func ppparameters(parameters []*Parameter) [][2]string {
output := make([][2]string, len(parameters))
for idx, param := range parameters {
output[idx] = [2]string{param.Name, param.Value}
}
return output
}
// EditQueue edits items in download queue or in history.
// Read the official docs for how to issue commands, and which commands are available.
// https://nzbget.net/api/editqueue
func (n *NZBGet) EditQueue(command, parameter string, ids []int64) (bool, error) {
return n.EditQueueContext(context.Background(), command, parameter, ids)
}
// EditQueueContext edits items in download queue or in history.
// Read the official docs for how to issue commands, and which commands are available.
// https://nzbget.net/api/editqueue
func (n *NZBGet) EditQueueContext(ctx context.Context, command, parameter string, ids []int64) (bool, error) {
var output bool
err := n.GetInto(ctx, "editqueue", &output, command, parameter, ids)
return output, err
}