-
-
Notifications
You must be signed in to change notification settings - Fork 464
Plex: announce a stable client identity to plex.tv #4217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,12 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Final | ||
|
|
||
| # Identity announced to Plex / plex.tv. Without this, plexapi falls back to the host | ||
| # machine's name (e.g. in the plex.tv "authorized devices" list and during auth). | ||
| PLEX_PRODUCT: Final = "Music Assistant" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be better to just use the existing APPLICATION_NAME constant from MA constants.py? |
||
|
|
||
| CONF_ACTION_AUTH_MYPLEX = "auth_myplex" | ||
| CONF_ACTION_AUTH_LOCAL = "auth_local" | ||
| CONF_ACTION_CLEAR_AUTH = "auth" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import asyncio | ||
| from typing import TYPE_CHECKING, cast | ||
|
|
||
| import plexapi | ||
| import requests | ||
| from music_assistant_models.enums import ImageType | ||
| from music_assistant_models.media_items import MediaItemImage, UniqueList | ||
|
|
@@ -13,14 +14,35 @@ | |
| from plexapi.library import MusicSection as PlexMusicSection | ||
| from plexapi.server import PlexServer | ||
|
|
||
| from music_assistant.providers.plex.constants import AUTH_TOKEN_UNAUTH | ||
| from music_assistant.providers.plex.constants import AUTH_TOKEN_UNAUTH, PLEX_PRODUCT | ||
|
|
||
| if TYPE_CHECKING: | ||
| from plexapi.base import PlexObject | ||
|
|
||
| from music_assistant.mass import MusicAssistant | ||
|
|
||
|
|
||
| def configure_plex_identity(client_id: str) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the identity is set in plexapi's process-global state and always with |
||
| """ | ||
| Make every plexapi client announce "Music Assistant" with a stable identity. | ||
|
|
||
| plexapi builds each request's headers from these process-global defaults. The device | ||
| name otherwise falls back to the machine's hostname, and - critically - the client | ||
| identifier defaults to the MAC address, which is unstable in containers. Plex binds | ||
| OAuth tokens to the client identifier, so an unstable one makes plex.tv reject the | ||
| stored token after a restart. We pin it to Music Assistant's persistent server id. | ||
|
OzGav marked this conversation as resolved.
|
||
|
|
||
| :param client_id: Stable client identifier to advertise (Music Assistant's server id). | ||
| """ | ||
| plexapi.X_PLEX_PRODUCT = PLEX_PRODUCT | ||
| plexapi.X_PLEX_DEVICE_NAME = PLEX_PRODUCT | ||
| plexapi.BASE_HEADERS["X-Plex-Product"] = PLEX_PRODUCT | ||
| plexapi.BASE_HEADERS["X-Plex-Device-Name"] = PLEX_PRODUCT | ||
| if client_id: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this ever be false? |
||
| plexapi.X_PLEX_IDENTIFIER = client_id | ||
| plexapi.BASE_HEADERS["X-Plex-Client-Identifier"] = client_id | ||
|
|
||
|
|
||
| async def get_libraries( | ||
| mass: MusicAssistant, | ||
| auth_token: str | None, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.