danielvijge / SqueezeCloud

SoundCloud plugin for Squeezebox
GNU General Public License v2.0
25 stars 11 forks source link

v0.12 not streaming on Win10/LMS8.3.0 #37

Closed pupvogel closed 3 years ago

pupvogel commented 3 years ago

Hi folks,

I just upgraded from v0.11 to v0.12 - unfortunately both my "soft and hard" players (Squeezelite-X / Squeezebox Classic) still won't stream, log says:

Plugins::SqueezeCloud::ProtocolHandler::getNextTrack (175) Getting track from soundcloud for 1035193807 Plugins::SqueezeCloud::ProtocolHandler::gotNextTrack (123) https://api.soundcloud.com/tracks/1035193807/stream Plugins::SqueezeCloud::ProtocolHandler::gotNextTrack (132) Redirecting stream to Plugins::SqueezeCloud::ProtocolHandler::gotNextTrack (139) setting soundcloud_meta_1035193807 Slim::Player::Song::open (491) Warning: stream failed to open [soundcloud://1035193807].

I created and entered a new API key to make sure it's not the issue. I also tried playing via Browser and the Soundcloud-Site (no LMS involved), that works. Tried both available download/stream settings.

Any ideas where else to look..? 8o)

danielvijge commented 3 years ago

The third log message should contain the actual URL. It should come from the location header of the second log message. if you have curl (or a similar tool) installed you could try curl -I --request GET --url https://api.soundcloud.com/tracks/1035193807/stream --header 'Authorization: OAuth <YOUR_API_KEY_HERE>' This should display a header Location with the actual URL.

One thing I see is that in the source code it tried to get location, but the header is Location. Headers shoudn't be case sensitive, but maybe one Windows it works differently that on Linux. If you can test that theory, you can try editing the plugin files directly.

Change 'location' to 'Location' and restart LMS.

pupvogel commented 3 years ago

Hi Daniel,

thanks for looking into this !

I changed location to Location, but that didn't do it. BUT: It seems to be the quotes !

I tried the curl-request, and that brings an error (and no location) if I just copy it as is - but if I use DOUBLE-quotes instead of the single-quotes, it works..! So I guess that's the problem, right..? Can I change the quotes in those .pm-files, too ?

Best Ken

danielvijge commented 3 years ago

Sure, you can always try changing 'location' to "location" and see if it makes a difference.

pupvogel commented 3 years ago

Hm no, that doesn't make a difference. If I understand the code correctly (I'm obviously not getting too much of it, sorry...), at the time the 'location' - string is used in the scripts, the request that fails is already done..?

I think something fails in this line: my $res = $ua->get($stream, getAuthenticationHeaders() ); or in this one: my $res = $ua->get( getStreamURL($json), getAuthenticationHeaders() );

...maybe somehow related to those quotes, or some other formatting problem...?

pupvogel commented 3 years ago

I dug into it a bit, I edited the ProtocolHandler to print the header that is returned from the soundcloud-url, it looks like this:

Content-Type: text/plain Client-Date: Sat, 11 Sep 2021 11:48:48 GMT Client-Warning: Internal response

That's all - so no wonder we can't find a location... I deactivated my firewall, but that didn't change it.

What could be the problem here..? The Mixcloud-Plugin works, by the way.

danielvijge commented 3 years ago

You can try adding the following lines of code before the lines that have location in it (in two files):

    use Data::Dumper;
    $log->debug(Dumper($res));

Restart LMS, and make sure your log settings for the SoundCloud plugin are set to debug. This will print everything related to the request and the response received. Note that is also contains the request headers that have your API key in there. Best to remove that before posting it here.

pupvogel commented 3 years ago

Ok, this is the output:

$VAR1 = bless( { '_content' => 'Can\'t connect to api.soundcloud.com:443

', '_rc' => 500, '_headers' => bless( { 'client-warning' => 'Internal response', 'client-date' => 'Sat, 11 Sep 2021 12:20:25 GMT', 'content-type' => 'text/plain', '::std_case' => { 'client-warning' => 'Client-Warning', 'client-date' => 'Client-Date' } }, 'HTTP::Headers' ), '_msg' => 'Can\'t connect to api.soundcloud.com:443', '_request' => bless( { '_content' => '', '_uri' => bless( do{(my $o = 'https://api.soundcloud.com/tracks/933922618/stream')}, 'URI::https' ), '_headers' => bless( { 'user-agent' => 'libwww-perl/6.44', 'authorization' => 'OAuth 3-82597-339387193-blablabla' }, 'HTTP::Headers' ), '_method' => 'GET' }, 'HTTP::Request' ) }, 'HTTP::Response' );

pupvogel commented 3 years ago

...and the curl-request works on the same machine, I get the location-string when running curl from the command line.

danielvijge commented 3 years ago

I dug up an old Windows machine to try and test this myself. The "good" news is that I can reproduce this, so it's a real bug, and not something related to a specific machine or network. The bad news is that I haven't been able to solve it yet.

Below some details of my investigation, for my own future reference, and maybe for other developers looking into this.

The plugin uses the default Perl library LWP::UserAgent. A request from this library to api.soundcloud.com always seems to fail with an Internal response error. LMS also provides its own HTTP library Slim::Networking::SimpleAsyncHTTP. To use this, it needs to make the request but ignore any redirects. According to the documentation maxRedirects => 0 should do that. But even with this parameters, redirects are still followed, and the plugin cannot set the actual streamURL. No idea if I do something wrong, or it is a bug in LMS.

Another totally different approach would be to actually set https://api.soundcloud.com/tracks/$id/stream as the streamURL, and let the player figure out all the redirects. However, that would require adding the authentication headers to the HTTP call that the player must do. Need to investigate if this is possible. (And it might be using requestString()).

danielvijge commented 3 years ago

Fixed by 952f42b090d759a730b88402894d9ccf3cfba96d Could you try 0.12.2 from the beta repository?

pupvogel commented 3 years ago

Perfect, works like a charm, thank you !!!