Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 72 lines (62 sloc) 1.768 kb
#!/usr/bin/perl
# srif - Sveriges Radio Info fetcher
use XML::Simple;
use LWP::Simple;
use Data::Dumper;
use Getopt::Long;
our ($optList,$optChan);
$optChan = 2576; # 1606 => P3 Street
# 2576 => Din Gata
if(!@ARGV) {
print printAll(), "\n";
}
GetOptions('list' => \$optList,
'chan:s' => \$optChan,
'help' => \$help,
'np' => sub {print printAll(), "\n";},
);
# 1606 => P3 Street
listOld() if $optList;
if($help) {
print << "USAGE";
$0 [OPTIONS]
OPTIONS
-np show now playing for \$chanID
-c channel id
-l show playback history
-h show this help
USAGE
}
sub listOld {
my $url = "http://api.sr.se/api/playlist/playlist.aspx?programid=$optChan";
my $oldInfoC = get($url) or die;
my $x2 = XML::Simple->new;
my $oldXML = $x2->XMLin($oldInfoC);
while(my ($c, $d) = each %$oldXML) {
while(my ($id,$songInfo) = each %$d) {
while(my($infoTag,$infoData) = each %$songInfo) {
printf("%9s: %s\n", $infoTag, $infoData);
}
}
}
exit 0;
}
sub printAll {
my $url = "http://api.sr.se/api/rightnowinfo/Rightnowinfo.aspx?unit=$optChan";
my $content = get($url) or die;
my $x = XML::Simple->new;
my $np = $x->XMLin($content);
my $artist = $np->{Channel}->{Artist} // 'unknown';
my $title = $np->{Channel}->{SongTitle} // 'unknown';
my $next = $np->{Channel}->{NextSong} // 'unknown';
my $chan = $np->{Channel}->{Name} // 'unknown';
my $output;
if(!$artist and !$title) {
$output = $np->{Channel}->{Song} // 'No info';
return $output;
}
$output = sprintf("np: %s - %s | Next: %s (%s)",
$artist, $title, $next, $chan);
return $output;
exit 0;
}
Jump to Line
Something went wrong with that request. Please try again.