]> kaliko git repositories - python-musicpdaio.git/blob - doc/source/tutorial/tutorial-01.py
Update documentation
[python-musicpdaio.git] / doc / source / tutorial / tutorial-01.py
1 import asyncio
2 import logging
3
4 from mpdaio import MPDClient
5
6 # Configure loggers
7 logging.basicConfig(level=logging.INFO, format='%(levelname)-8s %(message)s')
8 logging.getLogger("asyncio").setLevel(logging.WARNING)
9 # debug level level will show where defaults settings come from
10 log = logging.getLogger('mpdaio.client')
11 log.setLevel(logging.DEBUG)
12
13
14 async def search(fltr):
15     # Look for and add
16     await client.searchadd(fltr)
17
18
19 async def run():
20
21     # Make an initial connection to MPD server
22     # The connection is kept open an reused for later commands
23     await client.ping()
24     await client.clear()
25     filters = [
26             '(Artist == "Neurosis")',
27             '(Artist == "Isis")',
28             '(Artist == "Cult of Luna")',
29             ]
30     # Each task gathered here will run with it's own connection
31     await asyncio.gather(*map(search, filters))
32
33     # Closes all connections to MPD server
34     await client.close()
35
36
37 if __name__ == '__main__':
38     # Use defaults to access MPD server
39     client = MPDClient()
40     asyncio.run(run())