Skip to content

Commit

Permalink
Merge pull request #489 from philippe44/Deezer
Browse files Browse the repository at this point in the history
Deezer flac seeking for IP3K
  • Loading branch information
mherger committed Dec 27, 2020
2 parents 1336694 + 62383d3 commit 85ac338
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions Slim/Plugin/Deezer/ProtocolHandler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ sub _gotTrack {

$info->{bitrate} = _getBitratePlaceholder($info->{url});
$info->{type} = _getFormatPlaceholder($info->{url});
my ($trackId, $format) = _getStreamParams( $info->{url} );

# as we don't know the format for a flow/radio station, let's keep the format of the last played track to make assumptions later on...
$prefs->set('latestFormat', __PACKAGE__->getFormatForURL($info->{url}));
Expand Down Expand Up @@ -532,17 +533,33 @@ sub _gotTrack {
my $cache = Slim::Utils::Cache->new;
$cache->set( 'deezer_meta_' . $info->{id}, $meta, 86400 );

# Async resolve the hostname so gethostbyname in Player::Squeezebox::stream doesn't block
# When done, callback will continue on to playback
my $dns = Slim::Networking::Async->new;
$dns->open( {
Host => URI->new( $info->{url} )->host,
Timeout => 3, # Default timeout of 10 is too long,
# When doing flac, parse the header to be able to seek (IP3K)
if ($format =~ /fla?c/i) {
my $http = Slim::Networking::Async::HTTP->new;
$http->send_request( {
request => HTTP::Request->new( GET => $info->{url} ),
onStream => \&Slim::Utils::Scanner::Remote::parseFlacHeader,
onError => sub {
my ($self, $error) = @_;
$log->warn( "could not find $format header $error" );
$params->{successCb}->();
},
passthrough => [ $song->track, { cb => $params->{successCb} }, $info->{url} ],
} );
}
else {
# Async resolve the hostname so gethostbyname in Player::Squeezebox::stream doesn't block
# When done, callback will continue on to playback
my $dns = Slim::Networking::Async->new;
$dns->open( {
Host => URI->new( $info->{url} )->host,
Timeout => 3, # Default timeout of 10 is too long,
# by the time it fails player will underrun and stop
onDNS => $params->{successCb},
onError => $params->{successCb}, # even if it errors, keep going
passthrough => [],
} );
onDNS => $params->{successCb},
onError => $params->{successCb}, # even if it errors, keep going
passthrough => [],
} );
}

# Watch for playlist commands
Slim::Control::Request::subscribe(
Expand Down Expand Up @@ -592,14 +609,6 @@ sub _playlistCallback {
}
}

sub canDirectStreamSong {
my ( $class, $client, $song ) = @_;

# We need to check with the base class (HTTP) to see if we
# are synced or if the user has set mp3StreamingMethod
return $class->SUPER::canDirectStream( $client, $song->streamUrl(), $class->getFormatForURL($song->streamUrl()) );
}

# URL used for CLI trackinfo queries
sub trackInfoURL {
my ( $class, $client, $url ) = @_;
Expand Down

0 comments on commit 85ac338

Please sign in to comment.