--- Slim/Plugin/RadioTime/Plugin.pm 2011-08-02 10:02:06.000000000 +0100 +++ Slim/Plugin/RadioTime/Plugin.pm 2012-03-08 18:00:41.000000000 +0000 @@ -59,12 +59,105 @@ # Bug 15569, special case for RadioTime stations, use their trackinfo menu my $rtinfo = URI->new($url)->query_form_hash; - my $serial = Digest::MD5::md5_hex( $client->uuid || $client->id ); - + + # Guard against undef $client + my $serial = Digest::MD5::md5_hex( $client->uuid || $client->id ) + if $client; + + # Include formats query parameter so we are not restricted to Radiotime's + # default mp3 & wma streams. + # In principle could use existing 'formats' attribute in $url, but + # generate afresh as it may not be present, or correct (e.g. launched from + # a favourite). + + my $formats = __PACKAGE__->rtFormats( $client ); + + # Set id query parameter to the 'sid' of the current stream (will have + # been set by RadioTime) or to the 'id' if no 'sid' defined. + # This eliminates some 'The requested item is not available' responses + # from RadioTime when playing radio shows or streams other than the + # regular live radio streams. + # TODO - Check against current RadioTime documentation. + + my $id = $rtinfo->{sid} || $rtinfo->{id}; + + # TODO - Should this be hard coded to pre-empt omission from originating + # URL ? + my $partnerId = $rtinfo->{partnerId}; + + # Extract username, if present. It may not be, as RadioTime may have + # removed the username from the originating URL. + # (NB username is no longer stored on a local LMS server). + my $username = $rtinfo->{username}; + + my %queryFormParams; + $queryFormParams{id} = $id if $id; + $queryFormParams{partnerId} = $partnerId if $partnerId; + $queryFormParams{userName} = $username if $username; + $queryFormParams{serial} = $serial if $serial; + $queryFormParams{formats} = $formats if $formats; + + + # Generate form + my $uri = URI->new('http://opml.radiotime.com/Options.ashx'); - $uri->query_form( id => $rtinfo->{id}, partnerId => $rtinfo->{partnerId}, serial => $serial ); + $uri->query_form( %queryFormParams ); return $uri->as_string; } -1; \ No newline at end of file + +# This sub has been derived from code included in Slim::Plugin::InternetRadio::Plugin. +# Could be exported therefrom... + +sub rtFormats { + + my ( $class, $client ) = @_; + + # In order of preference + tie my %rtFormats, 'Tie::IxHash', ( + aac => 'aac', + ogg => 'ogg', + mp3 => 'mp3', + wmpro => 'wmap', + wma => 'wma', + wmvoice => 'wma', + # Real Player is supported through the AlienBBC plugin + real => 'rtsp', + ); + + my @formats = keys %rtFormats; + + if ($client) { + my %playerFormats = map { $_ => 1 } $client->formats; + + # RadioTime's listing defaults to giving us mp3 and wma streams only, + # but we support a few more + @formats = grep { + + # format played natively on player? + my $canPlay = $playerFormats{$rtFormats{$_}}; + + if ( !$canPlay && main::TRANSCODING ) { + + foreach my $supported (keys %playerFormats) { + + if ( Slim::Player::TranscodingHelper::checkBin(sprintf('%s-%s-*-*', $rtFormats{$_}, $supported)) ) { + $canPlay = 1; + last; + } + + } + } + + $canPlay; + + } keys %rtFormats; + + } + + return join(',', @formats); + +} + +1;