Skip to content

Commit 5786c71

Browse files
committed
Merge branch 'api6'
2 parents 00187c6 + 934e86e commit 5786c71

3 files changed

Lines changed: 74 additions & 11 deletions

File tree

.gitignore

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
1+
.idea/
22
__pycache__/ampache.cpython-37.pyc
33
*.pyc
4-
ampache.egg-info/*
5-
dist/ampache-*-py*.egg
6-
src/ampache.egg-info/*
4+
ampache.egg-info/
75
build/lib/ampache.py
6+
dist/
7+
docs/examples/ampache.py
8+
src/ampache.egg-info/
9+
venv/
810
test*.py
9-
.idea/
1011
get_art.jpg
1112
*ampyche.conf
12-
docs/examples/ampache.py
1313
build_docs.conf

src/_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"""
1515

1616
__author__ = "Lachlan de Waard (lachlan-00)"
17-
__version__ = "6.6.0"
17+
__version__ = "6.6.1"
1818

1919
DEBUG = False

src/ampache.py

Lines changed: 67 additions & 4 deletions
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
--------------------------------------------
@@ -37,6 +37,7 @@ class API(object):
3737

3838
def __init__(self):
3939
self.AMPACHE_API = 'xml'
40+
self.AMPACHE_VERSION = '6.6.0'
4041
self.AMPACHE_SERVER = ''
4142
self.AMPACHE_DEBUG = False
4243
self.DOCS_PATH = 'docs/'
@@ -96,6 +97,23 @@ def set_debug_path(self, path_string: str):
9697
"""
9798
self.DOCS_PATH = path_string
9899

100+
def set_version(self, myversion: str):
101+
""" set_version
102+
103+
Allow forcing a default API version
104+
105+
api3 = '390001'
106+
api4 = '443000'
107+
api5 = '5.5.6'
108+
api6 = '6.6.0'
109+
110+
INPUTS
111+
* myversion = (string) '6.6.0'|'390001'
112+
"""
113+
if self.AMPACHE_DEBUG:
114+
print('AMPACHE_VERSION set to ' + myversion)
115+
self.AMPACHE_VERSION = myversion
116+
99117
def set_user(self, myuser: str):
100118
""" set_user
101119
@@ -104,6 +122,8 @@ def set_user(self, myuser: str):
104122
INPUTS
105123
* myuser = (string) ''
106124
"""
125+
if self.AMPACHE_DEBUG:
126+
print('AMPACHE_USER set to ' + myuser)
107127
self.AMPACHE_USER = myuser
108128

109129
def set_key(self, mykey: str):
@@ -114,6 +134,8 @@ def set_key(self, mykey: str):
114134
INPUTS
115135
* mykey = (string) ''
116136
"""
137+
if self.AMPACHE_DEBUG:
138+
print('AMPACHE_KEY set to ' + mykey)
117139
self.AMPACHE_KEY = mykey
118140

119141
def set_url(self, myurl: str):
@@ -124,6 +146,8 @@ def set_url(self, myurl: str):
124146
INPUTS
125147
* myurl = (string) ''
126148
"""
149+
if self.AMPACHE_DEBUG:
150+
print('AMPACHE_URL set to ' + myurl)
127151
self.AMPACHE_URL = myurl
128152

129153
def set_config_path(self, path: str):
@@ -281,7 +305,19 @@ def get_id_list(self, data, attribute: str):
281305
except (KeyError, TypeError):
282306
id_list.append(data['id'])
283307
except (KeyError, TypeError):
284-
pass
308+
try:
309+
if data[0]['id']:
310+
for data_object in data:
311+
try:
312+
id_list.append(data_object[0]['id'])
313+
except (KeyError, TypeError):
314+
id_list.append(data_object['id'])
315+
try:
316+
id_list.append(data[0]['id'])
317+
except (KeyError, TypeError):
318+
id_list.append(data['id'])
319+
except (KeyError, TypeError):
320+
pass
285321

286322
return id_list
287323

@@ -597,7 +633,7 @@ def lost_password(self):
597633
$username;
598634
$key = hash('sha256', 'email');
599635
auth = hash('sha256', $username . $key);
600-
)
636+
)
601637
"""
602638
ampache_url = self.AMPACHE_URL + '/server/' + self.AMPACHE_API + '.server.php'
603639
data = {'action': 'goodbye',
@@ -3713,11 +3749,14 @@ def bookmark_edit(self, filter_id, object_type,
37133749
'type': object_type,
37143750
'position': position,
37153751
'client': client,
3716-
'date': date}
3752+
'date': date,
3753+
'include': include}
37173754
if not client:
37183755
data.pop('client')
37193756
if not date:
37203757
data.pop('date')
3758+
if not include:
3759+
data.pop('include')
37213760
data = urllib.parse.urlencode(data)
37223761
full_url = ampache_url + '?' + data
37233762
ampache_response = self.fetch_url(full_url, self.AMPACHE_API, 'bookmark_edit')
@@ -3998,3 +4037,27 @@ def user_update(self, username, password=False, fullname=False, email=False,
39984037
website, state, city, disable, maxbitrate,
39994038
fullname_public, reset_apikey, reset_streamtoken, clear_stats)
40004039

4040+
def execute(self, method: str, params=None):
4041+
if params is None:
4042+
params = {}
4043+
match method:
4044+
case 'handshake':
4045+
if not "version" in params:
4046+
params["version"] = self.AMPACHE_VERSION
4047+
if not "ampache_url" in params:
4048+
params["ampache_url"] = self.AMPACHE_URL
4049+
if not "ampache_api" in params:
4050+
params["ampache_api"] = self.AMPACHE_KEY
4051+
if not "ampache_user" in params:
4052+
params["ampache_user"] = self.AMPACHE_USER
4053+
if not "timestamp" in params or params["timestamp"] == 0:
4054+
return self.handshake(params["ampache_url"], self.encrypt_string(params["ampache_api"], params["ampache_user"]), False,
4055+
False, params["version"])
4056+
return self.handshake(params["ampache_url"], self.encrypt_password(params["ampache_api"], int(params["timestamp"])), params["ampache_user"],
4057+
int(params["timestamp"]), params["version"])
4058+
case 'ping':
4059+
if not "ampache_url" in params:
4060+
params["ampache_url"] = self.AMPACHE_URL
4061+
if not "ampache_api" in params:
4062+
params["ampache_api"] = self.AMPACHE_KEY
4063+
return self.ping(params["ampache_url"], params["ampache_api"])

0 commit comments

Comments
 (0)