FoxxMD / multi-scrobbler

Scrobble plays from multiple sources to multiple clients
https://foxxmd.github.io/multi-scrobbler
MIT License
346 stars 16 forks source link

BUG: No scrobbling when using Spotify connect #51

Closed DieSteinhose closed 1 year ago

DieSteinhose commented 2 years ago

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 commented 2 years ago

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:

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 commented 2 years ago

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 commented 2 years ago

Ok, thanks for verifying.

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

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.

DieSteinhose commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

Added in v0.4.2 and available in

DieSteinhose commented 1 year ago

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 commented 1 year ago

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.