Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: No scrobbling when using Spotify connect #51

Closed
DieSteinhose opened this issue Sep 27, 2022 · 10 comments
Closed

BUG: No scrobbling when using Spotify connect #51

DieSteinhose opened this issue Sep 27, 2022 · 10 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@DieSteinhose
Copy link

Due to a seeming bug at Spotify, it is (currently?) not possible to get songs via the recently-played api endpoint, which were played via Spotify connect. The endpoint currently-playing shows the correct song though.

Is there a way to include this as a fallback?

Greetings

@FoxxMD
Copy link
Owner

FoxxMD commented Sep 27, 2022

Do you have evidence recently-played explicitly excludes tracks played via spotify connect? Or have you seen this occur over a prolonged period?

recently-played only updates after spotify sees you "move on" from the current track. The track needs to have been played at least 30 seconds, then the player need to have been stopped for some amount of time (minutes?) OR a new track needs to be "currently played".

Additionally, sometimes spotify doesn't updated recently-played for a long time. I've seen it stay stale for several hours at a time.

To verify:

  • Play a track for at least 50% of its play duration using spotify connect
  • Switch to the normal spotify player and play a different track for at least 50% of its play duration
  • Wait for recently-played to update -- you can check this by getting the raw list result from the MS ui

image

after recently played is updated with the song from the normal player let me know if the spotify connect track does not show in recently played.

@DieSteinhose
Copy link
Author

I first noticed this behavior a few weeks ago, and since then the Spotify connect songs were always left out.

I just went through the steps, and yes exactly. The Spotify player song are displayed there and the Spotify connect are not.

@FoxxMD
Copy link
Owner

FoxxMD commented Sep 28, 2022

Ok, thanks for verifying.

I looked into it but don't have any good news for you...

  • The recently-played documentation mentions nothing about spotify connect, specifically
  • The spotify connect documentation also does not mention anything about recently played not working or excluded
  • There are quite a few instances of recently played being inconsistent in what it tracks with more than a few mentions of spotify connect

The endpoint currently-playing shows the correct song though.

I will need to implement the existing MemorySource used for subsonic to keep track of what is currently played and also modify its behavior a bit since recently-played also returns tracks. Unfortunately I do not have much time to work on MS at the moment...earliest I'd be able to get to this is late next week or second week of Oct.

@FoxxMD FoxxMD added the bug Something isn't working label Sep 28, 2022
@DieSteinhose
Copy link
Author

hej, in the meantime I found out that it is not a bug of Spotify Connect, but of the implementation that uses the application that I use. I use HiFiBerryOS and this uses librespot at the end.

Here is the issue about it and as it seems, this will not be fixed in a timely manner either.

You said that you can implement this using the existing MemorySource. Is this a lot of work?

@FoxxMD
Copy link
Owner

FoxxMD commented Feb 8, 2023

Here is the issue about it

Thanks that was enlightening. So it seems that spotify requires the client to report that a track has been played rather than the server (spotify) keeping track of it. And that track reporting is part of their private API. So really any client using spotify connect (since its 3rd party by nature) will not have tracks played by that client reported to recently-played.

You said that you can implement this using the existing MemorySource. Is this a lot of work?

It will require refactoring either the existing Spotify implementation or MemorySource code to work as a hybrid. They are somewhat mutually exclusive right now as their "source of truth" for recently played tracks comes from totally different places.

@FoxxMD FoxxMD added enhancement New feature or request help wanted Extra attention is needed and removed bug Something isn't working labels Feb 10, 2023
@FoxxMD
Copy link
Owner

FoxxMD commented Mar 2, 2023

@DieSteinhose

Re-reading the librespot discussion it seems like "currently-playing" and "recently-played" should be intrinsically linked: if a player is reporting what is being played than it would automatically be recorded to "recently-played" by spotify (so they are not two independent actions by the client).

Since librespot is reversed engineered it has no contract to report played tracks -- the music you listened to is only downloaded by the client in order to play and spotify distinguishes between track downloaded vs. track played.

The endpoint currently-playing shows the correct song though.

I got Spot , which uses librespot under the hood, running but spotify does not return any information for currently-playing or even active devices when using it.

What endpoint are you talking about? Are you saying that when using your forked version of spotifyd from hifiberryos you get a correct response from the currently-playing endpoint?

EDIT: Scratch that. I see spotifyd is acting as a Sink/device/speaker (and is wholly different than Spot/librespot). I can see currently-played and as a device from spotify's api. Investigating recently played now...

FoxxMD added a commit that referenced this issue Mar 2, 2023
* Use recently-played to scrobble backlogged tracks
* Use currently-playing or current-state to implement spotify as a memory source in order to track plays made from spotify connect devices
@FoxxMD
Copy link
Owner

FoxxMD commented Mar 2, 2023

@DieSteinhose

I've got some changes in that should work for your scenario! Please try MS using either the git branch spotifyConnect or with the docker image foxxmd/multi-scrobbler:experimental

You should re-authenticate your spotify source after the first run to get new credentials with more permissions.

@FoxxMD
Copy link
Owner

FoxxMD commented Mar 10, 2023

Added in v0.4.2 and available in

  • master git branch
  • foxxmd/multi-scrobbler:latest docker image tag
  • foxxmd/multi-scrobbler:0.4.2 docker image tag

@FoxxMD FoxxMD closed this as completed Mar 10, 2023
@DieSteinhose
Copy link
Author

Sry for the late answer. I was on the trip, but in the meantime I updated the container. Since then there were two error messages and the scrolling stopped.

2023-03-11T08:29:45+01:00 info   : [Client Maloja - ***Maloja] Scrobbled (New)     => (Spotify) Linkin Park - Lost @ 2023-03-11T08:27:53+01:00
2023-03-11T09:40:53+01:00 warn   : [Source - Spotify - Spotify ] Request failed but retries (0) less than max (1), retrying request after 2 seconds...
2023-03-11T09:40:55+01:00 error  : [Source - Spotify - Spotify ] Request failed on retry (1) with no more retries permitted (max 1)
2023-03-11T09:40:55+01:00 error  : [Spotify                    ] WebapiError: [object Object] [{"label":"Spotify"}]
    at _toError (/app/node_modules/spotify-web-api-node/src/http-manager.js:47:10)
    at /app/node_modules/spotify-web-api-node/src/http-manager.js:71:25
    at Request.callback (/app/node_modules/superagent/lib/node/index.js:867:3)
    at IncomingMessage.<anonymous> (/app/node_modules/superagent/lib/node/index.js:1070:18)
    at Stream.emit (node:events:513:28)
    at Unzip.<anonymous> (/app/node_modules/superagent/lib/node/unzip.js:54:12)
    at Unzip.emit (node:events:513:28)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2023-03-11T09:40:55+01:00 error  : [Source - Spotify - Spotify ] Error occurred while trying to retrieve current playback state: [object Object]
2023-03-11T09:40:55+01:00 error  : [Source - Spotify - Spotify ] Error occurred while polling
2023-03-11T09:40:55+01:00 error  : [Source - Spotify - Spotify ] WebapiError: [object Object]
    at _toError (/app/node_modules/spotify-web-api-node/src/http-manager.js:47:10)
    at /app/node_modules/spotify-web-api-node/src/http-manager.js:71:25
    at Request.callback (/app/node_modules/superagent/lib/node/index.js:867:3)
    at IncomingMessage.<anonymous> (/app/node_modules/superagent/lib/node/index.js:1070:18)
    at Stream.emit (node:events:513:28)
    at Unzip.<anonymous> (/app/node_modules/superagent/lib/node/unzip.js:54:12)
    at Unzip.emit (node:events:513:28)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2023-03-11T09:40:55+01:00 warn   : [Source - Spotify - Spotify ] Poll retries (0) equal to max poll retries (0), stopping polling!

In the meantime, I have tinkered my own solution. But it works only between HifiBerry and Maloja and this is my first Python project, as a noob, this was surprising not so difficult.

But thanks for implementing the feature here.

@FoxxMD
Copy link
Owner

FoxxMD commented Mar 13, 2023

I have not been able to reproduce your error. It looks like a regular service issue upstream from spotify rather than an issue with MS. Also, the first line looks like spotify was working due to scrobbling the linkin park track?

Since then there were two error messages

Does this mean it was working fine (was tracking music and scrobbling to maloja) but then stopped at some point? That would mean it was just spotify's api being unavailable.

EDIT: Please make sure you are on the latest develop image/branch, the error logging in your logs looks a little behind what is currently available in MS. I've additionally increased the default number of retries for spotify polling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants