-
Notifications
You must be signed in to change notification settings - Fork 206
Implement Last.fm scrobbling #1266
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
Implement Last.fm scrobbling #1266
Conversation
Plenty to review and fix here, I oughta have time this weekend. In the static analysis, PHPStan calls out my annotation of the return type of |
|
Thanks! I'll test this and have a closer look as soon as I have time. |
There's discussion phpstan/phpstan#4212 about this type of problems but it seems that there's no easy and clean way to handle this properly. Maybe the least bad option would be to turn part of that php-doc into ordinary comment not understood by PHPStan: |
|
Some stuff I was considering that didn't make it in (but might be considered blockers)
|
|
I tested this feature yesterday, and it seemed to work well. It was not a small task so great job! There are still some smallish details which I'd like to see improved. I'll add more comments about these once I have time to write the down, probably during the next few days. |
paulijar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it's a very good PR, and with some improvements on the commented topics, it will be excellent.
|
Thanks for the feedback! Hoping to get the fixes done this weekend |
|
😬 dipping my toe into dependency injection has really exposed my ignorance! I'll get these fixed |
|
From my point of view, this starts to be ready to be merged. Is there anything more you are planning to do before this should be merged? |
I mentioned a few ideas at the start of the code review process (#1266 (comment)), but IMO those are best kept as improvements if we find they're needed/wanted. I've been exploring libre.fm, which seems to have a handcrafted API application approval process. If that all works out of the box as a new instance of the I've got nothing else planned for the PR. The Last.fm and Admin settings wiki pages will need updating. I'd like to help with that as well, however I can. |
|
I agree that things in #1266 (comment) can be handled as separate PRs if ever. Regarding the possibility to encrypt the API secret, I don't see that this would actually improve the security in any meaningful way. The fact is that even if the secret was encrypted on the server, the key to open the encrypted secret should still be available somewhere on the server. Like the secret used to encrypt and decrypt the session key is right there in Most of the issues reported by Scrutinizer could still be addressed. The one about On the other hand, I think |
Appreciate the push. I realized there's no reason to expose the use of At this point, the curl calling functionality of Scrutinizer is now complaining about Final inspection note: Scrutinizer doesn't like my use of |
Definitely much better now. But now, if
Maybe it would help Scrutinizer if an explicit phpdoc type-hint was added
I have been struggling myself with how the type checking for URL arguments should be made in the Controller interface and I still haven't find a solution I would always be happy to apply. For one thing, often passing the arguments is mandatory for the meaningful operation of the REST endpoint. But if we mark the parameters as non-nullable, then trying to call the endpoint without proper arguments is responded with "500 Internal server error" which isn't very nice. It probably also gets logged on the server as an error. Something like "400 Bad request" would be must more correct, but to achieve that, we need to mark the parameters as nullable and then null-check manually and return the error response. That's a bit tedious if done extensively on all API endpoints, but maybe that would still be the way to go. In case of Another similar problem is the dependency injected |
|
I believe I've resolved the issues you highlighted. Marking Regarding controller parameters, maybe in the future annotations are a good option for expressing how a missing or invalid parameter can be handled by the dispatcher. Here's how Symfony does it https://symfony.com/doc/current/controller.html#automatic-mapping-of-the-request edit: OK, Scrutinizer still has an issue with the return type of |
Might be a bug in Scrutinizer and apparently this can't even be suppressed. Let's just forget it.
In my opinion, it would be cleaner to have a null-check block for this than rely on the Also the possible null In the latter case, if the code ever got executed with the null $userId (which is doubtful), the result would probably be |
Gotcha, I'll update the controller to proactively handle invalid
This might not change your recommendation, but I checked this and forgot to report back. When not logged in, all controller actions in NextCloud get routed to the login page with a |
- Store session encrypted - Enable session clearing - Better session creation result UX - Improved session creation instructions
- eliminate circular dep between TrackBusinessLayer and Scrobbler - controllers now record plays via Scrobbler interface - introduce AggregateScrobbler - rename ScrobblerService to ExternalScrobbler - register AggregateScrobbler as primary Scrobbler service
(no more php7/8 differences to account for!) Also, clarify return type of `curl_exec`
- ensure xmlString is a string - clarify return type of simplexml_load_string
- require auth, but not admin - clearSession should require a samesite cookie
- Don't use default values since that has the connotation that calling the endpoint without the argument would be valid - Still, make the parameters nullable since a null is passed by the cloud core if the REST API is called incorrectly without passing the args and we don't want the ugly unhandled error - Ensure $token is non-null when calling `generateSession`. This was still nagged on by Scrutinizer.
f37b591 to
5e89ab5
Compare
|
The inspection completed: 2 new issues, 26 updated code elements |
|
@mattwellss As you probably noticed, I rebased and merged the PR yesterday. Thanks again for your excellent work! It was a long haul. But that's nothing compared to the decade which the feature request sat on the back-log waiting for someone to pick it up ;). Btw, I did the small scrobbling-related updates to the wiki pages already on Sunday. I'm somewhat busy until Christmas but I hope I can get the Music v2.5.0 out still this year, including also this feature. |
|
Music v2.5.0 including this feature is now released. |

Resolves #339
config.phpkeys music.scrobble_api_key, music.scrobble_api_secret, music.scrobble_api_serviceScreenshots!
Settings update overview:
Authentication flow:
Screencast.From.2025-11-21.09-29-53.mp4
Not configured view: