| 1 | package Music::KNRadio::NowPlaying; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use open qw(:utf8 :std); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | @ISA = qw(Exporter); | |||||||||
| 10 | |||||||||||
| 11 | 1 | $VERSION = '0.012'; | |||||||||
| 12 | 1 | @EXPORT_OK = qw(knnp); | |||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 1 | ▶ | use LWP::Simple; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 1 | my $url = 'http://www.knradio.se/latlist/exfile.php'; | |||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub knnp { | ||||||||
|
Subroutine
knnp: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 22 | 0 | my @content = split(/\n/, get($url)); | |||||||||
| 23 | 0 | my %now_playing = ( | |||||||||
| 24 | artist => 'undef', | ||||||||||
| 25 | title => 'undef', | ||||||||||
| 26 | state => 'undef', | ||||||||||
| 27 | ); | ||||||||||
| 28 | |||||||||||
| 29 | 0 | for my $line(reverse(@content)) { | |||||||||
| 30 | 0 | ▶ | if($line =~ m/Spelas just nu:(.+)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | ▶ | unless($1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | $now_playing{state} = 'paused'; | |||||||||
| 33 | 0 | last; | |||||||||
| 34 | } | ||||||||||
| 35 | 0 | ($now_playing{artist}, $now_playing{title}) = $1 =~ m/(.+) - (.+)/; | |||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | last unless defined $now_playing{artist}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | $now_playing{artist} =~ s/[^[:ascii:]]//g; | |||||||||
| 39 | 0 | $now_playing{title} =~ s/[^[:ascii:]]//g; | |||||||||
| 40 | 0 | $now_playing{title} =~ s/\r//g; | |||||||||
| 41 | |||||||||||
| 42 | 0 | $now_playing{state} = 'playing'; | |||||||||
| 43 | 0 | last; | |||||||||
| 44 | } | ||||||||||
| 45 | else { | ||||||||||
| 46 | 0 | $now_playing{state} = 'paused'; | |||||||||
| 47 | } | ||||||||||
| 48 | } | ||||||||||
| 49 | 0 | return \%now_playing; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | 1 | 1; | |||||||||
| 55 | |||||||||||
| 56 | __END__ | ||||||||||