@@ -32,22 +32,22 @@ Once you connect with your passphrase or api key, the url and auth token are sto
3232 import time
3333
3434 # connect to the server
35- ampacheConnection = ampache.API()
35+ ampache_connection = ampache.API()
3636
3737 # if using password auth use encrypt_password
3838 mytime = int(time.time())
39- passphrase = ampacheConnection .encrypt_password('mypassword', mytime)
40- auth = ampacheConnection .handshake('https://music.com.au', passphrase, 'my username', mytime)
39+ passphrase = ampache_connection .encrypt_password('mypassword', mytime)
40+ auth = ampache_connection .handshake('https://music.com.au', passphrase, 'my username', mytime)
4141
4242 # if using an API key auth keep using encrypt_string
43- passphrase = ampacheConnection .encrypt_string('my apikey', 'my username')
44- auth = ampacheConnection .handshake('https://music.com.au', passphrase)
43+ passphrase = ampache_connection .encrypt_string('my apikey', 'my username')
44+ auth = ampache_connection .handshake('https://music.com.au', passphrase)
4545
4646 # now you can call methods without having to keep putting in the url and userkey
47- ampacheConnection .label(1677)
47+ ampache_connection .label(1677)
4848
4949 # ping has always allowed empty calls so you have to ping with a url and session still
50- ampacheConnection .ping('https://music.com.au', auth)
50+ ampache_connection .ping('https://music.com.au', auth)
5151
5252 NEWS
5353====
@@ -104,24 +104,54 @@ Here is a short code sample for python using version 5.x.x+ to scrobble a track
104104
105105.. code-block :: python3
106106
107- import time
108107 import ampache
108+ import sys
109+ import time
109110
110- # user variables
111- ampache_url = 'https://music.server'
112- my_api_key = 'mysuperapikey'
113- user = 'myusername'
114-
115- # processed details
116- ampacheConnection = ampache.API()
117- encrypted_key = ampacheConnection.encrypt_string(my_api_key, user)
118- ampache_session = ampacheConnection.handshake(ampache_url, encrypted_key)
119-
120- if ampache_session:
121- # Scrobble a music track to your ampache server
122- Process(target=ampacheConnection.scrobble,
123- args=('Beneath The Cold Clay', 'Crust', '...and a Dirge Becomes an Anthem',
124- '', '', '', int(time.time()))).start()
111+ # Open Ampache library
112+ ampache_connection = ampache.API()
113+
114+ # load up previous config
115+ 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)
127+
128+ # Get a session key using the handshake
129+ #
130+ # * ampache_url = (string) Full Ampache URL e.g. 'https://music.com.au'
131+ # * ampache_api = (string) encrypted apikey OR password if using password auth
132+ # * user = (string) username //optional
133+ # * timestamp = (integer) UNIXTIME() //optional
134+ # * version = (string) API Version //optional
135+ ampache_session = ampache_connection.execute('handshake')
136+
137+ # Fail if you didn't connect
138+ if not ampache_session:
139+ sys.exit(ampache_connection.AMPACHE_VERSION + ' ERROR Failed to connect to ' + ampache_connection.AMPACHE_URL)
140+
141+ # save your successful connection in your local config
142+ ampache_connection.save_config()
143+
144+ # Scrobble a music track to your ampache server
145+ #
146+ # * title = (string) song title
147+ # * artist_name = (string) artist name
148+ # * album_name = (string) album name
149+ # * mbtitle = (string) song mbid //optional
150+ # * mbartist = (string) artist mbid //optional
151+ # * mbalbum = (string) album mbid //optional
152+ # * stime = (integer) UNIXTIME() //optional
153+ # * 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())})
125155
126156 LINKS
127157=====
0 commit comments