Skip to content

Commit

Permalink
Merge pull request #219 from FoxxMD/GH-218/plexLocal
Browse files Browse the repository at this point in the history
fix(plex): Handle plex local user
  • Loading branch information
FoxxMD authored Oct 30, 2024
2 parents 489f709 + 312b6ce commit 640d2ff
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
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

0 comments on commit 640d2ff

Please sign in to comment.