Skip to content

Commit c69cd8c

Browse files
committed
Enhance documentation for MetadataItem and SearchResult in Modern API
1 parent ae85a46 commit c69cd8c

2 files changed

Lines changed: 109 additions & 39 deletions

File tree

docs/metadata_agents.rst

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ All agent base classes share the following class attributes:
8989
The ``version`` attribute on an agent class controls the *agent API style*:
9090

9191
- **version 0** (legacy) — ``search()`` receives a :ref:`MediaContainer <mediacontainer>` for ``results`` and you append :ref:`MetadataSearchResult <metadatasearchresult>` objects via ``results.Append(...)``.
92-
- **version 1+** (modern) — ``search()`` receives an :ref:`ObjectContainer <objectcontainer>` for ``results``.
92+
- **version 1+** (modern) — ``search()`` receives an :ref:`ObjectContainer <objectcontainer>` for ``results`` and you append :ref:`SearchResult <searchresult>` objects via ``results.Append(...)``.
9393

9494
This is **not** the same as ``PlexFrameworkVersion`` in ``Info.plist``, which
9595
selects the framework bootstrap version (always ``"2"`` for modern plug-ins).
@@ -108,7 +108,7 @@ Called when the server needs search results for a media item.
108108
- Type
109109
- Description
110110
* - results
111-
- :ref:`ObjectContainer <objectcontainer>` or :ref:`MediaContainer <mediacontainer>`
111+
- :ref:`MediaContainer <mediacontainer>` (V0) or :ref:`ObjectContainer <objectcontainer>` (V1+)
112112
- Container to append results to.
113113
* - media
114114
- :ref:`Media.Movie <media-movie>`, :ref:`Media.TV_Show <media-tv-show>`, :ref:`Media.Artist <media-artist>`, :ref:`Media.Album <media-album>`, etc.
@@ -161,7 +161,11 @@ For version 0 agents, append :ref:`MetadataSearchResult <metadatasearchresult>`
161161
162162
results.Append(MetadataSearchResult(id='123', name='Movie Title', year=2020, score=95, lang=lang))
163163
164-
For version 1+ agents, append SearchResult objects to the :ref:`ObjectContainer <objectcontainer>`.
164+
For version 1+ agents, append :ref:`SearchResult <searchresult>` objects:
165+
166+
.. code-block:: python
167+
168+
results.Append(SearchResult(id='123', name='Movie Title', year=2020, score=95, thumb=thumb_url))
165169
166170
update(self, metadata, media, lang, force=False)
167171
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -226,44 +230,9 @@ When ``version`` is set to ``1`` or higher, ``update()`` is called at the
226230
**parent level** instead of once per individual item. This is the key practical
227231
difference from version 0.
228232

229-
**Why this matters for hierarchical media types:**
230-
231-
With version 0, for a TV show agent, ``update()`` is called once for each
232-
*episode* — the ``guid`` passed to you identifies a specific episode and the
233-
``metadata`` object represents that episode. You must make a separate network
234-
request for every episode.
235-
236-
With version 1+, when any episode (or the show itself) needs a metadata
237-
refresh, the framework calls your ``update()`` with the **TV show's** GUID
238-
instead. The ``metadata`` object represents the whole show, and you can
239-
populate ``metadata.seasons[n].episodes[m]`` for all episodes in a single
240-
call. The optional ``child_guid`` parameter tells you which specific child
241-
item triggered the update, in case you want to prioritise it.
242-
243233
For flat media types (movies, music tracks) the behaviour is the same as
244234
version 0 — there is no parent to promote to.
245235

246-
**Summary of changes the framework applies for version 1+:**
247-
248-
- **Parent GUID promotion** — When PMS supplies a parent GUID alongside the
249-
child's GUID (e.g. the show's GUID alongside an episode's GUID), the
250-
framework promotes the *parent* GUID to be the primary lookup key passed as
251-
``metadata``. The child's original GUID is forwarded as the ``child_guid``
252-
keyword argument (and its database ID as ``child_id``). As a result, ``update()``
253-
receives the parent metadata object (e.g. :ref:`TV_Show <tv-show>`,
254-
:ref:`Artist <artist>`) rather than the child object.
255-
256-
- **Parent-rooted media tree** — The :ref:`MediaTree <mediatree>` passed as
257-
the ``media`` argument is also rooted at the parent, so
258-
``media.seasons``, ``media.episodes``, ``media.tracks`` etc. reflect the
259-
full hierarchy under the parent item rather than just the single child.
260-
261-
- **Versioned model class** — The framework may resolve a different metadata
262-
model class for version 1+ agents. For example, a version 1 music artist
263-
agent receives a ``ModernArtist`` model instance that can expose richer or
264-
differently structured attributes compared to the version 0 ``LegacyArtist``.
265-
The specific class used depends on the model definition.
266-
267236
.. note::
268237

269238
``child_guid`` and ``child_id`` are only injected into ``update()`` when

docs/modern_api.rst

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The top-level container for returning content to the client.
6161
- str
6262
- Source title override.
6363

64-
Supported child types: :ref:`DirectoryObject <directoryobject>`, :ref:`NextPageObject <nextpageobject>`, :ref:`InputDirectoryObject <inputdirectoryobject>`, :ref:`PopupDirectoryObject <popupdirectoryobject>`, :ref:`PrefsObject <prefsobject>`, :ref:`SearchDirectoryObject <searchdirectoryobject>`, :ref:`PlaylistObject <playlistobject>`, :ref:`MovieObject <movieobject>`, :ref:`VideoClipObject <videoclipobject>`, :ref:`EpisodeObject <episodeobject>`, :ref:`SeasonObject <seasonobject>`, :ref:`TVShowObject <tvshowobject>`, :ref:`ArtistObject / AlbumObject / PhotoObject / PhotoAlbumObject <artistobject-albumobject>`, :ref:`TrackObject <trackobject>`, MetadataItem, SearchResult, and all :ref:`Video Extra Types <video-extra-types>`.
64+
Supported child types: :ref:`DirectoryObject <directoryobject>`, :ref:`NextPageObject <nextpageobject>`, :ref:`InputDirectoryObject <inputdirectoryobject>`, :ref:`PopupDirectoryObject <popupdirectoryobject>`, :ref:`PrefsObject <prefsobject>`, :ref:`SearchDirectoryObject <searchdirectoryobject>`, :ref:`PlaylistObject <playlistobject>`, :ref:`MovieObject <movieobject>`, :ref:`VideoClipObject <videoclipobject>`, :ref:`EpisodeObject <episodeobject>`, :ref:`SeasonObject <seasonobject>`, :ref:`TVShowObject <tvshowobject>`, :ref:`ArtistObject / AlbumObject / PhotoObject / PhotoAlbumObject <artistobject-albumobject>`, :ref:`TrackObject <trackobject>`, :ref:`MetadataItem <metadataitem>`, :ref:`SearchResult <searchresult>`, and all :ref:`Video Extra Types <video-extra-types>`.
6565

6666
add(obj)
6767
~~~~~~~~
@@ -415,6 +415,107 @@ ArtistObject / AlbumObject / PhotoObject / PhotoAlbumObject
415415

416416
Non-media containers corresponding to their model types.
417417

418+
.. _metadataitem:
419+
420+
MetadataItem
421+
------------
422+
423+
A container representing a node in a hierarchical metadata tree. Used in agent version 1+
424+
object trees returned from PMS; not typically constructed directly in plugin code.
425+
``MetadataItem`` children can be nested recursively.
426+
427+
.. list-table::
428+
:header-rows: 1
429+
:widths: 25 10 65
430+
431+
* - Attribute
432+
- Type
433+
- Description
434+
* - type
435+
- str
436+
- Media type identifier (e.g. ``"movie"``, ``"show"``, ``"season"``, ``"episode"``).
437+
* - id
438+
- str
439+
- Unique identifier of the metadata item.
440+
* - title
441+
- str
442+
- Display title.
443+
* - guid
444+
- str
445+
- Plex GUID string (e.g. ``"com.plexapp.agents.imdb://tt1234567"``).
446+
* - index
447+
- str
448+
- Positional index (season number, episode number, etc.).
449+
* - originally_available_at
450+
- str
451+
- Original air / release date (ISO 8601 string).
452+
* - score
453+
- str
454+
- Match confidence score (0–100).
455+
* - thumb
456+
- str
457+
- Thumbnail URL.
458+
* - matched
459+
- str
460+
- ``"1"`` if the item has been matched to a metadata source, ``"0"`` otherwise.
461+
462+
.. _searchresult:
463+
464+
SearchResult
465+
------------
466+
467+
Represents a single candidate returned by an agent ``search()`` in version 1+. Append
468+
``SearchResult`` objects to the :ref:`ObjectContainer <objectcontainer>` passed as
469+
``results``. ``SearchResult`` children can be nested to represent hierarchical results
470+
(e.g. episodes within a show).
471+
472+
.. list-table::
473+
:header-rows: 1
474+
:widths: 25 10 65
475+
476+
* - Attribute
477+
- Type
478+
- Description
479+
* - type
480+
- str
481+
- Media type identifier.
482+
* - id
483+
- str
484+
- Source-specific identifier used to retrieve metadata in ``update()``.
485+
* - name
486+
- str
487+
- Display name of the result.
488+
* - guid
489+
- str
490+
- Plex GUID string.
491+
* - index
492+
- str
493+
- Positional index.
494+
* - year
495+
- str
496+
- Release year.
497+
* - score
498+
- str
499+
- Match confidence score (0–100).
500+
* - thumb
501+
- str
502+
- Thumbnail URL.
503+
* - matched
504+
- str
505+
- ``"1"`` if already matched.
506+
* - parentName
507+
- str
508+
- Name of the parent item (e.g. show title for an episode result).
509+
* - parentID
510+
- str
511+
- Identifier of the parent item.
512+
* - parentGUID
513+
- str
514+
- Plex GUID of the parent item.
515+
* - parentIndex
516+
- str
517+
- Index of the parent item (e.g. season number).
518+
418519
.. _mediaobject:
419520

420521
MediaObject

0 commit comments

Comments
 (0)