Skip to content

Commit

Permalink
[cli/core] Fix fetching more than 1000 entitlements
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod committed Jan 1, 2024
1 parent 96e07ff commit 7fefdc4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions legendary/api/egs.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,24 @@ def get_launcher_manifests(self, platform='Windows', label=None):
r.raise_for_status()
return r.json()

def get_user_entitlements(self):
def get_user_entitlements(self, start=0):
user_id = self.user.get('account_id')
r = self.session.get(f'https://{self._entitlements_host}/entitlement/api/account/{user_id}/entitlements',
params=dict(start=0, count=5000), timeout=self.request_timeout)
params=dict(start=start, count=1000), timeout=self.request_timeout)
r.raise_for_status()
return r.json()

def get_user_entitlements_full(self):
ret = []

while True:
resp = self.get_user_entitlements(start=len(ret))
ret.extend(resp)
if len(resp) < 1000:
break

return ret

def get_game_info(self, namespace, catalog_item_id, timeout=None):
r = self.session.get(f'https://{self._catalog_host}/catalog/api/shared/namespace/{namespace}/bulk/items',
params=dict(id=catalog_item_id, includeDLCDetails=True, includeMainGameDetails=True,
Expand Down
4 changes: 2 additions & 2 deletions legendary/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ def info(self, args):
else:
logger.info('Game not installed and offline mode enabled, cannot load manifest.')
elif game:
entitlements = self.core.egs.get_user_entitlements()
entitlements = self.core.egs.get_user_entitlements_full()
egl_meta = self.core.egs.get_game_info(game.namespace, game.catalog_item_id)
game.metadata = egl_meta
# Get manifest if asset exists for current platform
Expand Down Expand Up @@ -2046,7 +2046,7 @@ def activate(self, args):
redeemed = {k['gameId'] for k in key_list if k['redeemedOnUplay']}

games = self.core.get_game_list()
entitlements = self.core.egs.get_user_entitlements()
entitlements = self.core.egs.get_user_entitlements_full()
owned_entitlements = {i['entitlementName'] for i in entitlements}

uplay_games = []
Expand Down

0 comments on commit 7fefdc4

Please sign in to comment.