forslund / spotify-skill

Mycroft Skill to control spotify using the Spotify Connect API
Apache License 2.0
71 stars 38 forks source link

No device detected though installation went well #174

Open MorrisMalone opened 2 years ago

MorrisMalone commented 2 years ago

I get a SpotifySkill | Unable to get a default device while trying to play something.

I followed the instructions and it went well (as far as I could tell). I installed raspotify and saved my username and password in the configuration file along with the device name saved on mycroft.ai. (note: the instructions say to edit /etc/default/raspotify.conf but by me, it was /etc/default/raspotify) I did change User and Group to pi.

I also executed the auth.py and gave the credentials from the Spotify Developper App page.

Finally, I did add the credentials from my premium account on mycroft.ai.

Expected behavior Music starts playing.

Log files

08:22:52.792 | INFO     |   747 | Playback Control Skill | Resolving Player for: S3 from Niro
 08:22:57.007 | INFO     |   747 | SpotifySkill | Handling "S3 from Niro" as a genric query...
 08:22:57.007 | INFO     |   747 | SpotifySkill | Checking users playlists
 08:22:57.132 | INFO     |   747 | SpotifySkill | Checking artists
 08:22:57.260 | INFO     |   747 | SpotifySkill | Checking tracks
 08:22:57.419 | INFO     |   747 | SpotifySkill | Checking albums
 08:22:57.516 | INFO     |   747 | SpotifySkill | Checking tracks
 08:22:57.913 | INFO     |   747 | Playback Control Skill |    No matches
 08:23:19.301 | INFO     |   747 | Playback Control Skill | Resolving Player for: thriller from michael jackson
 08:23:20.908 | INFO     |   747 | SpotifySkill | Handling "thriller from michael jackson" as a genric query...
 08:23:20.908 | INFO     |   747 | SpotifySkill | Checking users playlists
 08:23:20.909 | INFO     |   747 | SpotifySkill | Checking artists
 08:23:21.041 | INFO     |   747 | SpotifySkill | Checking tracks
 08:23:21.581 | INFO     |   747 | SpotifySkill | Checking albums
 08:23:21.705 | INFO     |   747 | SpotifySkill | Checking tracks
 08:23:21.950 | INFO     |   747 | SpotifySkill | Spotify confidence: 0.5842696629213483
~~~~jKrsxVxwui8LYFL'}], 'limit': 10, 'next': None, 'offset': 0, 'previous': None, 'total': 3}}, 'name': None, 'type': 'track'}
 08:23:25.453 | INFO     |   747 | Playback Control Skill | Playing with: mycroft-spotify.forslund
 08:23:25.578 | INFO     |   747 | Playback Control Skill | Audio service status: {}
 08:23:25.839 | INFO     |   747 | SpotifySkill | Device detected: DeviceType.DESKTOP
 08:23:25.839 | ERROR    |   747 | SpotifySkill | Unable to get a default device while trying to play something.

Environment (please complete the following information):

Additional context According to the logs, it seems to correctly connect to spotify and find the music. I just don't know how to fix this default device problem, though it seems to find a Device detected: DeviceType.DESKTOP

Edit I ran pactl list sinks short and got the following output:

0   alsa_output.platform-bcm2835_audio.digital-stereo   module-alsa-card.c  s16le 2ch 48000Hz   IDLE
1   alsa_output.platform-bcm2835_audio.analog-stereo    module-alsa-card.c  s16le 2ch 44100Hz   SUSPENDED

Edit 2 I opened Spotify on my smartphone and it suggested my mycroft device with the proper name. I choose it and then I could use mycroft to play the music I wanted. On Reboot it stopped working again.

forslund commented 2 years ago

Hi, thanks for reporting.

Can you please provide three things for me: The name set in raspotify, the name of the Mycroft install and the hostname of the raspberry-pi (cat /etc/hostname)

The code tries to find the local device and checks if the spotify service matches the hostname of the machine. (The log makes me think you have a name matching the hostname)

Regarding the edit 2: Do you mean that after selecting the device on your phone and playing once Mycroft could use it?

MorrisMalone commented 2 years ago

hi and thanks for the quick reply.

in raspotify which I renamed raspotify.conf (should I set it back ?): DEVICE_NAME="johan" that's the name of the device on mycroft.ai mycroft install: Picroft hostname of the machine: picroft

Regarding the edit 2: Do you mean that after selecting the device on your phone and playing once Mycroft could use it?

Yes exactly. I went on spotify on my phone and it offered me to select the device so I selected johan and it started playing on my raspberry/picroft. I could then play songs via mycroft as expected. I rebooted and then it wasn't working again.

forslund commented 2 years ago

The thing you describe here sounds a bit like raspotify is in discovery mode and not logged in.

I'll see if I can replicate when I get home from work.

forslund commented 2 years ago

Hi, looking at the raspotify.service file it looks like it's looking for the config in /etc/default/raspotify so you should probably restore the filename.

I could not reproduce the issue here but I currently don't have a raspberry Pi to test on so I've tried to recreate the scenario as best as I can on my desktop.

If a device with the same name as the mycroft unit was found it should have reported DeviceType.MYCROFT

MorrisMalone commented 2 years ago

Thanks for taking the time to look at it. I guess I will try to reinstall everything from the beginning and see how it goes. One question though, when I install the spotify-skill, the auth.py file is missing. What I did then was to git pull from the mycroft-spotify folder and then pip install the requirements.txt. Is it the right way to do it?

forslund commented 2 years ago

Yes, the mycroft-skills repo hasn't accepted the latest release yet so that sounds like the correct way to do it. Just make sure to pip install into the mycroft virtual environment using mycroft-pip (found in the mycroft-core/bin folder)

Before re-installing try to change the raspotify config file back to the original version. Also a good test is to ask what spotify devices are available it should list all available devices online connected to your spotify user or complain about some credentials or similar if there is something missing.

MorrisMalone commented 2 years ago

I uninstalled raspotify and then reinstalled it. Same problem, I still get no device available after what spotify devices are available. By going through my phone, I could select my device on the spotify app and then control it via mycroft, even when the app was closed. After changing for another song, I got this error one time:

21:28:22.819 | INFO     |   752 | Playback Control Skill | Resolving Player for: haut standing sch
 21:28:25.229 | INFO     |   752 | SpotifySkill | Handling "haut standing sch" as a genric query...
 21:28:25.230 | INFO     |   752 | SpotifySkill | Checking users playlists
 21:28:25.231 | INFO     |   752 | SpotifySkill | Checking artists
 21:28:25.367 | INFO     |   752 | SpotifySkill | Checking tracks
 21:28:25.563 | INFO     |   752 | SpotifySkill | Spotify confidence: 0.8666666666666667
~~~~R'}], 'limit': 10, 'next': None, 'offset': 0, 'previous': None, 'total': 4}}, 'name': None, 'type': 'track'}
 21:28:30.067 | INFO     |   752 | Playback Control Skill | Playing with: mycroft-spotify.forslund
 21:28:30.137 | INFO     |   752 | Playback Control Skill | Audio service status: {}
 21:28:30.449 | INFO     |   752 | SpotifySkill | Playing on an active device [johan]
 21:28:30.450 | INFO     |   752 | SpotifySkill | playing track
 21:28:30.563 | INFO     |   752 | SpotifySkill | Pausing Spotify...
~~~~m/v1/me/player/pause?device_id=496c7fde9083e4d7bb41e818429c4c140693ea31 returned 404 due to Device not found
~~~~04, code:-1 - https://api.spotify.com/v1/me/player/pause?device_id=496c7fde9083e4d7bb41e818429c4c140693ea31:
 Device not found, reason: None
 21:28:32.454 | INFO     |   752 | SpotifySkill | spotify_play: 759412786bc533369b22377bf83fb9056c5b25b2

Even though there was the returned 404 due to Device not found it played the next song on my device.

When working, it says Device detected: DeviceType.MYCROFT as you mentioned, like in the following:

21:35:04.254 | INFO     |   752 | Playback Control Skill | Resolving Player for: thriller michael jackson
 21:35:06.364 | INFO     |   752 | SpotifySkill | Handling "thriller michael jackson" as a genric query...
 21:35:06.368 | INFO     |   752 | SpotifySkill | Checking users playlists
 21:35:06.512 | INFO     |   752 | SpotifySkill | Checking artists
 21:35:06.607 | INFO     |   752 | SpotifySkill | Checking tracks
 21:35:07.003 | INFO     |   752 | SpotifySkill | Checking albums
~~~~64 | INFO     |   752 | SpotifySkill | ('thriller michael jackson', 'thriller 25 super deluxe edition', 0.5)
 21:35:07.164 | INFO     |   752 | SpotifySkill | Checking tracks
 21:35:07.362 | INFO     |   752 | SpotifySkill | Spotify confidence: 0.75
~~~~y:playlist:3tZVXBYENxj4fMpH3DUE1C'}, 'name': 'thriller - michael jackson (totally 80s)', 'type': 'playlist'}
 21:35:11.126 | INFO     |   752 | Playback Control Skill | Playing with: mycroft-spotify.forslund
 21:35:11.252 | INFO     |   752 | Playback Control Skill | Audio service status: {}
 21:35:11.266 | INFO     |   752 | SpotifySkill | Device detected: DeviceType.MYCROFT
 21:35:11.266 | INFO     |   752 | SpotifySkill | playing thriller - michael jackson (totally 80s) using johan
 21:35:13.271 | INFO     |   752 | SpotifySkill | spotify_play: 759412786bc533369b22377bf83fb9056c5b25b2

After rebooting it stops working.

I will install everything anew tomorrow and document the steps. In case I did something stupid along the way. I will let you know :)

forslund commented 2 years ago

It sounds exactly like the username and password isn't set in the Raspotify config file so it's in discovery mode. When I get your description I'll try to dig up a Raspberry Pi and set it up according to your description (probably during the weekend).