Skip to content

Instantly share code, notes, and snippets.

@trygveaa
Created March 20, 2017 12:32
Show Gist options
  • Save trygveaa/746d13679c86e525c1c33e87cdee4e16 to your computer and use it in GitHub Desktop.
Save trygveaa/746d13679c86e525c1c33e87cdee4e16 to your computer and use it in GitHub Desktop.
MPD pause on song change
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use IO::Socket::INET6;
my $current_song;
if (my $server = IO::Socket::INET6->new(PeerAddr => ($ARGV[0] or 'localhost'), PeerPort => ($ARGV[1] or '6600'), Proto => 'tcp', Timeout => 5)) {
print $server "currentsong\n";
print $server "idle player\n";
while (<$server>) {
if (/^file: (.*)/) {
if ($current_song) {
if ($1 ne $current_song) {
print $server "noidle\n";
print $server "pause 1\n";
print $server "close\n";
}
} else {
$current_song = $1;
}
} elsif (/^changed:/) {
print $server "currentsong\n";
print $server "idle player\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment