Skip to content

Commit eec7760

Browse files
committed
Update README.rst
1 parent 6845523 commit eec7760

2 files changed

Lines changed: 41 additions & 34 deletions

File tree

README.rst

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,52 @@ The class documentation has been extracted out into a markdown file for easier r
1818

1919
`<https://raw.githubusercontent.com/ampache/python3-ampache/master/docs/MANUAL.md>`_
2020

21-
There has been a pretty significant change in the library between Ampache 4 and Ampache 5.
22-
23-
For anyone wanting to stay on v4 the branch has been separated from the master branch.
24-
25-
`<https://github.com/ampache/python3-ampache/tree/api4>`_
21+
This library supports connecting to any Ampache API release (3, 4, 5 and 6)
2622

2723
Once you connect with your passphrase or api key, the url and auth token are stored allowing you to call methods without them.
2824

2925
.. code-block:: python3
3026
3127
import ampache
28+
import sys
3229
import time
3330
34-
# connect to the server
31+
# Open Ampache library
3532
ampache_connection = ampache.API()
3633
37-
# if using password auth use encrypt_password
38-
mytime = int(time.time())
39-
passphrase = ampache_connection.encrypt_password('mypassword', mytime)
40-
auth = ampache_connection.handshake('https://music.com.au', passphrase, 'my username', mytime)
34+
# Set your server details
35+
ampache_connection.set_version('6.6.1')
36+
ampache_connection.set_url('https://music.com.au')
37+
ampache_connection.set_key('mypassword')
38+
ampache_connection.set_user('myusername')
4139
42-
# if using an API key auth keep using encrypt_string
43-
passphrase = ampache_connection.encrypt_string('my apikey', 'my username')
44-
auth = ampache_connection.handshake('https://music.com.au', passphrase)
40+
# Password auth requires a timestamp for encrypting the auth key
41+
ampache_session = ampache_connection.execute('handshake', {'timestamp': int(time.time())})
42+
if not ampache_session:
43+
# if using an api key you don't need the timestamp to use encrypt_string
44+
ampache_session = ampache_connection.execute('handshake')
45+
46+
# Fail if you didn't connect
47+
if not ampache_session:
48+
sys.exit(ampache_connection.AMPACHE_VERSION + ' ERROR Failed to connect to ' + ampache_connection.AMPACHE_URL)
4549
4650
# now you can call methods without having to keep putting in the url and userkey
47-
ampache_connection.label(1677)
48-
49-
# ping has always allowed empty calls so you have to ping with a url and session still
50-
ampache_connection.ping('https://music.com.au', auth)
51+
artists = ampache_connection.execute('artists', {'limit': 10})
52+
53+
# You can parse a response to get a list of ID's for that response
54+
artist_ids = ampache_connection.get_id_list(artists, 'artist')
55+
if artist_ids:
56+
print("We found some artists")
57+
for artist in artist_ids:
58+
print('ID:', artist)
59+
60+
# ping has always allowed empty calls so you have to ping with a session key
61+
ampache_connection.execute('ping', {'ampache_api': ampache_session})
5162
5263
NEWS
5364
====
5465

55-
- Password handshake auth is available now.
56-
- This library now supports every Ampache API release (3, 4, 5 and 6)
66+
- Examples are being updated to support the latest execute method which can simplify your code
5767
- You can save and restore from a json config file using new methods
5868

5969
- set_config_path: Set a folder to your config path
@@ -89,7 +99,7 @@ ampyche.py help:
8999
90100
/u:%CUSTOM_USER% (Custom username for the current action)
91101
/k:%CUSTOM_APIKEY% (Custom apikey for the current action)
92-
/a:%ACTION% (ping, playlists, localplay, download, configure, logout, showconfig)
102+
/a:%ACTION% (ping, playlists, localplay, download, list, configure, logout, showconfig)
93103
/l:%LIMIT% (integer)
94104
/o:%OBJECT_ID% (string)
95105
/t:%OBJECT_TYPE% (song, playlist)
@@ -100,7 +110,7 @@ ampyche.py help:
100110
(next, prev, stop, play, pause, add, volume_up,
101111
volume_down, volume_mute, delete_all, skip, status)
102112
103-
Here is a short code sample for python using version 5.x.x+ to scrobble a track to your server
113+
Here is a short code sample for python using version 6.x.x+ to scrobble a track to your server
104114

105115
.. code-block:: python3
106116
@@ -113,17 +123,11 @@ Here is a short code sample for python using version 5.x.x+ to scrobble a track
113123
114124
# load up previous config
115125
if not ampache_connection.get_config():
116-
# user variables
117-
api_version = '6.6.1'
118-
ampache_url = 'https://music.server'
119-
ampache_api_key = 'mysuperapikey'
120-
ampache_user = 'myusername'
121-
122-
# Set your details
123-
ampache_connection.set_version(api_version)
124-
ampache_connection.set_url(ampache_url)
125-
ampache_connection.set_key(ampache_api_key)
126-
ampache_connection.set_user(ampache_user)
126+
# Set your details manually if we can't get anything
127+
ampache_connection.set_version('6.6.1')
128+
ampache_connection.set_url('https://music.server')
129+
ampache_connection.set_key('mysuperapikey')
130+
ampache_connection.set_user('myusername')
127131
128132
# Get a session key using the handshake
129133
#
@@ -151,7 +155,10 @@ Here is a short code sample for python using version 5.x.x+ to scrobble a track
151155
# * mbalbum = (string) album mbid //optional
152156
# * stime = (integer) UNIXTIME() //optional
153157
# * client = (string) //optional
154-
ampache_connection.execute('scrobble', {'title': 'Beneath The Cold Clay', 'artist_name': 'Crust', 'album_name': '...and a Dirge Becomes an Anthem', 'stime': int(time.time())})
158+
ampache_connection.execute('scrobble', {'title': 'Beneath The Cold Clay',
159+
'artist_name': 'Crust',
160+
'album_name': '...and a Dirge Becomes an Anthem',
161+
'stime': int(time.time())})
155162
156163
LINKS
157164
=====

docs/examples/ampyche.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def show_help():
5252
"\n Possible Actions:\n"
5353
"\n /u:%CUSTOM_USER%\t(Custom username for the current action)"
5454
"\n /k:%CUSTOM_APIKEY%\t(Custom apikey for the current action)"
55-
"\n /a:%ACTION% \t(ping, playlists, localplay, stream, download list, configure, logout, showconfig)"
55+
"\n /a:%ACTION% \t(ping, playlists, localplay, stream, download, list, configure, logout, showconfig)"
5656
"\n /l:%LIMIT% \t(integer)"
5757
"\n /o:%OBJECT_ID% \t(string)"
5858
"\n /t:%OBJECT_TYPE% \t(song, playlist)"

0 commit comments

Comments
 (0)