Skip to content

Commit

Permalink
Merge pull request #27 from westsurname/plex-request-nginx
Browse files Browse the repository at this point in the history
Attempt to fix plex_request for shard users
  • Loading branch information
westsurname authored Jul 23, 2024
2 parents a9bb42e + cfe86aa commit 8fed74d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 18 additions & 7 deletions plex_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': plex['serverApiKey']
}
requestItem(user, ratingKey, datetime.now().timestamp(), metadataHeaders, getSeason=lambda: [int(season)])

recentlyRequested.append(token)
cache.set(ratingKey, recentlyRequested)
Expand Down Expand Up @@ -181,16 +185,19 @@ def all():
season = request.args.get('season.index', '1' if mediaType == 'show' else None)

if mediaType != 'episode':

metadataHeaders = {
**plexHeaders,
'X-Plex-Token': headers.get('X-Plex-Token', request.args.get('X-Plex-Token'))
'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:
Expand Down Expand Up @@ -272,10 +279,14 @@ def children(id):

metadataHeaders = {
**plexHeaders,
'X-Plex-Token': headers.get('X-Plex-Token', request.args.get('X-Plex-Token'))
'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:
Expand Down
4 changes: 2 additions & 2 deletions shared/overseerr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8fed74d

Please sign in to comment.