Package: ampache
AMPACHE LIBRARY FOR PYTHON3Upload to PyPIINFOA python3 library for interaction with your Ampache server using the XML & JSON APIhttps://ampache.org/API/Code examples and scripts are available from githubThe class documentation has been extracted out into a markdown file for easier reading.https://raw.githubusercontent.com/ampache/python3-ampache/master/docs/MANUAL.mdThere 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/api4Once you connect with your passphrase or api key, the url and auth token are stored allowing you to call methods without them.importampacheimporttime# connect to the serverampacheConnection=ampache.API()# if using password auth use encrypt_passwordmytime=int(time.time())passphrase=ampacheConnection.encrypt_password('mypassword',mytime)auth=ampacheConnection.handshake('https://music.com.au',passphrase,'my username',mytime)# if using an API key auth keep using encrypt_stringpassphrase=ampacheConnection.encrypt_string('my apikey','my username')auth=ampacheConnection.handshake('https://music.com.au',passphrase)# now you can call methods without having to keep putting in the url and userkeyampacheConnection.label(1677)# ping has always allowed empty calls so you have to ping with a url and session stillampacheConnection.ping('https://music.com.au',auth)NEWSPassword 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 methodsset_config_path: Set a folder to your config pathget_config: Load the config and set Ampache globalssave_config: Save the config file with the current globalsAMPACHE_URL = The URL of your Ampache serverAMPACHE_USER = config[“ampache_user”]AMPACHE_KEY = Your encrypted apikey OR password if using password authAMPACHE_SESSION = Current session auth from the handshake. Use to reconnect to an existing sessionAMPACHE_API = API output format “json” || “xml”INSTALLYou can now install from pip directly:pip3 install -U ampacheEXAMPLESThere 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.pyampyche.py help:PossibleActions:/u:%CUSTOM_USER%(Customusernameforthecurrentaction)/k:%CUSTOM_APIKEY%(Customapikeyforthecurrentaction)/a:%ACTION%(ping,playlists,localplay,download,configure,logout,showconfig)/l:%LIMIT%(integer)/o:%OBJECT_ID%(string)/t:%OBJECT_TYPE%(song,playlist)/p:%PATH%(folderfordownloads)/f:%FORMAT%(raw,mp3,ogg,flac)/usb(splitfilesintonumeric0-9foldersforcarUSBs)/c:%COMMAND%(localplaycommand)(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 serverimporttimeimportampache# user variablesampache_url='https://music.server'my_api_key='mysuperapikey'user='myusername'# processed detailsampacheConnection=ampache.API()encrypted_key=ampacheConnection.encrypt_string(my_api_key,user)ampache_session=ampacheConnection.handshake(ampache_url,encrypted_key)ifampache_session:# Scrobble a music track to your ampache serverProcess(target=ampacheConnection.scrobble,args=('Beneath The Cold Clay','Crust','...and a Dirge Becomes an Anthem','','','',int(time.time()))).start()LINKShttps://github.com/ampache/python3-ampache/https://pypi.org/project/ampache/