librespot icon indicating copy to clipboard operation
librespot copied to clipboard

Authenticate on startup?

Open pmpinto opened this issue 1 month ago • 2 comments

I have been trying to set up spotify-player, which apparently uses librespot in the background and I wasn't able to get audio playing from the terminal window. Speakers work. Audio works. Spotify works in the official client for Linux or the phone. But getting spotify player in the terminal to actually output sound isn't working.

So I then tried to set up and run librespot myself.

~ ❯ librespot --name "Omarchy" --device-type "Computer" --initial-volume 100 --bitrate 320
[2025-11-08T19:18:45Z INFO  librespot] librespot 0.7.1 84a33021 (Built on 2025-11-08, Build ID: 1762609304, Profile: release)
[2025-11-08T19:18:45Z INFO  librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0)
[2025-11-08T19:18:45Z INFO  librespot_playback::convert] Converting with ditherer: tpdf
[2025-11-08T19:18:45Z INFO  librespot_playback::audio_backend::rodio] Using Rodio sink with format S16 and cpal host: ALSA
[2025-11-08T19:18:45Z INFO  librespot_playback::audio_backend::rodio] Using audio device: default

I hear a "pff" sound when doing this, which tells me something is working. But at this point:

  • Spotify on my phone recognizes Omarchy as device;
  • spotify-player however, does not see it;

Only after I select Omarchy from my phone, is spotify player able to see it and list it as a device option. When that happens, I'm able to select it, and the sound works! This is the output after the previous one:

[2025-11-08T19:19:01Z WARN  librespot_core::apresolve] Failed to resolve all access points, using fallbacks
[2025-11-08T19:19:01Z WARN  librespot_core::apresolve] Resolve access points error: Service unavailable { client error (Connect) }
[2025-11-08T19:19:01Z INFO  librespot_core::session] Connecting to AP "ap.spotify.com:443"
[2025-11-08T19:19:02Z INFO  librespot_core::session] Authenticated as 'pmpinto' !
[2025-11-08T19:19:02Z INFO  librespot_core::session] Country: "PT"
[2025-11-08T19:19:02Z WARN  librespot_core::apresolve] Failed to resolve all access points, using fallbacks
[2025-11-08T19:19:02Z WARN  librespot_core::apresolve] Resolve access points error: Service unavailable { client error (Connect) }
[2025-11-08T19:19:03Z WARN  librespot_core::apresolve] Failed to resolve all access points, using fallbacks
[2025-11-08T19:19:03Z WARN  librespot_core::apresolve] Resolve access points error: Service unavailable { client error (Connect) }
[2025-11-08T19:19:03Z INFO  librespot_core::spclient] Resolved "spclient.wg.spotify.com:443" as spclient access point
[2025-11-08T19:19:03Z INFO  librespot_connect::spirc] active device is <> with session <REDACTED>
[2025-11-08T19:19:03Z WARN  librespot_connect::state::context] couldn't load context info because: context is not available. type: Default
[2025-11-08T19:19:04Z INFO  librespot_playback::player] Loading <Invincible> with Spotify URI <spotify:track:2gihj2AY74b7sFYWeMnN0z>
[2025-11-08T19:19:05Z INFO  librespot_playback::player] <Invincible> (222433 ms) loaded

So, I wanted to check if there's a way to achieve the workflow I had in mind:

  1. Turn on the computer;
  2. Launch librespot in the background;
  3. Launch spotify-player in the foregroung;
  4. Check the devices available, and select the one from librespot;
  5. Play some music — without ever launching the Spotify app on my phone or computer;

Is this possible?

And yes, I'm aware spotify-player runs librespot but it's failing to output any audio in the first place. Not sure why. Tried plenty of stuff, incluing building my own build from the repo.

pmpinto avatar Nov 08 '25 19:11 pmpinto

Did you try to reach out to the devs of spotify-player, yet? I think you shouldn't try to workaround, if it's not totally necessary, and rather resolve your issue with the devs of the software you are trying to use.

Btw. since around four days the latest published version of librespot can't play any tracks anymore. That's because of some changes on spotifys end. We did resolve it in our dev build but there isn't any published version yet, so build spotify-player with librespot as git dependency could also resolve your issue. And it seems this issue is what you are looking for https://github.com/aome510/spotify-player/issues/864.

photovoltex avatar Nov 08 '25 20:11 photovoltex

Did you try to reach out to the devs of spotify-player, yet?

No I haven't. I had to start somewhere, and since spotify player uses librespot in the background as the backend I figured it would be related to librespot more than spotify player itself. But I could be wrong.

Btw. since around four days the latest published version of librespot can't play any tracks anymore. That's because of some changes on spotifys end. We did resolve it in our dev build but there isn't any published version yet, so build spotify-player with librespot as git dependency could also resolve your issue. And it seems this issue is what you are looking for aome510/spotify-player#864.

Ok. A few things pop in my head.
Although that's good to know, I had been able to play songs through librespot with the workflow I mentioned above, although not ideal.

And although I did face the "skipping songs" issue as well, I wonder if before this whole issue appeared, the workflow I'm trying to achieve would be feasable in the first place—can you confirm this?

Thanks!

pmpinto avatar Nov 10 '25 13:11 pmpinto

Your description is to vague to answer fully. So what I can answer:

  1. is a manual step I suppose?
  2. you can automated this via a service (depends on your system you are using)
  3. seems like another manual step
  4. I'm not sure if this should be done automatically, and if so you can use the web-api for that
  5. seems like another manual step

photovoltex avatar Nov 10 '25 15:11 photovoltex

Looks like you are focusing on automating these tasks and that's not at all what I'm struggling with. Let's just assume I'm doing everything manually.

The issue I'm currently facing with that workflow—and again, I don't know whether or not this may have been caused by the issue you mentioned above—is the fact that the Spotify Connect device that librepsot enables/creates is passive and thus not available within spotify player. It only becomes active when I select it from my phone's app, for instance. Which is when the auth happens in the logs:

[2025-11-08T19:19:02Z INFO  librespot_core::session] Authenticated as 'pmpinto' !

I was hoping there was a way for this auth to happen at the same time the Spotify Connect device is created by librespot.

I'm just not sure whether this is a librespot limitation, Spotify's API limitation, spotify player limitation or whatever it may be.

pmpinto avatar Nov 10 '25 16:11 pmpinto

Oh... Providing more context what you are trying to achieve and where you are coming from helps a lot. You are searching for the --cache <directory where to save the cache> option which caches your credentials and some more info.

In combination with --enable-oauth you can also authenticate without a separate device. But authentication is only required at the beginning, afterwards it will use from the cache if applicable.

photovoltex avatar Nov 10 '25 17:11 photovoltex

I'm glad we could reach common ground. And indeed, following your suggestions does make it work!

If I understand this correctly, providing a --cache directory allows librespot to fetch the credentials on startup. Effectively completing the necessary handshake for a Spotify Connect device to become active without any further human intervention.

I was just failing to connect "authentication" and "cache" in my head.

Thanks for your time @photovoltex !

pmpinto avatar Nov 10 '25 19:11 pmpinto