Skip to content

Instantly share code, notes, and snippets.

@JamesTheBard
Last active December 18, 2015 03:38
Show Gist options
  • Save JamesTheBard/5719391 to your computer and use it in GitHub Desktop.
Save JamesTheBard/5719391 to your computer and use it in GitHub Desktop.
Perl script to grab mpd status and information.
#!/usr/bin/env perl
use Switch;
# Grab the first line from 'mpc' and throw it into
@song = split("\n", `mpc 2>&1`);
switch ($song[0]) {
case /Connection refused/ { print "MPD not running\n" }
case /^volume/ { print "Music playback stopped\n"}
else {
$time_regex = qr/[0-9]+:[0-9]+/;
$playing_regex = qr/\[[a-z]+]/;
$song[1] =~ /($playing_regex).+($time_regex)\/($time_regex)/;
print "${song[0]} [$2/$3]\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment