mirror of
https://github.com/navidrome/navidrome.git
synced 2026-06-02 07:01:36 +00:00
* feat(plugins): add PlaybackReport to Scrobbler interface and all implementations * feat(plugins): add PlaybackReport worker and dispatch in PlayTracker * feat(plugins): add PlaybackReportRequest to plugin scrobbler capability * chore(plugins): regenerate PDK files with PlaybackReport * feat(plugins): add PlaybackReport to test scrobbler plugin * feat(plugins): add PlaybackReport to plugin scrobbler adapter * refactor(plugins): fix double DB fetch in StateStopped and batch getActiveScrobblers - Hoist mf from scrobble branch so PlaybackReport reuses it instead of fetching again from DB - Call getActiveScrobblers once per drain batch instead of per-entry * chore(plugins): include generated scrobbler schema with PlaybackReport * fix(plugins): skip PlaybackReport for plugins that don't export it Plugins detected as scrobblers only need to export one scrobbler function. Older plugins that don't export nd_scrobbler_playback_report would cause noisy error logs on every reportPlayback call. Now errFunctionNotFound and errNotImplemented are treated as no-ops. * refactor: rename NowPlayingInfo to PlaybackReport Signed-off-by: Deluan <deluan@navidrome.org> * refactor: rename stopNowPlayingWorker to stopBackgroundWorkers Signed-off-by: Deluan <deluan@navidrome.org> * refactor: move NowPlaying and PlaybackReport logic to separate worker files Signed-off-by: Deluan <deluan@navidrome.org> * refactor(scrobbler): rename NowPlayingInfo to PlaybackSession and add expired state Rename NowPlayingInfo struct to PlaybackSession to better reflect its role as a complete playback session representation. Add UserId field to make sessions self-contained, removing redundant userId parameters from PlaybackReport interface method and internal dispatch functions. Introduce StateExpired internal state that fires when a session cache entry expires without an explicit stop, ensuring plugins always receive a terminal event regardless of client behavior. * fix(scrobbler): update playback state description to include 'expired' Signed-off-by: Deluan <deluan@navidrome.org> * fix(scrobbler): resolve data race in OnExpiration callback Capture conf.Server.EnableNowPlaying at construction time instead of reading it from the background ttlcache eviction goroutine. The previous code raced with test config cleanup that writes to the same field concurrently. * fix(scrobbler): return error when media file lookup fails in StateStopped Simplify the MediaFile population logic in the stopped case to return an error if the track cannot be found. A stop report with an empty MediaFile is useless to plugins, and returning the error allows clients to retry or alert the user when auto-scrobble is enabled. * refactor(scrobbler): use session data directly in PlaybackReport adapter Use info.Username from PlaybackSession instead of extracting it from context in the plugin adapter, since the session is now self-contained. Add debug/trace logging for session expiration and enqueue the expired report with a user-enriched context so downstream handlers can identify the user. --------- Signed-off-by: Deluan <deluan@navidrome.org>
197 lines
8.1 KiB
YAML
197 lines
8.1 KiB
YAML
version: v1-draft
|
|
exports:
|
|
nd_scrobbler_is_authorized:
|
|
description: IsAuthorized checks if a user is authorized to scrobble to this service.
|
|
input:
|
|
$ref: '#/components/schemas/IsAuthorizedRequest'
|
|
contentType: application/json
|
|
output:
|
|
type: boolean
|
|
contentType: application/json
|
|
nd_scrobbler_now_playing:
|
|
description: NowPlaying sends a now playing notification to the scrobbling service.
|
|
input:
|
|
$ref: '#/components/schemas/NowPlayingRequest'
|
|
contentType: application/json
|
|
nd_scrobbler_scrobble:
|
|
description: Scrobble submits a completed scrobble to the scrobbling service.
|
|
input:
|
|
$ref: '#/components/schemas/ScrobbleRequest'
|
|
contentType: application/json
|
|
nd_scrobbler_playback_report:
|
|
description: PlaybackReport sends a playback state report to the scrobbling service.
|
|
input:
|
|
$ref: '#/components/schemas/PlaybackReportRequest'
|
|
contentType: application/json
|
|
components:
|
|
schemas:
|
|
ArtistRef:
|
|
description: ArtistRef is a reference to an artist with name and optional MBID.
|
|
properties:
|
|
id:
|
|
type: string
|
|
description: ID is the internal Navidrome artist ID (if known).
|
|
name:
|
|
type: string
|
|
description: Name is the artist name.
|
|
mbid:
|
|
type: string
|
|
description: MBID is the MusicBrainz ID for the artist.
|
|
required:
|
|
- name
|
|
IsAuthorizedRequest:
|
|
description: IsAuthorizedRequest is the request for authorization check.
|
|
properties:
|
|
username:
|
|
type: string
|
|
description: Username is the username of the user.
|
|
required:
|
|
- username
|
|
NowPlayingRequest:
|
|
description: NowPlayingRequest is the request for now playing notification.
|
|
properties:
|
|
username:
|
|
type: string
|
|
description: Username is the username of the user.
|
|
track:
|
|
$ref: '#/components/schemas/TrackInfo'
|
|
description: Track is the track currently playing.
|
|
position:
|
|
type: integer
|
|
format: int32
|
|
description: Position is the current playback position in seconds.
|
|
required:
|
|
- username
|
|
- track
|
|
- position
|
|
PlaybackReportRequest:
|
|
description: PlaybackReportRequest is the request for playback report notifications.
|
|
properties:
|
|
username:
|
|
type: string
|
|
description: Username is the username of the user.
|
|
track:
|
|
$ref: '#/components/schemas/TrackInfo'
|
|
description: Track is the track being played.
|
|
state:
|
|
type: string
|
|
description: State is the current playback state (starting/playing/paused/stopped/expired).
|
|
positionMs:
|
|
type: integer
|
|
format: int64
|
|
description: PositionMs is the current playback position in milliseconds.
|
|
playbackRate:
|
|
type: number
|
|
format: float
|
|
description: PlaybackRate is the playback speed (1.0 = normal).
|
|
playerId:
|
|
type: string
|
|
description: PlayerId is the unique client identifier.
|
|
playerName:
|
|
type: string
|
|
description: PlayerName is the human-readable player name.
|
|
timestamp:
|
|
type: integer
|
|
format: int64
|
|
description: Timestamp is the Unix timestamp when this report was generated.
|
|
required:
|
|
- username
|
|
- track
|
|
- state
|
|
- positionMs
|
|
- playbackRate
|
|
- playerId
|
|
- playerName
|
|
- timestamp
|
|
ScrobbleRequest:
|
|
description: ScrobbleRequest is the request for submitting a scrobble.
|
|
properties:
|
|
username:
|
|
type: string
|
|
description: Username is the username of the user.
|
|
track:
|
|
$ref: '#/components/schemas/TrackInfo'
|
|
description: Track is the track that was played.
|
|
timestamp:
|
|
type: integer
|
|
format: int64
|
|
description: Timestamp is the Unix timestamp when the track started playing.
|
|
required:
|
|
- username
|
|
- track
|
|
- timestamp
|
|
TrackInfo:
|
|
description: TrackInfo contains track metadata.
|
|
properties:
|
|
id:
|
|
type: string
|
|
description: ID is the internal Navidrome track ID.
|
|
title:
|
|
type: string
|
|
description: Title is the track title.
|
|
album:
|
|
type: string
|
|
description: Album is the album name.
|
|
artist:
|
|
type: string
|
|
description: Artist is the formatted artist name for display (e.g., "Artist1 • Artist2").
|
|
albumArtist:
|
|
type: string
|
|
description: AlbumArtist is the formatted album artist name for display.
|
|
artists:
|
|
type: array
|
|
description: Artists is the list of track artists.
|
|
items:
|
|
$ref: '#/components/schemas/ArtistRef'
|
|
albumArtists:
|
|
type: array
|
|
description: AlbumArtists is the list of album artists.
|
|
items:
|
|
$ref: '#/components/schemas/ArtistRef'
|
|
duration:
|
|
type: number
|
|
format: float
|
|
description: Duration is the track duration in seconds.
|
|
trackNumber:
|
|
type: integer
|
|
format: int32
|
|
description: TrackNumber is the track number on the album.
|
|
discNumber:
|
|
type: integer
|
|
format: int32
|
|
description: DiscNumber is the disc number.
|
|
mbzRecordingId:
|
|
type: string
|
|
description: MBZRecordingID is the MusicBrainz recording ID.
|
|
mbzAlbumId:
|
|
type: string
|
|
description: MBZAlbumID is the MusicBrainz album/release ID.
|
|
mbzReleaseGroupId:
|
|
type: string
|
|
description: MBZReleaseGroupID is the MusicBrainz release group ID.
|
|
mbzReleaseTrackId:
|
|
type: string
|
|
description: MBZReleaseTrackID is the MusicBrainz release track ID.
|
|
libraryId:
|
|
type: integer
|
|
format: int32
|
|
description: |-
|
|
LibraryID is the ID of the library the track belongs to.
|
|
Only included if the plugin has library permission with filesystem access for the track's library.
|
|
path:
|
|
type: string
|
|
description: |-
|
|
Path is the full path to the track file, relative to the library root.
|
|
Only included if the plugin has library permission with filesystem access for the track's library.
|
|
required:
|
|
- id
|
|
- title
|
|
- album
|
|
- artist
|
|
- albumArtist
|
|
- artists
|
|
- albumArtists
|
|
- duration
|
|
- trackNumber
|
|
- discNumber
|