File: connect.py

package info (click to toggle)
python-musicpd 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 484 kB
  • sloc: python: 792; makefile: 6
file content (29 lines) | stat: -rw-r--r-- 894 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()