X-Git-Url: https://git.kaliko.me/?p=python-musicpd.git;a=blobdiff_plain;f=doc%2Fsource%2Fexamples%2Fconnect.py;fp=doc%2Fsource%2Fexamples%2Fconnect.py;h=0c744488615901a5e5f0411c465622408d56b5c0;hp=0000000000000000000000000000000000000000;hb=c7b2fbbb9689a180f220322b21e2b0bef798eb68;hpb=43a63d085fab34f337ceec232e29e5760f4fcc25 diff --git a/doc/source/examples/connect.py b/doc/source/examples/connect.py new file mode 100644 index 0000000..0c74448 --- /dev/null +++ b/doc/source/examples/connect.py @@ -0,0 +1,30 @@ +import musicpd +import logging + +import musicpd + +# Set logging to debug level +# it should log messages showing where defaults come from +logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s') +log = logging.getLogger() + +client = musicpd.MPDClient() +# use MPD_HOST/MPD_PORT env var if set else +# test ${XDG_RUNTIME_DIR}/mpd/socket for existence +# fallback to localhost:6600 +# connect support host/port argument as well +client.connect() + +status = client.status() +if status.get('state') == 'play': + current_song_id = status.get('songid') + current_song = client.playlistid(current_song_id)[0] + log.info(f'Playing : {current_song.get("file")}') + next_song_id = status.get('nextsongid', None) + if next_song_id: + next_song = client.playlistid(next_song_id)[0] + log.info(f'Next song : {next_song.get("file")}') +else: + log.info('Not playing') + +client.disconnect()