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 **musicpdaio** tries to come with sane defaults, then running
48 :py:class:`mpdaio.MPDClient` with no explicit argument will try default values
49 to connect to MPD. Cf. :ref:`reference` for more about
50 :ref:`defaults<default_settings>`.
52 **Using a specific host, port and a password.**
54 The password is sent when a connection is made, no need to explicitly use the
55 password command. In the following code a client is constructed with a password argument, then when the ping method is called:
57 * the client fetch a connection from the pool
58 * then a password command is sent with the password
59 * finally the ping command is sent.
61 .. sourcecode:: python
63 client = mpdaio.MPDClient(host='example.org', port='6601', password='53(237')
66 **Wrapping some commands in a python script**
68 .. literalinclude:: tutorial/tutorial-00.py
70 .. index:: single: command; albumart
72 **Fetch album art for the given track**
74 The logic is similar with `readpicture` command.
76 .. sourcecode:: python
78 client = mpdaio.MPDClient()
79 # Looking for cover art in 'Tool/2001-Lateralus/'
80 track = 'Tool/2001-Lateralus/09-Tool - Lateralus.flac'
81 aart = await cli.albumart(track, 0)
82 received = int(aart.get('binary'))
83 size = int(aart.get('size'))
84 with open('/tmp/cover', 'wb') as cover:
85 # aart = {'size': 42, 'binary': 2051, data: bytes(...)}
86 cover.write(aart.get('data'))
87 while received < size:
88 aart = await cli.albumart(track, received)
89 cover.write(aart.get('data'))
90 received += int(aart.get('binary'))
92 print('something went wrong')
95 Cf. `MPD protocol documentation`_ for more binary responses.
101 .. literalinclude:: tutorial/tutorial-01.py
103 .. vim: spell spelllang=en