Skip to content

Commit 640d2ff

Browse files
authored
Merge pull request #219 from FoxxMD/GH-218/plexLocal
fix(plex): Handle plex local user
2 parents 489f709 + 312b6ce commit 640d2ff

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

docsite/docs/configuration/configuration.mdx

+48-8
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,58 @@ If your Spotify player has [Automix](https://community.spotify.com/t5/FAQs/What-
244244
<Tabs groupId="plexType" queryString>
245245
<TabItem value="api" label="API">
246246

247-
:::tip[Important Defaults]
247+
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.
248248

249-
By default...
249+
<details>
250250

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

256-
:::
253+
**Multi-scrobbler will automatically scrobble for these users by default:**
257254

258-
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.
255+
* The User authenticated with the Plex Token
256+
* and the **Local User**
257+
258+
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).
259+
260+
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.
261+
262+
<details>
263+
264+
<summary>Examples</summary>
265+
266+
###### Defaults
267+
268+
If `usersallow` and `PLEX_USERS_ALLOW` are not defined then the Plex Token authenticated User and Local User will be scrobbled for.
269+
270+
271+
###### Only A Specific User
272+
273+
* `"usersallow": ["SomeUser"]` or
274+
* `PLEX_USERS_ALLOW: SomeUser`
275+
276+
Only the Plex user `SomeUser` will be scrobbled for. The Plex Token authenticated user and the Local User will not be scrobbled for.
277+
278+
###### A Specific User + Defaults
279+
280+
(Assuming the plex authenticated user is `FoxxMD`)
281+
282+
* `"usersallow": ["FoxxMD", "PLEX_LOCAL_USER", "SomeUser"]` or
283+
* `PLEX_USERS_ALLOW: FoxxMD,PLEX_LOCAL_USER,SomeUser`
284+
285+
The Plex user SomeUser, the Plex Token authenticated user (FoxxMD) and the Local User will be scrobbled for.
286+
287+
</details>
288+
289+
</details>
290+
291+
<details>
292+
293+
<summary>Allowed Libraries and Defaults</summary>
294+
295+
By default multi-scrobbler will only scrobble media found in Plex libraries that are labelled as **Music.**
296+
* `librariesAllow` or `PLEX_LIBRARIES_ALLOW` will override this
297+
298+
</details>
259299

260300
#### Configuration
261301

src/backend/sources/PlexApiSource.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
asPlayerStateDataMaybePlay,
77
FormatPlayObjectOptions,
88
InternalConfig,
9+
NO_USER,
910
PlayerStateData,
1011
PlayerStateDataMaybePlay,
1112
PlayPlatformId, REPORTED_PLAYER_STATUSES
@@ -31,6 +32,8 @@ import { FixedSizeList } from 'fixed-size-list';
3132

3233
const shortDeviceId = truncateStringToLength(10, '');
3334

35+
export const LOCAL_USER = 'PLEX_LOCAL_USER';
36+
3437
const THUMB_REGEX = new RegExp(/\/library\/metadata\/(?<ratingkey>\d+)\/thumb\/\d+/)
3538

3639
export default class PlexApiSource extends MemoryPositionalSource {
@@ -162,6 +165,7 @@ export default class PlexApiSource extends MemoryPositionalSource {
162165

163166
if(this.usersAllow.length === 0) {
164167
this.usersAllow.push(this.plexUser.toLocaleLowerCase());
168+
this.usersAllow.push(LOCAL_USER.toLocaleLowerCase());
165169
}
166170

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

0 commit comments

Comments
 (0)