Skip to content

Commit

Permalink
Merge branch 'api6'
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlan-00 committed Aug 28, 2024
2 parents 00187c6 + 934e86e commit 5786c71
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 11 deletions.
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

.idea/
__pycache__/ampache.cpython-37.pyc
*.pyc
ampache.egg-info/*
dist/ampache-*-py*.egg
src/ampache.egg-info/*
ampache.egg-info/
build/lib/ampache.py
dist/
docs/examples/ampache.py
src/ampache.egg-info/
venv/
test*.py
.idea/
get_art.jpg
*ampyche.conf
docs/examples/ampache.py
build_docs.conf
2 changes: 1 addition & 1 deletion src/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"""

__author__ = "Lachlan de Waard (lachlan-00)"
__version__ = "6.6.0"
__version__ = "6.6.1"

DEBUG = False
71 changes: 67 additions & 4 deletions src/ampache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


"""
Copyright (C)2023 Ampache.org
Copyright (C)2024 Ampache.org
--------------------------------------------
Ampache XML and JSON Api library for python3
--------------------------------------------
Expand Down Expand Up @@ -37,6 +37,7 @@ class API(object):

def __init__(self):
self.AMPACHE_API = 'xml'
self.AMPACHE_VERSION = '6.6.0'
self.AMPACHE_SERVER = ''
self.AMPACHE_DEBUG = False
self.DOCS_PATH = 'docs/'
Expand Down Expand Up @@ -96,6 +97,23 @@ def set_debug_path(self, path_string: str):
"""
self.DOCS_PATH = path_string

def set_version(self, myversion: str):
""" set_version
Allow forcing a default API version
api3 = '390001'
api4 = '443000'
api5 = '5.5.6'
api6 = '6.6.0'
INPUTS
* myversion = (string) '6.6.0'|'390001'
"""
if self.AMPACHE_DEBUG:
print('AMPACHE_VERSION set to ' + myversion)
self.AMPACHE_VERSION = myversion

def set_user(self, myuser: str):
""" set_user
Expand All @@ -104,6 +122,8 @@ def set_user(self, myuser: str):
INPUTS
* myuser = (string) ''
"""
if self.AMPACHE_DEBUG:
print('AMPACHE_USER set to ' + myuser)
self.AMPACHE_USER = myuser

def set_key(self, mykey: str):
Expand All @@ -114,6 +134,8 @@ def set_key(self, mykey: str):
INPUTS
* mykey = (string) ''
"""
if self.AMPACHE_DEBUG:
print('AMPACHE_KEY set to ' + mykey)
self.AMPACHE_KEY = mykey

def set_url(self, myurl: str):
Expand All @@ -124,6 +146,8 @@ def set_url(self, myurl: str):
INPUTS
* myurl = (string) ''
"""
if self.AMPACHE_DEBUG:
print('AMPACHE_URL set to ' + myurl)
self.AMPACHE_URL = myurl

def set_config_path(self, path: str):
Expand Down Expand Up @@ -281,7 +305,19 @@ def get_id_list(self, data, attribute: str):
except (KeyError, TypeError):
id_list.append(data['id'])
except (KeyError, TypeError):
pass
try:
if data[0]['id']:
for data_object in data:
try:
id_list.append(data_object[0]['id'])
except (KeyError, TypeError):
id_list.append(data_object['id'])
try:
id_list.append(data[0]['id'])
except (KeyError, TypeError):
id_list.append(data['id'])
except (KeyError, TypeError):
pass

return id_list

Expand Down Expand Up @@ -597,7 +633,7 @@ def lost_password(self):
$username;
$key = hash('sha256', 'email');
auth = hash('sha256', $username . $key);
)
)
"""
ampache_url = self.AMPACHE_URL + '/server/' + self.AMPACHE_API + '.server.php'
data = {'action': 'goodbye',
Expand Down Expand Up @@ -3713,11 +3749,14 @@ def bookmark_edit(self, filter_id, object_type,
'type': object_type,
'position': position,
'client': client,
'date': date}
'date': date,
'include': include}
if not client:
data.pop('client')
if not date:
data.pop('date')
if not include:
data.pop('include')
data = urllib.parse.urlencode(data)
full_url = ampache_url + '?' + data
ampache_response = self.fetch_url(full_url, self.AMPACHE_API, 'bookmark_edit')
Expand Down Expand Up @@ -3998,3 +4037,27 @@ def user_update(self, username, password=False, fullname=False, email=False,
website, state, city, disable, maxbitrate,
fullname_public, reset_apikey, reset_streamtoken, clear_stats)

def execute(self, method: str, params=None):
if params is None:
params = {}
match method:
case 'handshake':
if not "version" in params:
params["version"] = self.AMPACHE_VERSION
if not "ampache_url" in params:
params["ampache_url"] = self.AMPACHE_URL
if not "ampache_api" in params:
params["ampache_api"] = self.AMPACHE_KEY
if not "ampache_user" in params:
params["ampache_user"] = self.AMPACHE_USER
if not "timestamp" in params or params["timestamp"] == 0:
return self.handshake(params["ampache_url"], self.encrypt_string(params["ampache_api"], params["ampache_user"]), False,
False, params["version"])
return self.handshake(params["ampache_url"], self.encrypt_password(params["ampache_api"], int(params["timestamp"])), params["ampache_user"],
int(params["timestamp"]), params["version"])
case 'ping':
if not "ampache_url" in params:
params["ampache_url"] = self.AMPACHE_URL
if not "ampache_api" in params:
params["ampache_api"] = self.AMPACHE_KEY
return self.ping(params["ampache_url"], params["ampache_api"])

0 comments on commit 5786c71

Please sign in to comment.