9 For now the code is in early development stage. No releases are made.
14 python -m venv .../path/to/my/venv
15 . .../path/to/my/venv/bin/activate
16 pip install git+https://codeberg.org/MusicPlayerDaemon/python-musicpdaio.git@main
21 Updating a previous installation via `pip install git+https`.
26 .. index:: single: command; searchadd
28 **Connect, clear the queue, add tracks**
30 .. sourcecode:: python
34 client = mpdaio.MPDClient()
35 await client.ping() # Plain connection test
36 print(client.version) # Prints MPD's protocol version
37 print(await client.clear()) # Clears the current queue
38 # Add all tracks from artist "Amon Tobin"
39 print(await client.searchadd('(Artist == "Amon Tobin")'))
41 await client.setvol(60)
42 print(await client.currentsong())
43 await client.close() # Finally close connection
45 .. index:: single: command; password
47 **Using a specific host, port and a password.**
49 The password is sent when a connection is made, no need to explicitly send the
52 .. sourcecode:: python
54 client = mpdaio.MPDClient(host='example.org', port='6601', password='53(237')
57 **Wrapping some commands in a python script**
59 .. literalinclude:: tutorial/tutorial-00.py
61 .. index:: single: command; albumart
63 **Fetch album art for the given track**
65 The logic is similar with `readpicture` command.
67 .. sourcecode:: python
69 client = mpdaio.MPDClient()
70 # Looking for cover art in 'Tool/2001-Lateralus/'
71 track = 'Tool/2001-Lateralus/09-Tool - Lateralus.flac'
72 aart = await cli.albumart(track, 0)
73 received = int(aart.get('binary'))
74 size = int(aart.get('size'))
75 with open('/tmp/cover', 'wb') as cover:
76 # aart = {'size': 42, 'binary': 2051, data: bytes(...)}
77 cover.write(aart.get('data'))
78 while received < size:
79 aart = await cli.albumart(track, received)
80 cover.write(aart.get('data'))
81 received += int(aart.get('binary'))
83 print('something went wrong')
86 Cf. `MPD protocol documentation`_ for more binary responses.
92 .. literalinclude:: tutorial/tutorial-01.py
95 .. _MPD protocol documentation: http://www.musicpd.org/doc/protocol/
96 .. vim: spell spelllang=en