line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
package Mplayer::NowPlaying; |
3
|
1
|
|
|
1
|
|
75050
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
6
|
require Exporter; |
7
|
1
|
|
|
1
|
|
5
|
use vars qw(@ISA @EXPORT_OK $VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
78
|
|
8
|
1
|
|
|
|
|
2
|
$VERSION = '0.032'; |
9
|
1
|
|
|
|
|
12
|
@ISA = 'Exporter'; |
10
|
1
|
|
|
|
|
19
|
@EXPORT_OK = qw(now_playing now_playing_stream); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
10
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
14
|
1
|
|
|
1
|
|
338
|
use Mplayer::NowPlaying::Genres; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
552
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub now_playing { |
18
|
0
|
|
|
0
|
1
|
|
my($log, $mode) = @_; |
19
|
0
|
0
|
|
|
|
|
not defined $log and Carp::croak("No mplayer log file specified\n"); |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if(!defined($mode)) { |
22
|
0
|
|
|
|
|
|
$mode = 'default'; # mplayer *.mp3 |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $fh = _get_fh($log); |
26
|
0
|
|
|
|
|
|
chomp(my @content = <$fh>); |
27
|
0
|
|
|
|
|
|
close($fh); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my %mplayer_internals = ( |
30
|
|
|
|
|
|
|
ID_CLIP_INFO_VALUE0 => 'title', |
31
|
|
|
|
|
|
|
ID_CLIP_INFO_VALUE1 => 'artist', |
32
|
|
|
|
|
|
|
ID_CLIP_INFO_VALUE2 => 'album', |
33
|
|
|
|
|
|
|
ID_CLIP_INFO_VALUE3 => 'year', |
34
|
|
|
|
|
|
|
ID_CLIP_INFO_VALUE4 => 'comment', |
35
|
|
|
|
|
|
|
ID_CLIP_INFO_VALUE5 => 'genre', |
36
|
|
|
|
|
|
|
ID_AUDIO_BITRATE => 'bitrate', |
37
|
|
|
|
|
|
|
ID_AUDIO_CODEC => 'codec', |
38
|
|
|
|
|
|
|
ID_AUDIO_FORMAT => 'format', |
39
|
|
|
|
|
|
|
ID_AUDIO_ID => 'id', |
40
|
|
|
|
|
|
|
ID_AUDIO_NCH => 'channels', |
41
|
|
|
|
|
|
|
ID_CHAPTERS => 'chapters', |
42
|
|
|
|
|
|
|
ID_AUDIO_RATE => 'audio', |
43
|
|
|
|
|
|
|
ID_DEMUXER => 'demuxer', |
44
|
|
|
|
|
|
|
ID_LENGTH => 'length', |
45
|
|
|
|
|
|
|
ID_SEEKABLE => 'seekable', # 1,0 |
46
|
|
|
|
|
|
|
ID_START_TIME => 'start', |
47
|
|
|
|
|
|
|
ID_FILENAME => 'file', |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $regex; |
52
|
0
|
0
|
|
|
|
|
if($mode eq 'default') { |
|
|
0
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$regex = qr/\s* |
54
|
|
|
|
|
|
|
( |
55
|
|
|
|
|
|
|
codec |
56
|
|
|
|
|
|
|
| Bitrate |
57
|
|
|
|
|
|
|
| File |
58
|
|
|
|
|
|
|
| chapters |
59
|
|
|
|
|
|
|
| demuxer |
60
|
|
|
|
|
|
|
| seekable |
61
|
|
|
|
|
|
|
| id |
62
|
|
|
|
|
|
|
| channels |
63
|
|
|
|
|
|
|
| genre |
64
|
|
|
|
|
|
|
| Artist |
65
|
|
|
|
|
|
|
| Album |
66
|
|
|
|
|
|
|
| length |
67
|
|
|
|
|
|
|
| Comment |
68
|
|
|
|
|
|
|
| format |
69
|
|
|
|
|
|
|
| Title |
70
|
|
|
|
|
|
|
| Year |
71
|
|
|
|
|
|
|
| start |
72
|
|
|
|
|
|
|
)[=:](.+)\b |
73
|
|
|
|
|
|
|
/x; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
elsif($mode eq 'identify') { # mplayer -msglevel identify=4 |
77
|
0
|
|
|
|
|
|
my $id = join('|', keys(%mplayer_internals)); |
78
|
0
|
|
|
|
|
|
$regex = qr/\b($id\S+)=(.+)\b/o; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my %information; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
CONTENT: |
84
|
0
|
|
|
|
|
|
for my $l(@content) { |
85
|
0
|
0
|
|
|
|
|
if($l =~ m/$regex/) { |
86
|
0
|
|
|
|
|
|
my($tag, $value) = ($1, $2); |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if(exists($mplayer_internals{$tag})) { # identify used |
89
|
0
|
|
|
|
|
|
$tag = $mplayer_internals{$tag}; |
90
|
0
|
0
|
|
|
|
|
if($tag eq 'genre') { |
91
|
0
|
|
|
|
|
|
$value = get_genre($value); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$value =~ s/^\s+|\s+$//; |
96
|
0
|
|
|
|
|
|
$information{ lc($tag) } = $value; |
97
|
0
|
|
|
|
|
|
next CONTENT; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
return \%information; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub now_playing_stream { |
104
|
0
|
|
|
0
|
1
|
|
my $log = shift; |
105
|
0
|
|
|
|
|
|
my $fh = _get_fh($log); |
106
|
0
|
|
|
|
|
|
chomp(my @content = <$fh>); |
107
|
0
|
|
|
|
|
|
close($fh); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my %results; |
110
|
0
|
|
|
|
|
|
for my $line(reverse(@content)) { |
111
|
0
|
0
|
|
|
|
|
if($line =~ m/ICY Info: StreamTitle='(.+)';.+/m) { |
112
|
0
|
|
|
|
|
|
$results{icy} = $1; |
113
|
0
|
0
|
|
|
|
|
if($results{icy} =~ m/(.+) - (.+) - (.+)/) { |
114
|
0
|
|
|
|
|
|
$results{album} = $1; |
115
|
0
|
|
|
|
|
|
$results{artist} = $2; |
116
|
0
|
|
|
|
|
|
$results{title} = $3; |
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
|
last; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
0
|
|
|
|
|
|
return \%results; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _get_fh { |
125
|
0
|
|
|
0
|
|
|
my $file = shift; |
126
|
0
|
0
|
|
|
|
|
not defined $file and Carp::croak("No logfile specified\n"); |
127
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
if(ref($file)) { |
129
|
0
|
|
|
|
|
|
return $file; |
130
|
|
|
|
|
|
|
} |
131
|
0
|
0
|
|
|
|
|
open(my $fh, '<', $file) or croak("Can not open '$file': $!\n"); |
132
|
0
|
|
|
|
|
|
return $fh; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |