Audio-RPLD
view release on metacpan or search on metacpan
lib/Audio/RPLD.pm view on Meta::CPAN
sub q_ple {
my ($e, $ple) = @_;
return $ple;
}
sub q_iot {
my ($e, $io) = @_;
return $io;
}
sub q_plt {
my ($e, $plt) = @_;
return uc($plt);
}
#-------------
# parsers:
sub p_ple {
my ($e, $ple) = @_;
my $r = {};
my @p = split(/=/, $ple);
my @t;
local $_;
#0 1 2 3 4 5 6 7 8 9 10
#unknown=00:00:00=ALBUM=TITLE=ARTIST=PERFORMER=VERSION=FILE=long:0xBED9000000000373/short:0xBE0003AA/uuid:0c26ea9c-5f37-48e3-b338-8895b1a84dfe=0xDISCID/TN=GENRE(GID)=LIKENESS
# $r->{'raw'} = {'data' => $ple, 'splited' => \@p};
foreach (@p) {
if ( $_ eq '*' ) {
$_ = undef;
next;
}
if ( $_ eq '' ) {
$_ = undef;
}
}
if ( $p[0] eq 'unknown' ) {
$r->{'codec'} = undef;
} else {
$r->{'codec'} = $p[0];
}
@t = split(/:/, $p[1]);
$r->{'length'} = $t[-1] + $t[-2] * 60 + $t[-3] * 3600;
$r->{'length'} = undef unless $r->{'length'};
$r->{'file'} = $p[7];
$r->{'meta'} = {'album' => $p[2], 'title' => $p[3], 'artist' => $p[4], 'performer' => $p[5], 'version' => $p[6]};
if ( $p[8] =~ m#^(long:0x[0-9a-fA-F]{16})/(short:0x[0-9a-fA-F]{8})(?:/(uuid:[0-9a-fA-F-]{36}))?$# ) {
$r->{'longid'} = $1;
$r->{'shortid'} = $2;
$r->{'uuid'} = $3 if $3;
}
if ( $p[9] =~ m#^(0x[0-9a-fA-F]{8})/(\d+)$# ) {
$r->{'meta'}->{'discid'} = hex($1) if $1;
$r->{'meta'}->{'tracknumber'} = int($2) if $2;
$r->{'meta'}->{'discid'} = undef unless $r->{'meta'}->{'discid'};
if ( $r->{'meta'}->{'discid'} ) {
$r->{'meta'}->{'totaltracks'} = $r->{'meta'}->{'discid'} & 0xFF;
}
}
if ( $p[10] =~ m#^(.+)\((0x[0-9a-fA-F]+)\)$# ) {
if ( $2 !~ /^0xf+$/i ) {
$r->{'meta'}->{'genre'} = $1 if $1;
$r->{'meta'}->{'genreid'} = hex($2) if $2;
}
}
if ( defined($p[11]) ) {
$r->{'likeness'} = $p[11]+0;
}
return $r;
}
sub p_playlist {
my ($e, $playlist) = @_;
my $c;
my ($k, $v);
local $_;
$c = {'id' => int($1), 'parent' => int($2), 'name' => $3, 'children' => []};
$playlist =~ /^\s*(\d+):\s*\[([^\]]+)\]\s*"(.+?)"$/ or return undef;
$c = {'id' => int($1), 'name' => $3, 'children' => []};
foreach (split(/, /, $2)) {
($k, $v) = /^([^:]+):\s(.+)$/;
$k =~ tr/ /_/;
if ( $k eq 'backend' ) {
$v =~ s/^"(.+)"$/$1/;
} elsif ( $k eq 'volume' ) {
$v =~ s/^(\d+)\/65535$/$1/;
$v = int($v);
} elsif ( $k eq 'history' ) {
$v = int($v);
} elsif ( $k eq 'history_size' ) {
$v = int($v);
} elsif ( $k eq 'mixer' ) {
$v = int($v);
$v = undef if $v == -1;
}
$c->{lc($k)} = $v;
}
return $c;
}
# This is very similar to p_playlist(). Maybe they should be merged.
lib/Audio/RPLD.pm view on Meta::CPAN
The name of the used codec.
=item length (optional)
The playback length in seconds.
=item file
The filename. This may be anything supported by RoarAudio's DSTR. Including local files, web radio streams and other types.
=item meta
The value for the meta key is a hashref of it's own to a list of provided meta data.
The following keys may be included. All are optional. Other keys may also be included.
=over 8
=item album
Name of the album.
=item title
Title of the song.
=item artist
Name of the Artist.
=item performer
Name of the performer for this record.
=item version
Version of this record.
=item discid
CDDB DiscID for this song.
=item tracknumber
Tracknumber of this song in the album.
=item totaltracks
Total number of tracks in this album.
=item genre
Genre of this song.
=item genreid
Genre ID of this song.
=back
=item longid
The long GTN for the entry.
=item shortid
The short GTN for the entry.
=item uuid (optional)
The UUID for the entry.
=item likeness (optional)
The likeness value stored by the server.
This is a float in rage from zero to infinity.
The bigger the value is the more the song is liked.
=back
=cut
sub like {
my ($e, $ple, $likeness) = @_;
my @q = ('LIKE', $e->q_ple($ple), ($likeness+0 || 1));
my $r = $e->cmd(@q);
return undef unless defined($r);
return $_[0]->is_ok($r);
}
=pod
=head3 $res = $rpld-E<gt>like($ple[, $likeness])
Tells the server that the user likes this entry.
Optionally tells the server how much. A value of +1.0 is the default if no value is given.
This is added to the likeness value stored by the server.
A value of zero has no effect. A negative value indicates dislikeness.
See dislike() for more information about dislikeness.
=cut
sub dislike {
my ($e, $ple, $likeness) = @_;
my @q = ('DISLIKE', $e->q_ple($ple), $likeness+0 || 1);
my $r = $e->cmd(@q);
return undef unless defined($r);
return $_[0]->is_ok($r);
}
=pod
=head3 $res = $rpld-E<gt>dislike($ple[, $likeness])
This is the same as like() just marks a the given entry as disliked.
Optionally tells the server how much. A value of +1.0 is the default if no value is given.
The value is subtracted from server's value.
lib/Audio/RPLD.pm view on Meta::CPAN
my ($e, $pointer, $ple, $pli) = @_;
my @q = (uc($pointer), $e->q_ple($ple));
my $r;
if ( $pli ) {
push(@q, 'FROM');
push(@q, $e->q_pli($pli));
}
$r = $_[0]->cmd('SETPOINTER', @q);
return undef unless defined($r);
return $_[0]->is_ok($r);
}
=pod
=head3 $res = $rpld-E<gt>setpointer($pointer, $ple[, $playlist])
Set the given pointer to the given playlist entry. If no playlist is given the currently selected one is used.
=cut
sub unsetpointer {
my ($e, $pointer) = @_;
my $r;
$r = $_[0]->cmd('UNSETPOINTER', uc($pointer));
return undef unless defined($r);
return $_[0]->is_ok($r);
}
=pod
=head3 $res = $rpld-E<gt>unsetpointer($pointer)
Unset the given pointer.
=cut
sub showpointer {
my ($e, $pointer) = @_;
my $q;
my $r = {};
my $plent;
local $_;
$q = $e->cmd_data('SHOWPOINTER', $pointer ? (uc($pointer)) : ());
return undef unless $e->is_ok(shift(@{$q}));
foreach (@{$q}) {
if ( /^POINTER (.+) NOT SET$/ ) {
$r->{$1} = {};
} elsif ( /^POINTER (.+?) IS AT (.+)/ ) {
$r->{$1} = {'plent' => $plent = {'raw' => $2}};
if ( $plent->{'raw'} =~ /^long:/ ) {
$plent->{'longid'} = $plent->{'raw'};
} elsif ( $plent->{'raw'} =~ /^short:/ ) {
$plent->{'shortid'} = $plent->{'raw'};
} elsif ( $plent->{'raw'} =~ /^uuid:/ ) {
$plent->{'uuid'} = $plent->{'raw'};
} elsif ( $plent->{'raw'} =~ /^random:(\d+)$/ ) {
$plent->{'playlist'} = int($1);
$plent->{'random'} = $plent->{'raw'};
} elsif ( $plent->{'raw'} =~ /^randomlike:(\d+)$/ ) {
$plent->{'playlist'} = int($1);
$plent->{'randomlike'} = $plent->{'raw'};
}
}
}
return $r;
}
=pod
=head3 $res = $rpld-E<gt>showpointer([$pointer])
Returns information about the given or all pointers.
The return value is a hashref with keys of the pointer names.
The values for those keys are a hashref containing information on the corresponding pointer.
If the hashref for the pointer points to a empty hash (no keys defined) then the pointer is not defined.
If the pointer is defined the following keys are contained:
=over
=item raw
The playlist entry the pointer points to in a raw format.
=item longid (optional)
If the pointer contains an information about the playlist entries long GTN this GTN.
=item shortid (optional)
If the pointer contains an information about the playlist entries short GTN this GTN.
=item uuid (optional)
If the pointer contains an information about the playlist entries UUID this UUID.
=item random (optional)
If the pointer points to a random song within a playlist this contains the corresponding search string.
=item randomlike (optional)
If the pointer points to a random song (respecting likeness) within a playlist this
contains the corresponding search string.
=item playlist (optional)
If the pointer contains a playlist hint this contains the playlist ID.
=back
=cut
# -- CLIENTS:
=pod
=head2 Clients
=cut
sub listclients {
my ($e) = @_;
my $q = $e->cmd_data('LISTCLIENTS');
my @r;
local $_;
return undef unless defined($q);
return undef unless $e->is_ok(shift(@{$q}));
while (($_ = shift(@{$q}))) {
push(@r, p_client($e, $_));
}
return \@r;
}
=pod
=head3 $res = $rpld-E<gt>listclients()
Get a list of clients connected to the server.
This returns a arrayref to a array containing a hashref for each client. This hash contains the following keys:
( run in 1.135 second using v1.01-cache-2.11-cpan-ceb78f64989 )