Skip to content

Allow query parameters in LibrarySection.hubs() and add Playlist.centroid#1621

Open
ajacobson wants to merge 3 commits into
pushingkarmaorg:masterfrom
ajacobson:feat/section-hubs-kwargs
Open

Allow query parameters in LibrarySection.hubs() and add Playlist.centroid#1621
ajacobson wants to merge 3 commits into
pushingkarmaorg:masterfrom
ajacobson:feat/section-hubs-kwargs

Conversation

@ajacobson

Copy link
Copy Markdown

Description

Two small additions to support the personalized "Mixes For You" hub in music sections:

  • LibrarySection.hubs() now accepts optional query parameters (e.g. count=10 to limit items per hub, or includeMyMixes=1 to include the "Mixes For You" hub), matching the signature Library.hubs() already has. includeStations=1 remains the default via setdefault, so the request is unchanged for existing callers (including MusicSection.stations()), and it can now be overridden.

  • New Playlist.centroid property returning the centroid Artist a personalized "Mix For You" playlist is built around, or None for regular playlists. Mix playlists have no composite/thumb of their own — the nested centroid <Directory> is their only artwork source, and there was previously no public way to reach it.

  • 'centroid' is added to _DONT_RELOAD_FOR_KEYS: it is legitimately None on every regular playlist, so without the exemption, accessing it on a partial object would trigger a spurious auto-reload (which can never surface a centroid anyway — it only exists in the hub payload). The mocked test asserts zero reloads.

Since the CI bootstrap server cannot generate personalized mixes, test_Playlist_centroid replays a hubs response captured from a live PMS (attribute shapes preserved: mixes carry no ratingKey, and artwork lives only on the nested centroid <Directory>).

Tested against a live PMS: default hubs() output unchanged across section types, MusicSection.stations() unaffected, count/include flags honored on movie/show/music sections, and 9 real mixes parsing with centroid artist + thumb with no extra requests.

Motivation: music-assistant/server#3736, where the downstream Plex provider currently maintains a manual-parsing workaround for these items and the maintainers asked for an upstream fix.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the docstring for new or existing methods
  • I have added tests when applicable

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends PlexAPI’s library hub querying and adds support for parsing “Mixes For You” music mix playlists by exposing the centroid artist embedded in hubs payloads.

Changes:

  • Add **kwargs passthrough to LibrarySection.hubs() (with includeStations=1 preserved as the default) to support parameters like count and includeMyMixes.
  • Introduce Playlist.centroid to expose the centroid Artist for personalized mix playlists (or None for regular playlists).
  • Add tests and a captured hubs payload fixture to validate centroid parsing and to ensure no auto-reload occurs when centroid is absent.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_playlist.py Adds coverage for Playlist.centroid parsing from hubs payloads and verifies no unintended reload for regular/partial playlists.
tests/test_library.py Adds a regression test validating LibrarySection.hubs(count=...) limits hub item payload sizes.
tests/payloads.py Adds a recorded hubs XML payload representing “Mixes For You” mix + centroid directory structure.
plexapi/playlist.py Implements Playlist.centroid as a cached data property returning the centroid Artist when present.
plexapi/library.py Updates LibrarySection.hubs() to accept query kwargs while keeping prior behavior via default includeStations=1.
plexapi/base.py Adds centroid to the “don’t auto-reload when None” key set to prevent spurious reload attempts for hub-only centroid data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plexapi/library.py Outdated
@ajacobson ajacobson requested a review from JonnyWong16 July 2, 2026 17:08
ajacobson added 2 commits July 2, 2026 11:15
…roid

* LibrarySection.hubs() now accepts optional query parameters
  (e.g. count=10, includeMyMixes=1), matching Library.hubs();
  includeStations=1 remains the default and may be overridden.
* Add Playlist.centroid returning the nested centroid Artist a
  personalized 'Mix For You' playlist is built around (its only
  artwork source), guarded against auto-reload on partial objects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants