Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
anasty17
GitHub Repository: anasty17/mirror-leech-telegram-bot
Path: blob/master/sabnzbdapi/job_functions.py
1631 views
1
from sabnzbdapi.bound_methods import SubFunctions
2
3
4
class JobFunctions(SubFunctions):
5
6
async def add_uri(
7
self,
8
url: str = "",
9
file: str = "",
10
nzbname: str = "",
11
password: str = "",
12
cat: str = "*",
13
script: list = None,
14
priority: int = 0,
15
pp: int = 1,
16
):
17
18
'return {"status": True, "nzo_ids": ["SABnzbd_nzo_kyt1f0"]}'
19
20
if file:
21
name = file
22
mode = "addlocalfile"
23
else:
24
name = url
25
mode = "addurl"
26
27
return await self.call(
28
{
29
"mode": mode,
30
"name": name,
31
"nzbname": nzbname,
32
"password": password,
33
"cat": cat,
34
"script": script,
35
"priority": priority,
36
"pp": pp,
37
}
38
)
39
40
async def get_downloads(
41
self,
42
start: int | None = None,
43
limit: int | None = None,
44
search: str | None = None,
45
category: str | list[str] | None = None,
46
priority: int | list[str] | None = None,
47
status: str | list[str] | None = None,
48
nzo_ids: str | list[str] | None = None,
49
):
50
"""return {
51
"queue": {
52
"status": "Downloading",
53
"speedlimit": "9",
54
"speedlimit_abs": "4718592.0",
55
"paused": false,
56
"noofslots_total": 2,
57
"noofslots": 2,
58
"limit": 10,
59
"start": 0,
60
"timeleft": "0:16:44",
61
"speed": "1.3 M",
62
"kbpersec": "1296.02",
63
"size": "1.2 GB",
64
"sizeleft": "1.2 GB",
65
"mb": "1277.65",
66
"mbleft": "1271.58",
67
"slots": [
68
{
69
"status": "Downloading",
70
"index": 0,
71
"password": "",
72
"avg_age": "2895d",
73
"script": "None",
74
"direct_unpack": "10/30",
75
"mb": "1277.65",
76
"mbleft": "1271.59",
77
"mbmissing": "0.0",
78
"size": "1.2 GB",
79
"sizeleft": "1.2 GB",
80
"filename": "TV.Show.S04E11.720p.HDTV.x264",
81
"labels": [],
82
"priority": "Normal",
83
"cat": "tv",
84
"timeleft": "0:16:44",
85
"percentage": "0",
86
"nzo_id": "SABnzbd_nzo_p86tgx",
87
"unpackopts": "3"
88
},
89
{
90
"status": "Paused",
91
"index": 1,
92
"password": "",
93
"avg_age": "2895d",
94
"script": "None",
95
"direct_unpack": null,
96
"mb": "1277.76",
97
"mbleft": "1277.76",
98
"mbmissing": "0.0",
99
"size": "1.2 GB",
100
"sizeleft": "1.2 GB",
101
"filename": "TV.Show.S04E12.720p.HDTV.x264",
102
"labels": [
103
"TOO LARGE",
104
"DUPLICATE"
105
],
106
"priority": "Normal",
107
"cat": "tv",
108
"timeleft": "0:00:00",
109
"percentage": "0",
110
"nzo_id": "SABnzbd_nzo_ksfai6",
111
"unpackopts": "3"
112
}
113
],
114
"diskspace1": "161.16",
115
"diskspace2": "161.16",
116
"diskspacetotal1": "465.21",
117
"diskspacetotal2": "465.21",
118
"diskspace1_norm": "161.2 G",
119
"diskspace2_norm": "161.2 G",
120
"have_warnings": "0",
121
"pause_int": "0",
122
"left_quota": "0 ",
123
"version": "3.x.x",
124
"finish": 2,
125
"cache_art": "16",
126
"cache_size": "6 MB",
127
"finishaction": null,
128
"paused_all": false,
129
"quota": "0 ",
130
"have_quota": false,
131
}
132
}"""
133
134
if nzo_ids:
135
nzo_ids = nzo_ids if isinstance(nzo_ids, str) else ",".join(nzo_ids)
136
if status:
137
status = status if isinstance(status, str) else ",".join(status)
138
if category:
139
category = category if isinstance(category, str) else ",".join(category)
140
if priority:
141
priority = priority if isinstance(priority, str) else ",".join(priority)
142
143
return await self.call(
144
{
145
"mode": "queue",
146
"start": start,
147
"limit": limit,
148
"search": search,
149
"category": category,
150
"priority": priority,
151
"status": status,
152
"nzo_ids": nzo_ids,
153
},
154
)
155
156
async def pause_job(self, nzo_id: str):
157
"""return {"status": True, "nzo_ids": ["all effected ids"]}"""
158
return await self.call({"mode": "queue", "name": "pause", "value": nzo_id})
159
160
async def resume_job(self, nzo_id: str):
161
"""return {"status": True, "nzo_ids": ["all effected ids"]}"""
162
return await self.call({"mode": "queue", "name": "resume", "value": nzo_id})
163
164
async def delete_job(self, nzo_id: str | list[str], delete_files: bool = False):
165
"""return {"status": True, "nzo_ids": ["all effected ids"]}"""
166
return await self.call(
167
{
168
"mode": "queue",
169
"name": "delete",
170
"value": nzo_id if isinstance(nzo_id, str) else ",".join(nzo_id),
171
"del_files": 1 if delete_files else 0,
172
}
173
)
174
175
async def pause_all(self):
176
"""return {"status": True}"""
177
return await self.call({"mode": "pause"})
178
179
async def resume_all(self):
180
"""return {"status": True}"""
181
return await self.call({"mode": "resume"})
182
183
async def purge_all(self, delete_files: bool = False):
184
"""return {"status": True, "nzo_ids": ["all effected ids"]}"""
185
return await self.call(
186
{"mode": "queue", "name": "purge", "del_files": 1 if delete_files else 0}
187
)
188
189
async def get_files(self, nzo_id: str):
190
"""
191
return {
192
"files": [
193
{
194
"status": "finished",
195
"mbleft": "0.00",
196
"mb": "0.05",
197
"age": "25d",
198
"bytes": "52161.00",
199
"filename": "93a4ec7c37752640deab48dabb46b164.par2",
200
"nzf_id": "SABnzbd_nzf_1lk0ij",
201
},
202
...,
203
]
204
}
205
"""
206
return await self.call({"mode": "get_files", "value": nzo_id})
207
208
async def remove_file(self, nzo_id: str, file_ids: str | list[str]):
209
return await self.call(
210
{
211
"mode": "queue",
212
"name": "delete_nzf",
213
"value": nzo_id,
214
"value2": file_ids if isinstance(file_ids, str) else ",".join(file_ids),
215
}
216
) # return nzf_ids of removed file idk how yet
217
218
async def get_history(
219
self,
220
start: int | None = None,
221
limit: int | None = None,
222
search: str | None = None,
223
category: str | list[str] | None = None,
224
archive: int | None = None,
225
status: str | list[str] | None = None,
226
nzo_ids: str | list[str] | None = None,
227
failed_only: bool = False,
228
last_history_update: int | None = None,
229
):
230
"""{
231
"history": {
232
"noofslots": 220,
233
"ppslots": 1,
234
"day_size": "1.9 G",
235
"week_size": "30.4 G",
236
"month_size": "167.3 G",
237
"total_size": "678.1 G",
238
"last_history_update": 1469210913,
239
"slots": [
240
{
241
"action_line": "",
242
"duplicate_key": "TV.Show/4/2",
243
"meta": null,
244
"fail_message": "",
245
"loaded": false,
246
"size": "2.3 GB",
247
"category": "tv",
248
"pp": "D",
249
"retry": 0,
250
"script": "None",
251
"nzb_name": "TV.Show.S04E02.720p.BluRay.x264-xHD.nzb",
252
"download_time": 64,
253
"storage": "C:\\Users\\xxx\\Videos\\Complete\\TV.Show.S04E02.720p.BluRay.x264-xHD",
254
"has_rating": false,
255
"status": "Completed",
256
"script_line": "",
257
"completed": 1469172988,
258
"nzo_id": "SABnzbd_nzo_sdkoun",
259
"downloaded": 2436906376,
260
"report": "",
261
"password": "",
262
"path": "\\\\?\\C:\\SABnzbd\\TV.Show.S04E02.720p.BluRay.x264-xHD",
263
"postproc_time": 40,
264
"name": "TV.Show.S04E02.720p.BluRay.x264-xHD",
265
"url": "TV.Show.S04E02.720p.BluRay.x264-xHD.nzb",
266
"md5sum": "d2c16aeecbc1b1921d04422850e93013",
267
"archive": false,
268
"bytes": 2436906376,
269
"url_info": "",
270
"stage_log": [
271
{
272
"name": "Source",
273
"actions": [
274
"TV.Show.S04E02.720p.BluRay.x264-xHD.nzb"
275
]
276
},
277
{
278
"name": "Download",
279
"actions": [
280
"Downloaded in 1 min 4 seconds at an average of 36.2 MB/s<br/>Age: 550d<br/>10 articles were malformed"
281
]
282
},
283
{
284
"name": "Servers",
285
"actions": [
286
"Frugal=2.3 GB"
287
]
288
},
289
{
290
"name": "Repair",
291
"actions": [
292
"[pA72r5Ac6lW3bmpd20T7Hj1Zg2bymUsINBB50skrI] Repaired in 19 seconds"
293
]
294
},
295
{
296
"name": "Unpack",
297
"actions": [
298
"[pA72r5Ac6lW3bmpd20T7Hj1Zg2bymUsINBB50skrI] Unpacked 1 files/folders in 6 seconds"
299
]
300
}
301
]
302
},
303
{
304
"action_line": "",
305
"duplicate_key": "TV.Show/4/13",
306
"meta": null,
307
"fail_message": "",
308
"loaded": false,
309
"size": "2.3 GB",
310
"category": "tv",
311
"pp": "D",
312
"retry": 0,
313
"script": "None",
314
"nzb_name": "TV.Show.S04E13.720p.BluRay.x264-xHD.nzb",
315
"download_time": 60,
316
"storage": "C:\\Users\\xxx\\Videos\\Complete\\TV.Show.S04E13.720p.BluRay.x264-xHD",
317
"has_rating": false,
318
"status": "Completed",
319
"script_line": "",
320
"completed": 1469172947,
321
"nzo_id": "SABnzbd_nzo_gqhp63",
322
"downloaded": 2491255137,
323
"report": "",
324
"password": "",
325
"path": "\\\\?\\C:\\SABnzbd\\TV.Show.S04E13.720p.BluRay.x264-xHD",
326
"postproc_time": 82,
327
"name": "TV.Show.S04E13.720p.BluRay.x264-xHD",
328
"url": "TV.Show.S04E13.720p.BluRay.x264-xHD.nzb",
329
"md5sum": "85baf55ec0de0dc732c2af6537c5c01b",
330
"archive": true,
331
"bytes": 2491255137,
332
"url_info": "",
333
"stage_log": [
334
{
335
"name": "Source",
336
"actions": [
337
"TV.Show.S04E13.720p.BluRay.x264-xHD.nzb"
338
]
339
},
340
{
341
"name": "Download",
342
"actions": [
343
"Downloaded in 1 min at an average of 39.4 MB/s<br/>Age: 558d<br/>15 articles were malformed"
344
]
345
},
346
{
347
"name": "Servers",
348
"actions": [
349
"Frugal=2.3 GB"
350
]
351
},
352
{
353
"name": "Repair",
354
"actions": [
355
"[m0vklMEMKIT5L5XH9z5YTmuquoitCQ3F5LISTLFjT] Repaired in 47 seconds"
356
]
357
},
358
{
359
"name": "Unpack",
360
"actions": [
361
"[m0vklMEMKIT5L5XH9z5YTmuquoitCQ3F5LISTLFjT] Unpacked 1 files/folders in 6 seconds"
362
]
363
}
364
]
365
}
366
]
367
}
368
}"""
369
370
if nzo_ids:
371
nzo_ids = nzo_ids if isinstance(nzo_ids, str) else ",".join(nzo_ids)
372
if status:
373
status = status if isinstance(status, str) else ",".join(status)
374
if category:
375
category = category if isinstance(category, str) else ",".join(category)
376
377
return await self.call(
378
{
379
"mode": "history",
380
"start": start,
381
"limit": limit,
382
"archive": archive,
383
"search": search,
384
"category": category,
385
"status": status,
386
"nzo_ids": nzo_ids,
387
"failed_only": failed_only,
388
"last_history_update": last_history_update,
389
},
390
)
391
392
async def retry_item(self, nzo_id: str, password: str = ""):
393
"""return {"status": True}"""
394
return await self.call({"mode": "retry", "value": nzo_id, "password": password})
395
396
async def retry_all(self):
397
"""return {"status": True}"""
398
return await self.call({"mode": "retry_all"})
399
400
async def delete_history(
401
self, nzo_ids: str | list[str], archive: int = 0, delete_files: bool = False
402
):
403
"""return {"status": True}"""
404
return await self.call(
405
{
406
"mode": "history",
407
"name": "delete",
408
"value": nzo_ids if isinstance(nzo_ids, str) else ",".join(nzo_ids),
409
"archive": archive,
410
"del_files": 1 if delete_files else 0,
411
}
412
)
413
414
async def change_job_pp(self, nzo_id: str, pp: int):
415
"""return {"status": True}"""
416
return await self.call({"mode": "change_opts", "value": nzo_id, "value2": pp})
417
418
async def set_speedlimit(self, limit: str | int):
419
"""return {"status": True}"""
420
return await self.call({"mode": "config", "name": "speedlimit", "value": limit})
421
422
async def delete_config(self, section: str, keyword: str):
423
"""return {"status": True}"""
424
return await self.call(
425
{"mode": "del_config", "section": section, "keyword": keyword}
426
)
427
428
async def set_config_default(self, keyword: str | list[str]):
429
"""return {"status": True}"""
430
return await self.call({"mode": "set_config_default", "keyword": keyword})
431
432
async def get_config(self, section: str = None, keyword: str = None):
433
"""return config as dic"""
434
return await self.call(
435
{"mode": "get_config", "section": section, "keyword": keyword}
436
)
437
438
async def set_config(self, section: str, keyword: str, value: str):
439
"""Returns the new setting when saved successfully"""
440
return await self.call(
441
{
442
"mode": "set_config",
443
"section": section,
444
"keyword": keyword,
445
"value": value,
446
}
447
)
448
449
async def set_special_config(self, section: str, items: dict):
450
"""Returns the new setting when saved successfully"""
451
return await self.call(
452
{
453
"mode": "set_config",
454
"section": section,
455
**items,
456
}
457
)
458
459
async def server_stats(self):
460
"""return {
461
"day": 2352634799,
462
"week": 32934490677,
463
"month": 179983557488,
464
"total": 728426161290,
465
"servers": {
466
"eunews.server.com": {
467
"week": 19783288936,
468
"total": 163741252273,
469
"day": 2352634799,
470
"month": 90478917031,
471
"daily": {
472
"2017-01-28": 1234,
473
"2017-01-29": 4567
474
},
475
"articles_tried": 929299,
476
"articles_success": 8299
477
},
478
"News.server.net": {
479
"week": 13151201741,
480
"total": 165783396295,
481
"day": 0,
482
"month": 89499300889,
483
"daily": {
484
"2017-01-28": 1234,
485
"2017-01-29": 4567
486
},
487
"articles_tried": 520400,
488
"articles_success": 78881
489
}
490
}
491
}"""
492
return await self.call({"mode": "server_stats"})
493
494
async def version(self):
495
"""return {'version': '4.2.2'}"""
496
return await self.call({"mode": "version"})
497
498
async def restart(self):
499
"""return {"status": True}"""
500
return await self.call({"mode": "restart"})
501
502
async def restart_repair(self):
503
"""return {"status": True}"""
504
return await self.call({"mode": "restart_repair"})
505
506
async def shutdown(self):
507
"""return {"status": True}"""
508
return await self.call({"mode": "shutdown"})
509
510