Skip to content

Instantly share code, notes, and snippets.

@trygveaa
Created March 20, 2017 21:33
Show Gist options
  • Save trygveaa/d512cad510cbc3a92cafeea8c567ea12 to your computer and use it in GitHub Desktop.
Save trygveaa/d512cad510cbc3a92cafeea8c567ea12 to your computer and use it in GitHub Desktop.
#!/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";
sleep 5;
print $server "pause 0\n";
print $server "idle player\n";
}
}
$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