Python and the python-dbus library.
If you are using XChat, its Python plugin must be loaded.
Simply place the script in ~/.xchat2/ and it will be loaded automatically on XChat start. Type /playing to post the currently playing track.
To print to stdout, simply execute the script. Use in other clients with /exec -out, which can be bound, e.g. (in irssi at least) /alias np exec -out - /home/myself/xchat-nowplaying.py