4 from mpdaio.client import MPDClient
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)
15 # Explicit host declaration
16 #client = MPDClient(host='example.org', port='6601')
20 # MPDClient use MPD_HOST/MPD_PORT env var if set
21 # else test ${XDG_RUNTIME_DIR}/mpd/socket for existence
22 # finnally fallback to localhost:6600
24 # Make an initial connection to MPD server
25 # The connection is kept open an reused for later commands
28 status = await client.status()
29 if status.get('state') == 'play':
30 current_song_id = status.get('songid')
31 current_song = await client.playlistid(current_song_id)
32 log.info(f'Playing : {current_song[0].get("file")}')
33 next_song_id = status.get('nextsongid', None)
35 next_song = await client.playlistid(next_song_id)
36 log.info(f'Next song : {next_song[0].get("file")}')
38 log.info('Not playing')
40 # Closes any remaining connections to MPD server
44 if __name__ == '__main__':