Skip to content

Instantly share code, notes, and snippets.

@gammy
Created September 13, 2017 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gammy/00e670efb0411f661f88e386e81b667b to your computer and use it in GitHub Desktop.
Save gammy/00e670efb0411f661f88e386e81b667b to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use warnings;
use strict;
my $song_file = '/export/home/gammy/.current_song';
my $ices_file = '/export/home/gammy/.ices_metadata';
my $ices_pidfile = '/export/home/gammy/.ices.pid';
sub read_file {
my $filename = shift;
open my $fh, '<', $filename or die "$filename: $!";
# Read a single line
my $buffer = <$fh>;
close $fh;
chomp $buffer;
return $buffer;
}
sub ices_poke {
my $ices_pid = '';
if(-e $ices_pidfile) {
$ices_pid = read_file($ices_pidfile);
}
if("$ices_pid" eq "" or
"$ices_pid" !~ m/\d+/) {
print STDERR "IceS doesn't appear to be running\n";
return(1);
}
print "IceS PID: $ices_pid\n";
kill 'SIGUSR1', ($ices_pid);
return(0);
}
my $buf_old = '';
my $buf_new = '';
for(;;) {
$buf_new = read_file($song_file);
if("$buf_new" ne "$buf_old") {
my $title = $buf_new;
my $artist = '';
if($buf_new=~m/(.*?[^-]) - (.*$)/) {
$artist = $1;
$title = $2;
}
$buf_old = $buf_new;
open my $fh, '>', $ices_file or die "$ices_file: $!";
print $fh "TITLE=$title\n";
print $fh "ARTIST=$artist\n";
print $fh "ALBUM=\n";
print $fh "CONTACT=\n";
close $fh;
print "\n";
print "TITLE=$title\n";
print "ARTIST=$artist\n";
print "ALBUM=\n";
print "CONTACT=\n";
sleep(2);
ices_poke();
}
sleep(5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment