Skip to content
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

fix(plex): Handle plex local user #219

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions docsite/docs/configuration/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,58 @@ If your Spotify player has [Automix](https://community.spotify.com/t5/FAQs/What-
<Tabs groupId="plexType" queryString>
<TabItem value="api" label="API">

:::tip[Important Defaults]
Find your [**Plex Token**](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/) and make note of the **URL** and **Port** used to connect to your Plex instance.

By default...
<details>

* multi-scrobbler will **only** scrobble for the user authenticated with the Plex Token.
* Allowed Users (`usersAllow` or `PLEX_USERS_ALLOW`) are only necessary if you want to scrobble for additional users.
* multi-scrobbler will only scrobble media found in Plex libraries that are labelled as **Music.**
* `librariesAllow` or `PLEX_LIBRARIES_ALLOW` will override this
<summary>Allowed Users and Defaults</summary>

:::
**Multi-scrobbler will automatically scrobble for these users by default:**

Find your [**Plex Token**](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/) and make note of the **URL** and **Port** used to connect to your Plex instance.
* The User authenticated with the Plex Token
* and the **Local User**

The Local User (`PLEX_LOCAL_USER`) is how Plex identifies anyone directly accessing the Plex UI from a local IP (who does not need to login).

To allow MS to scrobble for other users use `usersAllow` or `PLEX_USERS_ALLOW` (env) from the below configuration docs. However, because you are overriding the default settings you must also explicitly list the authenticated user and the Local User if you want them to also be able to scrobble.

<details>

<summary>Examples</summary>

###### Defaults

If `usersallow` and `PLEX_USERS_ALLOW` are not defined then the Plex Token authenticated User and Local User will be scrobbled for.


###### Only A Specific User

* `"usersallow": ["SomeUser"]` or
* `PLEX_USERS_ALLOW: SomeUser`

Only the Plex user `SomeUser` will be scrobbled for. The Plex Token authenticated user and the Local User will not be scrobbled for.

###### A Specific User + Defaults

(Assuming the plex authenticated user is `FoxxMD`)

* `"usersallow": ["FoxxMD", "PLEX_LOCAL_USER", "SomeUser"]` or
* `PLEX_USERS_ALLOW: FoxxMD,PLEX_LOCAL_USER,SomeUser`

The Plex user SomeUser, the Plex Token authenticated user (FoxxMD) and the Local User will be scrobbled for.

</details>

</details>

<details>

<summary>Allowed Libraries and Defaults</summary>

By default multi-scrobbler will only scrobble media found in Plex libraries that are labelled as **Music.**
* `librariesAllow` or `PLEX_LIBRARIES_ALLOW` will override this

</details>

#### Configuration

Expand Down
10 changes: 8 additions & 2 deletions src/backend/sources/PlexApiSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
asPlayerStateDataMaybePlay,
FormatPlayObjectOptions,
InternalConfig,
NO_USER,
PlayerStateData,
PlayerStateDataMaybePlay,
PlayPlatformId, REPORTED_PLAYER_STATUSES
Expand All @@ -31,6 +32,8 @@ import { FixedSizeList } from 'fixed-size-list';

const shortDeviceId = truncateStringToLength(10, '');

export const LOCAL_USER = 'PLEX_LOCAL_USER';

const THUMB_REGEX = new RegExp(/\/library\/metadata\/(?<ratingkey>\d+)\/thumb\/\d+/)

export default class PlexApiSource extends MemoryPositionalSource {
Expand Down Expand Up @@ -162,6 +165,7 @@ export default class PlexApiSource extends MemoryPositionalSource {

if(this.usersAllow.length === 0) {
this.usersAllow.push(this.plexUser.toLocaleLowerCase());
this.usersAllow.push(LOCAL_USER.toLocaleLowerCase());
}

this.logger.info(`Authenticated on behalf of user ${this.plexUser} on Server ${server.object.mediaContainer.friendlyName} (version ${server.object.mediaContainer.version})`);
Expand Down Expand Up @@ -299,7 +303,7 @@ export default class PlexApiSource extends MemoryPositionalSource {
machineIdentifier
} = {},
user: {
title: userTitle
title: userTitle,
} = {}
// plex returns the track artist as originalTitle (when there is an album artist)
// otherwise this is undefined
Expand All @@ -315,7 +319,9 @@ export default class PlexApiSource extends MemoryPositionalSource {
duration: duration / 1000
},
meta: {
user: userTitle,
// If a user does not have to login to Plex (local IP and no Home Management(?)) then the User node is never populated
// in this case we will use a special constant to signal this is the local user
user: userTitle ?? LOCAL_USER,
trackId: guid,
// server: ServerId,
mediaType: type,
Expand Down
Loading