/
/
/
1"""Small stateless parsing helpers shared across the Plex remote control mixins."""
2
3from __future__ import annotations
4
5from typing import Any
6
7
8def plex_item_fields(item: Any) -> tuple[str | None, int | None]:
9 """
10 Return the ``(key, playQueueItemID)`` of a Plex play queue item.
11
12 Either field may be absent on a given item, in which case it is returned as None.
13
14 :param item: A plexapi play queue item.
15 """
16 return getattr(item, "key", None), getattr(item, "playQueueItemID", None)
17
18
19def plex_key_for_item(media_item: Any, provider_instance: str) -> str | None:
20 """
21 Return the Plex item_id mapped to the given provider instance, if any.
22
23 :param media_item: A Music Assistant media item (or None).
24 :param provider_instance: The Plex provider instance_id to match.
25 """
26 if not media_item:
27 return None
28 return next(
29 (
30 mapping.item_id
31 for mapping in media_item.provider_mappings
32 if mapping.provider_instance == provider_instance
33 ),
34 None,
35 )
36