hyperactivated / ampache-sonos

Enables the configuration of an ampache instance as a SONOS music service
GNU Affero General Public License v3.0
7 stars 1 forks source link

Sonos cannot log in to Ampache #1

Open gutyex opened 5 years ago

gutyex commented 5 years ago

After following the setup instructions, Sonos asks for the Ampache login when adding the service but will not accept credentials which work in the Ampache web interface.

hyperactivated commented 5 years ago

Hi @gutyex I haven't used Ampache or Sonos for a while, so it's possible that something has changed one end that has broken things, but I just installed this on the latest dev version of Ampache and the API seems to be handling authentication on that end fine. I don't have a Sonos around at the moment to test full end to end but I'm assuming that it wouldn't have asked for credentials if they no longer supported the API version being used.

A few things to check:

  1. Does the user have both streaming and API access permissions in ampache?
  2. Are there any errors in your ampache logs?
  3. Are there any errors in your apache/nginx/php logs? In particular, is there something about the SoapServer class not being found? If so, you need to install the PHP SOAP module, see https://secure.php.net/manual/en/soap.installation.php

If none of those help to resolve the issue, please provide details of the OS, webserver, PHP and ampache versions that you're using.

Thanks.

gutyex commented 5 years ago

Hi,

Server OS is Ubuntu 18.04, with apache2 and php 7.2 Installing the php-soap package resolved the login issue, however I now get the error "unable to browse music" - I can raise this as a separate issue if needed.

When I try to browse music from the Sonos app, apache's access.log shows: [27/Feb/2019:11:48:38 +0000] "POST /ampache/ampache-sonos/SonosAPI.php HTTP/1.1" 302 569 "-" "Linux UPnP/1.0 Sonos/48.2-61220 (WDCR:Microsoft Windows NT 10.0.17134)"

If I try to navigate to https://DOMAIN.REDACTED/ampache/ampache-sonos/SonosAPI.php in a browser, the browser gives a 500 error and apache's error.log shows: [Wed Feb 27 11:43:37.644102 2019] [php7:error] [pid 441] [client REDACTED] PHP Fatal error: Uncaught Error: Call to undefined function T_() in /var/www/html/ampache/ampache-sonos/SonosAPI.php:5\nStack trace:\n#0 {main}\n thrown in /var/www/html/ampache/ampache-sonos/SonosAPI.php on line 5

Permissions on the ampache-sonos folder & its contents match those on the rest of the ampache installation.

hyperactivated commented 5 years ago

Hi,

I've patched the issue that I believe was causing the 500 error that you were receiving when you opened the page in the browser, however, I don't think that this is actually related to the error you're seeing in the Sonos app. If you're still seeing Error: Call to undefined function T_() after pulling down the change then that probably means that you're missing php7.2-gettext on your Ubuntu install.

I'm going to see if I can get my hands on some Sonos hardware and work out what's going on, but it may take a couple of days.

gutyex commented 5 years ago

Installing php-gettext and pulling the updates to the repo now gives me "This service is for use by Sonos products only." when I access through a browser, but accessing via Sonos still gives me "Unable to browse music" and the 302 response in the logs.

gutyex commented 5 years ago

@hyperactivated if there's any troubleshooting I can help you with for this, let me know.

hyperactivated commented 5 years ago

@gutyex A 302 in your access log would suggest that your apache instance is redirecting the request, do you have URL re-writes in place? (Probably in .htaccess in your ampache directory, I'd guess)

gutyex commented 5 years ago

@hyperactivated the only .htaccess files on my system are in sub-directories of the ampache install: /var/www/html/ampache/channel/.htaccess /var/www/html/ampache/templates/.htaccess /var/www/html/ampache/rest/.htaccess /var/www/html/ampache/config/.htaccess /var/www/html/ampache/plex/.htaccess /var/www/html/ampache/play/.htaccess /var/www/html/ampache/daap/.htaccess /var/www/html/ampache/bin/.htaccess /var/www/html/ampache/modules/.htaccess /var/www/html/ampache/server/.htaccess /var/www/html/ampache/lib/vendor/blueimp/jQuery-File-Upload/server/php/files/.htaccess /var/www/html/ampache/lib/.htaccess /var/www/html/ampache/lib/javascript/.htaccess

I have a lets encrypt certificate installed for https support, but it doesn't seem to be set up to re-direct to https automatically - I can still load the SonosAPI.php file in a browser on plain http.

gutyex commented 5 years ago

After some changes to my setup (moving the host behind an nginx reverse proxy) I can now get lists of artists and albums but song listings still result in "Unable to browse music", and a 500 error in the logs.

hyperactivated commented 5 years ago

@gutyex can you provide the details of the 500 error from the apache error log? Also, are you able to view/play albums?

gutyex commented 5 years ago

I am not able to play anything via Sonos.

The logs look like: 192.168.0.8 - - [08/Mar/2019:14:25:51 +0000] "POST /ampache/ampache-sonos/SonosAPI.php HTTP/1.0" 500 842 "-" "Linux UPnP/1.0 Sonos/48.2-61220 (WDCR:Microsoft Windows NT 10.0.17134)"

bastoonch commented 4 years ago

@gutyex Hi Were you able to fix the issue? I have the same behaviour

Lanxor commented 4 years ago

It seems to be a mistake of the mime type.

Too few arguments to function Song::type_to_mime(), 0 passed in /folder/ampache/ampache-sonos/SonosAPI.php on line 399 and exactly 1 expected

I don't know why the type_to_mime($type) function doesn't return a matching mime. https://github.com/ampache/ampache/blob/develop/lib/class/song.class.php#L704

But I added the following code in SonosAPI.php file and it works.

https://github.com/hyperactivated/ampache-sonos/blob/master/SonosAPI.php#L391

function getSongMetadata($song_id) {
    ...

    $item['mimeType'] = 'audio/mpeg';
    switch($song->get_fields()['type']) {
        case 'mp3':
        case 'mpeg3':
            $item['mimeType'] = 'audio/mpeg';
        case 'm4a':
            $item['mimeType'] = 'audio/mp4';
    }

    ...
}

Please, checked xml communications with wireshark on a computer on which you are using the sonos desktop application if you have the http 500 error.