Search by

detain / phlix-plugin-lastfm

detain

Last.fm scrobbler plugin for Phlix — scrobbles what you play to Last.fm.

Package info

github.com/detain/phlix-plugin-lastfm

Type:phlix-plugin

pkg:composer/detain/phlix-plugin-lastfm

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.2.0 2026-10-30 19:13 UTC

This package is auto-updated.

Last update: 2026-12-04 09:33:54 UTC


README

tests

Last.fm scrobbler plugin for Phlix — scrobbles what you play to Last.fm.

Overview

Connects a Phlix server to your Last.fm account:

  • Now Playing — on playback start the plugin calls Last.fm track.updateNowPlaying so your profile shows what you're listening to in real time.
  • Scrobbling — on playback stop the plugin submits a track.scrobble, enforcing Last.fm's official rule (track longer than 30 seconds and more than 50% played) measured from where playback started on this server, so resuming a half-finished track cannot credit its unplayed beginning.
  • Connects each Phlix user to Last.fm through the web auth flow served by the host: the host performs the authorize + callback handshake and persists one session key per user into lastfm_sessions; the plugin signs authenticated calls with your shared secret and consumes those stored session keys when scrobbling.

It subscribes to phlix.playback.started and phlix.playback.stopped.

Install

From the Phlix admin Plugins section, paste this repo's URL:

https://github.com/detain/phlix-plugin-lastfm

…or from the CLI:

php bin/phlix plugin:install https://github.com/detain/phlix-plugin-lastfm

Settings

Configure these in the Phlix admin Plugins → Configure dialog.

Setting Type Required Default Description
enabled bool no false Master on/off for Last.fm scrobbling. Parsed strictly: a real bool, or a canonical boolean string ('true', '1', 'on', 'yes' — case-insensitive) enables it; the canonical false strings ('false', '0', 'off', 'no', '') disable it, and any other value — junk strings such as 'banana', numbers other than 1/0, null, arrays — also stays disabled.
api_key string yes — Your Last.fm API key. Create a free API account at last.fm/api/account/create.
shared_secret string (secret) yes — The "Shared secret" shown next to your API key on your Last.fm API accounts page. Used to sign authenticated requests.

The OAuth "Connect Last.fm" handshake (authorize + callback) is served by the host at GET /api/v1/oauth/lastfm and GET /api/v1/oauth/lastfm/callback; the callback URL is derived from the request host, so no callback_url setting is needed. Per-user session keys are stored in lastfm_sessions and consumed by the scrobbler.

Where to get your credentials

  1. Sign in to Last.fm and open Create an API account.
  2. Fill in the application name/description. For the Callback URL, register the exact path the host derives at auth time — https://<your-phlix-host>/api/v1/oauth/lastfm/callback (the host sends that URL as cb= on every auth request, and Last.fm validates the request against this registered URL, so a different or query-strewn value fails the handshake).
  3. Copy the API key into api_key and the Shared secret into shared_secret.
  4. Enable the plugin and toggle enabled on.

api_key is deliberately not marked secret while shared_secret is: a Last.fm API key is a public client identifier — the web-auth flow embeds it in the browser-facing authorization URL by design — whereas the shared secret is signing material that never leaves the server and is masked in the admin UI.

Session-row lifecycle (no foreign keys, by decision)

lastfm_sessions.user_id links to the host users table without a database-enforced foreign key. That mirrors the host: its 023 and 089 migrations create the table with no FK, and the plugin's DDL is compared against that host shape by tests/Unit/LastfmMigrationsParityTest — an FK added on the plugin side alone would fork the exact schema the parity guard pins. (The estate's FK usage is selective rather than absent: identity-domain tables carry foreign keys; plugin-mirrored integration tables like this one do not.)

Row removal is therefore owned by code, not the storage engine:

  • Disconnect deletes the row on both paths — the host's LastfmSessionRepository::delete() when an admin disconnects the account, and the plugin's invalid-session self-heal when Last.fm rejects a stored key.
  • User deletion is the one path that can leave an orphan: the host deletes users with a single-table DELETE FROM users, so a session row of a deleted user may outlive it. The orphan is inert — no read ever consults lastfm_sessions without a live user_id — and sweeping such rows is a host-side cleanup duty, not something this plugin does to the host's table.

Session-key at-rest storage (plaintext — disclosed)

lastfm_sessions.session_key holds long-lived Last.fm bearer keys, and the column stores them in plaintext today: the host's live writer inserts the key from auth.getSession verbatim, and nothing on either side encrypts at rest. This is a known gap (finding phlix-lastfm-007), disclosed here rather than half-fixed from the plugin side.

Encryption is deliberately follow-the-host: the table is host-owned (host migrations 023/089 create it; this plugin's DDL mirrors it under a parity guard) and the host's live writer is the only producer of rows, so the durable fix is the host adopting an at-rest cipher — a cross-repo decision covering key custody and the cipher interface (server-internal classes cannot be depended on from a plugin). A column this plugin's read path could not decrypt would simply stop scrobbling, which is why there is no unilateral plugin encryption. The closure seam is tracked as S-lastfm-18b; when it lands, this section is replaced by the encrypted-at-rest posture. Until then: anyone with database read access can read these session keys — protect the database accordingly, and note that revoking access on the Last.fm account page invalidates a leaked key (the plugin's self-heal and the host's reconnect paths delete or replace the row).

Development

composer install
vendor/bin/phpunit
vendor/bin/phpstan analyse
php scripts/security-audit-check.php

Static analysis is configured in phpstan.neon (level 9 over src).

scripts/security-audit-check.php audits the whole of composer.lock — runtime and require-dev dependencies — via composer audit --locked, and runs in CI as the blocking composer-audit job in .github/workflows/test.yml.

The entry class is Phlix\Plugins\Scrobbler\Lastfm\LastfmPlugin (implements Phlix\Shared\Plugin\LifecycleInterface and Phlix\Shared\Plugin\ConfigurableInterface). It runs inside a Phlix server host, which provides the playback/library services at runtime. onEnable() is boot-safe — it only wires collaborators and subscribes events — so the lastfm_sessions schema is ensured lazily on the first playback event, when LastfmScrobbler invokes the deferred LastfmMigrationRunner closure. The runner also reconciles a legacy CHAR(36) user_id column to the canonical VARCHAR(36) host shape (replay-safe, fires at most once). Only per-user session keys are persisted; disabling the plugin removes nothing, and dropping the table is an uninstall-time action performed by the host's rollback through the migration's down() leg.

License

MIT — see LICENSE.