From ff327026a9801624568ba4e53f9ff5e3192a69fa Mon Sep 17 00:00:00 2001 From: westsurname <155189104+westsurname@users.noreply.github.com> Date: Mon, 22 Jul 2024 22:42:39 -0400 Subject: [PATCH 1/3] Attempt to fix plex_request for shard users --- plex_request.py | 15 +++++++++++---- shared/overseerr.py | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plex_request.py b/plex_request.py index d89a56c..ad8a8bc 100644 --- a/plex_request.py +++ b/plex_request.py @@ -91,7 +91,11 @@ def requestRatingKey(mediaType, mediaTypeNum, ratingKey, season=None): print(ratingKey, 'Not in recentRequests') user = getUserForPlexServerToken(token) - requestItem(user, ratingKey, datetime.now().timestamp(), headers, getSeason=lambda: [int(season)]) + metadataHeaders = { + **plexHeaders, + 'X-Plex-Token': user['authToken'] + } + requestItem(user, ratingKey, datetime.now().timestamp(), metadataHeaders, getSeason=lambda: [int(season)]) recentlyRequested.append(token) cache.set(ratingKey, recentlyRequested) @@ -181,10 +185,11 @@ def all(): season = request.args.get('season.index', '1' if mediaType == 'show' else None) if mediaType != 'episode': - + token = headers.get('X-Plex-Token', request.args.get('X-Plex-Token')) + user = getUserForPlexServerToken(token) metadataHeaders = { **plexHeaders, - 'X-Plex-Token': headers.get('X-Plex-Token', request.args.get('X-Plex-Token')) + 'X-Plex-Token': user['authToken'] } metadataAllRequest = requests.get(f"{plex['metadataHost']}library/metadata/{guid}", headers=metadataHeaders, params=request.args) @@ -270,9 +275,11 @@ def children(id): existing_seasons = {int(item['index']) for item in mediaContainer.get('Metadata', []) if item['type'] == 'season'} highest_season = max(existing_seasons) if existing_seasons else 0 + token = headers.get('X-Plex-Token', request.args.get('X-Plex-Token')) + user = getUserForPlexServerToken(token) metadataHeaders = { **plexHeaders, - 'X-Plex-Token': headers.get('X-Plex-Token', request.args.get('X-Plex-Token')) + 'X-Plex-Token': user['authToken'] } metadataChildrenRequest = requests.get(f"{plex['metadataHost']}library/metadata/{guid}/children", headers=metadataHeaders, params=request.args) diff --git a/shared/overseerr.py b/shared/overseerr.py index 106edaa..3ae2cb9 100644 --- a/shared/overseerr.py +++ b/shared/overseerr.py @@ -22,14 +22,14 @@ def getUserForPlexServerToken(serverToken): return getUserForPlexToken(token) -def requestItem(user, ratingKey, watchlistedAtTimestamp, headers, getSeason): +def requestItem(user, ratingKey, watchlistedAtTimestamp, metadataHeaders, getSeason): try: userId = user['id'] username = user['displayName'] watchlistedAt = datetime.datetime.fromtimestamp(watchlistedAtTimestamp) - metadataRequest = requests.get(f"{metadataHost}library/metadata/{ratingKey}", headers=headers) + metadataRequest = requests.get(f"{metadataHost}library/metadata/{ratingKey}", headers=metadataHeaders) metadata = next(iter(metadataRequest.json()['MediaContainer']['Metadata']), None) if not metadata: From 8b40ded04e5abef562b912667e01c53d4ddf1fcf Mon Sep 17 00:00:00 2001 From: westsurname <155189104+westsurname@users.noreply.github.com> Date: Mon, 22 Jul 2024 23:26:54 -0400 Subject: [PATCH 2/3] Attempt 2 to fix plex_request for shared users --- plex_request.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/plex_request.py b/plex_request.py index ad8a8bc..4a0bc56 100644 --- a/plex_request.py +++ b/plex_request.py @@ -93,7 +93,7 @@ def requestRatingKey(mediaType, mediaTypeNum, ratingKey, season=None): user = getUserForPlexServerToken(token) metadataHeaders = { **plexHeaders, - 'X-Plex-Token': user['authToken'] + 'X-Plex-Token': plex['serverApiKey'] } requestItem(user, ratingKey, datetime.now().timestamp(), metadataHeaders, getSeason=lambda: [int(season)]) @@ -189,13 +189,17 @@ def all(): user = getUserForPlexServerToken(token) metadataHeaders = { **plexHeaders, - 'X-Plex-Token': user['authToken'] + 'X-Plex-Token': plex['serverApiKey'] } - metadataAllRequest = requests.get(f"{plex['metadataHost']}library/metadata/{guid}", headers=metadataHeaders, params=request.args) + args = dict(request.args) + if 'X-Plex-Token' in args: + del args['X-Plex-Token'] + + metadataAllRequest = requests.get(f"{plex['metadataHost']}library/metadata/{guid}", headers=metadataHeaders, params=args) # print(f"{plex['metadataHost']}library/metadata/{guid}") # print(metadataHeaders) - # print(request.args) + # print(args) print(metadataAllRequest) # print(metadataAllRequest.text) if metadataAllRequest.status_code == 200: @@ -279,10 +283,14 @@ def children(id): user = getUserForPlexServerToken(token) metadataHeaders = { **plexHeaders, - 'X-Plex-Token': user['authToken'] + 'X-Plex-Token': plex['serverApiKey'] } - metadataChildrenRequest = requests.get(f"{plex['metadataHost']}library/metadata/{guid}/children", headers=metadataHeaders, params=request.args) + args = dict(request.args) + if 'X-Plex-Token' in args: + del args['X-Plex-Token'] + + metadataChildrenRequest = requests.get(f"{plex['metadataHost']}library/metadata/{guid}/children", headers=metadataHeaders, params=args) print(metadataChildrenRequest) # print(metadataChildrenRequest.text) if metadataChildrenRequest.status_code == 200: From 8060976d9d8d7d4fd01392f4b39b0519e6ccb633 Mon Sep 17 00:00:00 2001 From: westsurname <155189104+westsurname@users.noreply.github.com> Date: Tue, 23 Jul 2024 00:26:00 -0400 Subject: [PATCH 3/3] Cleanup --- plex_request.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plex_request.py b/plex_request.py index 4a0bc56..dc6e56b 100644 --- a/plex_request.py +++ b/plex_request.py @@ -185,8 +185,6 @@ def all(): season = request.args.get('season.index', '1' if mediaType == 'show' else None) if mediaType != 'episode': - token = headers.get('X-Plex-Token', request.args.get('X-Plex-Token')) - user = getUserForPlexServerToken(token) metadataHeaders = { **plexHeaders, 'X-Plex-Token': plex['serverApiKey'] @@ -279,8 +277,6 @@ def children(id): existing_seasons = {int(item['index']) for item in mediaContainer.get('Metadata', []) if item['type'] == 'season'} highest_season = max(existing_seasons) if existing_seasons else 0 - token = headers.get('X-Plex-Token', request.args.get('X-Plex-Token')) - user = getUserForPlexServerToken(token) metadataHeaders = { **plexHeaders, 'X-Plex-Token': plex['serverApiKey']