Skip to content

Commit cea48e7

Browse files
committed
add an execute command to make it easier to call functions
call execute(method: str, params: dict) when you configure your lib with the properties you don't need to reqrite the url and api kell all the time
1 parent 6b700f7 commit cea48e7

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/ampache.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
"""
5-
Copyright (C)2023 Ampache.org
5+
Copyright (C)2024 Ampache.org
66
--------------------------------------------
77
Ampache XML and JSON Api library for python3
88
--------------------------------------------
@@ -3998,3 +3998,27 @@ def user_update(self, username, password=False, fullname=False, email=False,
39983998
website, state, city, disable, maxbitrate,
39993999
fullname_public, reset_apikey, reset_streamtoken, clear_stats)
40004000

4001+
def execute(self, method: str, params=None):
4002+
if params is None:
4003+
params = {}
4004+
match method:
4005+
case 'handshake':
4006+
if not "version" in params:
4007+
params["version"] = '6.6.0'
4008+
if not "ampache_url" in params:
4009+
params["ampache_url"] = self.AMPACHE_URL
4010+
if not "ampache_api" in params:
4011+
params["ampache_api"] = self.AMPACHE_KEY
4012+
if not "ampache_user" in params:
4013+
params["ampache_user"] = self.AMPACHE_USER
4014+
if not "timestamp" in params or params["timestamp"] == 0:
4015+
return self.handshake(params["ampache_url"], self.encrypt_string(params["ampache_api"], params["ampache_user"]), False,
4016+
False, params["version"])
4017+
return self.handshake(params["ampache_url"], self.encrypt_password(params["ampache_api"], int(params["timestamp"])), params["ampache_user"],
4018+
int(params["timestamp"]), params["version"])
4019+
case 'ping':
4020+
if not "ampache_url" in params:
4021+
params["ampache_url"] = self.AMPACHE_URL
4022+
if not "ampache_api" in params:
4023+
params["ampache_api"] = self.AMPACHE_KEY
4024+
return self.ping(params["ampache_url"], params["ampache_api"])

0 commit comments

Comments
 (0)