Add api.playlist_clear and api.playlist_remove
This commit is contained in:
parent
98d67c0444
commit
b3a2a1fb78
|
@ -13,6 +13,19 @@ def set_endpoint(base_url:str):
|
||||||
class APIError(Exception): pass
|
class APIError(Exception): pass
|
||||||
|
|
||||||
# decorator:
|
# 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):
|
def request_post(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def new_func(*args, **kwargs):
|
def new_func(*args, **kwargs):
|
||||||
|
@ -73,6 +86,15 @@ def playlist_next():
|
||||||
def playlist_previous():
|
def playlist_previous():
|
||||||
return f"playlist/previous", None
|
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
|
@request_get
|
||||||
def get_playback_pos():
|
def get_playback_pos():
|
||||||
return f"time"
|
return f"time"
|
||||||
|
|
Loading…
Reference in New Issue