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