2

The only thing i need to extract from mpd is the currently played song/track. I have to ensure this always is up to date in the output file.

jhansen
  • 33
  • 1
  • 3
  • What format do you want the information about the currently-played song to appear in? How are you talking to the server? Are you using `mpc`, or a library like `ruby-mpd`? – Phrogz Jan 20 '16 at 00:24
  • The format only need to be as simple as Artist - Songname. Currently im only using the mpd module in ampache (localplay). I can certainly install whatever client/module that is most practical to extract this information from mpd. – jhansen Jan 20 '16 at 16:06

1 Answers1

6

If you install mpc then you can do the following:

mpc idle player # block until the player changes songs
mpc current     # outputs "Artist Name - Song Name" onto stdout

Do those in a loop, and output the result of current into a file, and you're done!

#!/bin/sh
while true
do
  mpc current > current_song.txt
  mpc idle player
done

The full list of what you can idle for is on the MPD command reference:
http://www.musicpd.org/doc/protocol/command_reference.html#status_commands

Phrogz
  • 296,393
  • 112
  • 651
  • 745
  • Just a note for anyone like me who tried using this to record number of times a track was played, it won't work: `mpc idle player` fires not only for current song changes, but also when player is paused and unpaused. – Kied Llaentenn Sep 02 '23 at 12:19