Python library for Ampache XML & JSON API
Project description
AMPACHE LIBRARY FOR PYTHON3
INFO
A python3 library for interaction with your Ampache server using the XML & JSON API
Code examples and scripts are available from github
The class documentation has been extracted out into a markdown file for easier reading.
https://raw.githubusercontent.com/ampache/python3-ampache/master/docs/MANUAL.md
There has been a pretty significant change in the library between Ampache 4 and Ampache 5.
For anyone wanting to stay on v4 the branch has been separated from the master branch.
https://github.com/ampache/python3-ampache/tree/api4
Once you connect with your passphrase or api key, the url and auth token are stored allowing you to call methods without them.
import ampache
import time
# connect to the server
ampache_connection = ampache.API()
# if using password auth use encrypt_password
mytime = int(time.time())
passphrase = ampache_connection.encrypt_password('mypassword', mytime)
auth = ampache_connection.handshake('https://music.com.au', passphrase, 'my username', mytime)
# if using an API key auth keep using encrypt_string
passphrase = ampache_connection.encrypt_string('my apikey', 'my username')
auth = ampache_connection.handshake('https://music.com.au', passphrase)
# now you can call methods without having to keep putting in the url and userkey
ampache_connection.label(1677)
# ping has always allowed empty calls so you have to ping with a url and session still
ampache_connection.ping('https://music.com.au', auth)
NEWS
Password handshake auth is available now.
This library now supports every Ampache API release (3, 4, 5 and 6)
You can save and restore from a json config file using new methods
set_config_path: Set a folder to your config path
get_config: Load the config and set Ampache globals
save_config: Save the config file with the current globals
AMPACHE_URL = The URL of your Ampache server
AMPACHE_USER = config[“ampache_user”]
AMPACHE_KEY = Your encrypted apikey OR password if using password auth
AMPACHE_SESSION = Current session auth from the handshake. Use to reconnect to an existing session
AMPACHE_API = API output format “json” || “xml”
INSTALL
You can now install from pip directly:
pip3 install -U ampache
EXAMPLES
There is a fairly simple cli example for windows/linux to perform a few functions. It’s a good example for testing and might make things a bit easier to follow.
https://raw.githubusercontent.com/ampache/python3-ampache/master/docs/examples/ampyche.py
ampyche.py help:
Possible Actions:
/u:%CUSTOM_USER% (Custom username for the current action)
/k:%CUSTOM_APIKEY% (Custom apikey for the current action)
/a:%ACTION% (ping, playlists, localplay, download, configure, logout, showconfig)
/l:%LIMIT% (integer)
/o:%OBJECT_ID% (string)
/t:%OBJECT_TYPE% (song, playlist)
/p:%PATH% (folder for downloads)
/f:%FORMAT% (raw, mp3, ogg, flac)
/usb (split files into numeric 0-9 folders for car USBs)
/c:%COMMAND% (localplay command)
(next, prev, stop, play, pause, add, volume_up,
volume_down, volume_mute, delete_all, skip, status)
Here is a short code sample for python using version 5.x.x+ to scrobble a track to your server
import ampache
import sys
import time
# Open Ampache library
ampache_connection = ampache.API()
# load up previous config
if not ampache_connection.get_config():
# user variables
api_version = '6.6.1'
ampache_url = 'https://music.server'
ampache_api_key = 'mysuperapikey'
ampache_user = 'myusername'
# Set your details
ampache_connection.set_version(api_version)
ampache_connection.set_url(ampache_url)
ampache_connection.set_key(ampache_api_key)
ampache_connection.set_user(ampache_user)
# Get a session key using the handshake
#
# * ampache_url = (string) Full Ampache URL e.g. 'https://music.com.au'
# * ampache_api = (string) encrypted apikey OR password if using password auth
# * user = (string) username //optional
# * timestamp = (integer) UNIXTIME() //optional
# * version = (string) API Version //optional
ampache_session = ampache_connection.execute('handshake')
# Fail if you didn't connect
if not ampache_session:
sys.exit(ampache_connection.AMPACHE_VERSION + ' ERROR Failed to connect to ' + ampache_connection.AMPACHE_URL)
# save your successful connection in your local config
ampache_connection.save_config()
# Scrobble a music track to your ampache server
#
# * title = (string) song title
# * artist_name = (string) artist name
# * album_name = (string) album name
# * mbtitle = (string) song mbid //optional
# * mbartist = (string) artist mbid //optional
# * mbalbum = (string) album mbid //optional
# * stime = (integer) UNIXTIME() //optional
# * client = (string) //optional
ampache_connection.execute('scrobble', {'title': 'Beneath The Cold Clay', 'artist_name': 'Crust', 'album_name': '...and a Dirge Becomes an Anthem', 'stime': int(time.time())})
LINKS
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ampache-6.6.3.tar.gz
.
File metadata
- Download URL: ampache-6.6.3.tar.gz
- Upload date:
- Size: 36.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9c55d4e64fb80655e55cada4123258836bbedfeb3b9c9e8dba27398864c5cf2 |
|
MD5 | 419dcfbfae576e6cb06844b63ae9a3c3 |
|
BLAKE2b-256 | f574e7e3fb75d12aa02f98956a4ca094c80e4f5de0908b2c046bf1532d7e7568 |
File details
Details for the file ampache-6.6.3-py3-none-any.whl
.
File metadata
- Download URL: ampache-6.6.3-py3-none-any.whl
- Upload date:
- Size: 36.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2d40f35e9656e1668dbefb883e882fa5464af826a5f6206fc55ace2958ccf66 |
|
MD5 | 6b00508d3c6904b19d3b4da2139cd836 |
|
BLAKE2b-256 | 1b7e639b909e5a7cd59186b6735804a3d7e83241dab921b66a351c45269ece19 |