5 from mpdaio import MPDClient
8 logging.basicConfig(level=logging.INFO, format='%(levelname)-8s %(message)s')
9 logging.getLogger("asyncio").setLevel(logging.WARNING)
10 # debug level level will show where defaults settings come from
11 log = logging.getLogger('mpdaio.client')
12 log.setLevel(logging.DEBUG)
16 # Explicit host declaration
17 #client = MPDClient(host='example.org', port='6601')
21 # MPDClient use MPD_HOST/MPD_PORT env var if set
22 # else test ${XDG_RUNTIME_DIR}/mpd/socket for existence
23 # finnally fallback to localhost:6600
25 # Make an initial connection to MPD server
26 # The connection is kept open an reused for later commands
30 status = await client.status()
31 if status.get('state') == 'play':
32 current_song_id = status.get('songid')
33 current_song = await client.playlistid(current_song_id)
34 log.info(f'Playing : {current_song[0].get("file")}')
35 next_song_id = status.get('nextsongid', None)
37 next_song = await client.playlistid(next_song_id)
38 log.info(f'Next song : {next_song[0].get("file")}')
40 log.info('Not playing')
42 # Add all songs form artist "The Doors"
43 await client.searchadd('(Artist == "The Doors")')
45 if (await client.status()).get('state') != 'play':
49 # Closes any remaining connections to MPD server
53 if __name__ == '__main__':