Add api.playlist_clear and api.playlist_remove

This commit is contained in:
Peder Bergebakken Sundt 2018-03-04 15:15:59 +01:00
parent 98d67c0444
commit b3a2a1fb78
1 changed files with 22 additions and 0 deletions

View File

@ -13,6 +13,19 @@ def set_endpoint(base_url:str):
class APIError(Exception): pass
# decorator:
# (TODO): Add logging
def request_delete(func):
@wraps(func)
def new_func(*args, **kwargs):
url, data = func(*args, **kwargs)
if type(data) is dict: data = json.dumps(data)
response = requests.delete(f"{BASE_URL}/{url}", data=data)
data = json.loads(response.text)
if "error" not in data or data["error"] != False:
print(data)
raise APIError(data["error"])
return data["success"]
return new_func
def request_post(func):
@wraps(func)
def new_func(*args, **kwargs):
@ -73,6 +86,15 @@ def playlist_next():
def playlist_previous():
return f"playlist/previous", None
@request_delete
def playlist_clear():
return f"playlist", None
@request_delete
def playlist_remove(index:int):
args = urlencode(locals())
return f"playlist?{args}", None
@request_get
def get_playback_pos():
return f"time"