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

Fetching metadata through mpris sometimes returns an empty array. #503

Closed
ghost opened this issue Feb 8, 2020 · 26 comments
Closed

Fetching metadata through mpris sometimes returns an empty array. #503

ghost opened this issue Feb 8, 2020 · 26 comments
Labels
advice Advice within issues that people could find helpful later on bug A functionality or parts of a program that do not work as intended

Comments

@ghost
Copy link

ghost commented Feb 8, 2020


EDIT:
If you encounter rate limit errors, please use your own Spotify client ID by setting an environment variable named SPOTIFYD_CLIENT_ID. You can create a client ID here.

~ Sven (SirWindfield)


Hi, first of all thanks for the great work.

My status bar refreshes every 5 seconds and I'm showing the currently playing music on it. So that means in every 5 seconds I'm fetching metadata data from spotifyd with this command:

dbus-send --print-reply --type=method_call
--dest=org.mpris.MediaPlayer2.spotifyd
/org/mpris/MediaPlayer2
org.freedesktop.DBus.Properties.GetAll
string:org.mpris.MediaPlayer2.Player

But sometimes that returns either an empty array or partial data like just the title or just the artist. Example return value:
.
.
dict entry(
string "Metadata"
variant array [
]
)
.
.

When I run spotifyd with --no-daemon option, it prints this for every failed fetching attempt:

Couldn't fetch metadata from spotify: Err(RateLimited(Some(8)))

And seems like the number inside Some() decreases every second and when it is 0, I can fetch the data. As I'm guessing from its name it is some kind of a limitation. Why is this happening? Is this something that set intentionally? I don't get this kind of error with the official spotify client.
If is there a way to set this limitation to 5 seconds so that it can sync to my bar, I would really appreciate it.

I'm on kernel version 5.5.2 and using the lastest pre-compiled binary.

@ghost ghost changed the title Fetching metadata through mpris sometimes returns null Fetching metadata through mpris sometimes returns an empty array. Feb 8, 2020
@mainrs
Copy link
Member

mainrs commented Feb 8, 2020

The spotify api is fetched to retrieve data related to the currently playing song. All running daemon instances share a client id, meaning that all current users probably reach the rate limit.

There might be an alternative way to get the metadata through librespot, but as far as I know, there isn't one right now.

A fix would be to introduce a config or env variable that users could use to set their own client_id for now.

@mainrs mainrs added the bug A functionality or parts of a program that do not work as intended label Feb 8, 2020
@hifiberry
Copy link

I don't think it has to do with the other bug, but I've also seen this. Didn't think there was a global client ID. In this case, the problem would be worse the more people are using spotifyd. I think, a configuration option is needed for this.

@hifiberry
Copy link

After some thinking on this, just polling the API for every MPRIS request might not be a good solution at all as it won't scale very well even with multiple client IDs.
As far as I see, librepot seems to have some kind of metadata support already:
https://github.com/librespot-org/librespot/tree/dev/metadata/src
Would it be possible to use these instead of polling the Web API?

@mainrs
Copy link
Member

mainrs commented Feb 9, 2020

I think that API is relatively new as at the time of writing that part of code librespot wasn't able to provide metadata (at least that's what I remember).

@hifiberry
Copy link

Do you think this could be used? If spotifyd becomes more popular, rate limits polling the API will become more and more a problem.

@roqueeee
Copy link

The rate limiting also occurs when trying to play a song with 'playerctl open "URI"'.

The track is never played, journalctl shows the 'Couldn't fetch metadata from spotify: Err(RateLimited(Some(n)))' error.

@Aimmig
Copy link

Aimmig commented Feb 20, 2020

I'm using spotifyd with playerctl and somehow if the metadata couldn't be fetched, playerctl changes its status to stopped which is quite confusing.

@mainrs
Copy link
Member

mainrs commented Mar 4, 2020

I think this has been fixed by #528. If anyone still encounters empty metadata when using their own client id, let me know!

The fix is only on the master branch, so you guys would have to compile it yourself.

@hifiberry
Copy link

Is a new release planned in the next time?

@mainrs
Copy link
Member

mainrs commented Mar 5, 2020

I couldn't test it long enough and hoped that some people would give it a try with their own client id before I push a new release. I didn't encounter any rate limits up until now though (after around 4 hours of play time in total).

@t4k1t
Copy link

t4k1t commented Mar 5, 2020

I had this running with my own client id for almost 8 hours today. I didn't encounter any rate limits, however there still seem to be some issues. For the most part metadata was working fine but intermittently I got some errors:

<Way Down We Go - Recorded at Spotify Studios NYC> loaded
Running "\"/home/notify-spotifyd.sh\"" using "/usr/bin/zsh" with environment variables {"PLAYER_EVENT": "change", "TRACK_ID": "3inSmIa3↷
Couldn't fetch metadata from spotify: Err(Unauthorized)
Couldn't fetch metadata from spotify: Err(Unauthorized)
Couldn't fetch metadata from spotify: Err(Unauthorized)
Couldn't fetch metadata from spotify: Err(Unauthorized)

... a few more repeats of the "Couldn't fetch metadata line ...

Couldn't fetch metadata from spotify: Err(Unauthorized)
Loading <Mr. Jones - Live At Chelsea Studios, New York/1997> with Spotify URI <spotify:track:0pjOjoHMJrerHhiXNRs3GK>
Unhandled DBus message: (Signal, Some("/org/freedesktop/DBus"), Some("org.freedesktop.DBus"), Some("NameAcquired"))
Unhandled DBus message: (Signal, Some("/org/freedesktop/DBus"), Some("org.freedesktop.DBus"), Some("NameAcquired"))
Unhandled DBus message: (Error, None, None, None)
<Mr. Jones - Live At Chelsea Studios, New York/1997> loaded

Over the course of the time I had spotifyd running I had this show up twice.
During these error blocks playerctl metadata did not return anything.

@varac
Copy link

varac commented Mar 7, 2020

I can confirm I don't get any rate limit errors anymore with latest master and own client id.

@varac
Copy link

varac commented Mar 8, 2020

Another thing I noticed is that after restarting spotifyd, querying the mpris player metatdata times out after 25s (tried with playerctl metadata as well as with dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotifyd /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata').
Only after playing the first song you can query metadata.

Should I create a dedicated issue for this ?

@theel0ja
Copy link

I think the data should be cached while the same track is playing as currently the MPRIS metadata interface is buggy due to ratelimit from Spotify.

@hifiberry
Copy link

@theel0ja I agree on this. Unfortunately I have no experience in Rust and can't help with this.

@ruifm
Copy link

ruifm commented Mar 26, 2020

I'm experiencing the same issue. I can only fetch MPRIS metadata using playerctl metadata or this polybar mpris-tail script for a extremely small time window per song.

My spotifyd log also shows the same repeated message as @tablet-mode whenever a mprys metadata request was made:

Couldn't fetch metadata from spotify: Err(RateLimited(Some(12)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(4)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(20)))

@AndydeCleyre
Copy link

Another log sample:

expand
2020-04-19 14:48:00.981077212  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:04.346346210  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:07.648137851  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:07.863635267  Loading <Saturday Sun> with Spotify URI <spotify:track:1drLQNS9D5z9lBP4DbtO2R>
2020-04-19 14:48:08.351144958  <Saturday Sun> loaded
2020-04-19 14:48:11.179967937  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:14.222461774  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:17.206551892  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:20.367032306  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:23.537730886  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:26.599503936  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:29.731113900  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:32.794865488  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:35.836217514  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:38.908796435  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:41.949998940  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:45.278958916  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:48.775928297  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:51.923958780  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:55.293513117  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:48:58.530899908  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:01.847987917  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:04.891967652  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:08.446911741  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:11.609110250  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:15.003501571  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:17.909110440  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:20.989420724  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:24.163313777  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:27.872548540  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:31.024827866  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:34.008117305  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:37.194799584  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:40.189160523  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:43.933691674  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:47.505853746  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:50.640863101  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:53.757418938  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:56.830607734  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:49:59.903060732  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:02.944090205  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:06.004403835  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:09.216391393  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:12.209174457  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:16.285495303  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:19.298163936  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:22.636325574  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:25.619189116  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:28.918316924  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:31.913478359  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:35.379527245  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:38.873003178  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:42.105541078  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:45.079425937  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:48.198911021  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:51.515567375  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:54.529884695  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:50:57.649242006  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:00.779972153  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:04.161472450  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:07.309188652  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:10.399421967  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:13.649445097  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:16.840252639  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:19.921454977  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:23.052589831  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:26.174395502  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:29.354576632  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:32.376749258  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:35.834713543  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:39.537013413  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:42.696507342  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:45.995336838  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:48.980083099  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:51.971353774  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:55.044410094  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:51:58.104568256  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:01.307261450  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:04.446758264  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:07.695429816  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:10.996238206  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:13.278133664  Loading <Swing Lo Magellan> with Spotify URI <spotify:track:2JtL0a3NHcGkFQ7kfDLKUT>
2020-04-19 14:52:13.710145417  <Swing Lo Magellan> loaded
2020-04-19 14:52:14.179988335  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:17.196625369  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:20.131950469  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:23.136477450  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:26.443582711  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:29.464833319  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:32.529167154  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:35.548996234  Couldn't fetch metadata from spotify: Err(Unauthorized)
2020-04-19 14:52:38.650750682  Couldn't fetch metadata from spotify: Err(Unauthorized)

@oscarcp
Copy link

oscarcp commented May 19, 2020

As you see I linked this issue from another place, but I have something that might be interesting to check. In my case the numbers are not random, to me they look like a request rate limit that is triggered and you have to wait N seconds to be able to query:


ec1f9b9cd85047c09580e083795167feCouldn't fetch metadata from spotify: Err(RateLimited(Some(11)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(10)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(10)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(8)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(8)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(6)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(6)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(6)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(4)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(4)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(4)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(2)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(2)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(2)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(1)))
Couldn't fetch metadata from spotify: Err(RateLimited(Some(1)))

@mtshrmn
Copy link

mtshrmn commented Jul 25, 2020

Is there any progress on this issue? I'm having the same log output as @oscarcp

@mainrs
Copy link
Member

mainrs commented Jul 25, 2020

I'm 100% sure the rate limit error is gone if you use your own client ids, if that is what you are referring to @mtshrmn

@mtshrmn
Copy link

mtshrmn commented Jul 25, 2020

I'm using my own client id though

@mtshrmn
Copy link

mtshrmn commented Jul 25, 2020

Just to be sure, the way I should set the client id is by setting the CLIENT_ID variable, right?
taken from #507

@mainrs
Copy link
Member

mainrs commented Jul 25, 2020

No, SPOTIFYD_CLIENT_ID.

I'll close this now. I am pretty sure that this has been solved. People just need to use their own IDs. If not, please create a new issue.

@mainrs mainrs added the advice Advice within issues that people could find helpful later on label Jul 25, 2020
@mainrs mainrs closed this as completed Jul 25, 2020
@evrardjp
Copy link

evrardjp commented Nov 18, 2020

@sirwindfield how do I configure the secret (I don't see a SPOTIFY_CLIENT_SECRET in code) that goes along with the SPOTIFY_CLIENT_ID? Could you explain that in the top post, please?

@robinvd
Copy link
Contributor

robinvd commented Nov 18, 2020

@evrardjp i dont think you need the secret

@busybox11
Copy link

Hey,
I'm writing a polybar module with spotifyd's MPRIS display on it.
image

I have this rate limiting problem too. Sometimes playerctl returns No player could handle this command (see screenshot below) and checking the logs of spotifyd tells that I'm rate limited.
image

Is there any workaround? I tried waiting 2 seconds between each call but it doesn't seem to work.

Here's mo polybar script:

zscroll -l 35 \
	--delay 0.15 \
	--update-check true "playerctl -p spotifyd metadata --format '{{ title }} - {{ artist }}'" &

sleep 3
wait

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
advice Advice within issues that people could find helpful later on bug A functionality or parts of a program that do not work as intended
Projects
None yet
Development

No branches or pull requests