]> kaliko git repositories - python-musicpd.git/blob - doc/source/examples/connect.py
Releasing 0.9.0
[python-musicpd.git] / doc / source / examples / connect.py
1 import logging
2
3 import musicpd
4
5 # Set logging to debug level
6 # it should log messages showing where defaults come from
7 logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s')
8 log = logging.getLogger()
9
10 client = musicpd.MPDClient()
11 # use MPD_HOST/MPD_PORT env var if set else
12 # test ${XDG_RUNTIME_DIR}/mpd/socket for existence
13 # fallback to localhost:6600
14 # connect support host/port argument as well
15 client.connect()
16
17 status = client.status()
18 if status.get('state') == 'play':
19     current_song_id = status.get('songid')
20     current_song = client.playlistid(current_song_id)[0]
21     log.info(f'Playing   : {current_song.get("file")}')
22     next_song_id = status.get('nextsongid', None)
23     if next_song_id:
24         next_song = client.playlistid(next_song_id)[0]
25         log.info(f'Next song : {next_song.get("file")}')
26 else:
27     log.info('Not playing')
28
29 client.disconnect()