Created
March 20, 2017 12:32
-
-
Save trygveaa/746d13679c86e525c1c33e87cdee4e16 to your computer and use it in GitHub Desktop.
MPD pause on song change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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