mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 17:55:27 +00:00
[core] Move getting manifest urls into separate function
This commit is contained in:
parent
cddc58c46e
commit
dad1c7f2c2
|
@ -12,6 +12,7 @@ from datetime import datetime, timezone
|
||||||
from locale import getdefaultlocale
|
from locale import getdefaultlocale
|
||||||
from multiprocessing import Queue
|
from multiprocessing import Queue
|
||||||
from random import choice as randchoice
|
from random import choice as randchoice
|
||||||
|
from requests import Request
|
||||||
from requests.exceptions import HTTPError
|
from requests.exceptions import HTTPError
|
||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
|
|
||||||
|
@ -525,8 +526,7 @@ class LegendaryCore:
|
||||||
old_bytes = self.lgd.load_manifest(app_name, igame.version)
|
old_bytes = self.lgd.load_manifest(app_name, igame.version)
|
||||||
return old_bytes, igame.base_urls
|
return old_bytes, igame.base_urls
|
||||||
|
|
||||||
def get_cdn_manifest(self, game, platform_override=''):
|
def get_cdn_urls(self, game, platform_override=''):
|
||||||
base_urls = []
|
|
||||||
platform = 'Windows' if not platform_override else platform_override
|
platform = 'Windows' if not platform_override else platform_override
|
||||||
m_api_r = self.egs.get_game_manifest(game.asset_info.namespace,
|
m_api_r = self.egs.get_game_manifest(game.asset_info.namespace,
|
||||||
game.asset_info.catalog_item_id,
|
game.asset_info.catalog_item_id,
|
||||||
|
@ -536,26 +536,28 @@ class LegendaryCore:
|
||||||
if len(m_api_r['elements']) > 1:
|
if len(m_api_r['elements']) > 1:
|
||||||
raise ValueError('Manifest response has more than one element!')
|
raise ValueError('Manifest response has more than one element!')
|
||||||
|
|
||||||
manifest_data = None
|
base_urls = []
|
||||||
manifest_info = m_api_r['elements'][0]
|
manifest_urls = []
|
||||||
for manifest in manifest_info['manifests']:
|
for manifest in m_api_r['elements'][0]['manifests']:
|
||||||
base_url = manifest['uri'].rpartition('/')[0]
|
base_url = manifest['uri'].rpartition('/')[0]
|
||||||
if base_url not in base_urls:
|
if base_url not in base_urls:
|
||||||
base_urls.append(base_url)
|
base_urls.append(base_url)
|
||||||
if manifest_data:
|
|
||||||
continue
|
|
||||||
|
|
||||||
params = dict()
|
params = None
|
||||||
if 'queryParams' in manifest:
|
if 'queryParams' in manifest:
|
||||||
for param in manifest['queryParams']:
|
params = {p['name']: p['value'] for p in manifest['queryParams']}
|
||||||
params[param['name']] = param['value']
|
|
||||||
|
|
||||||
self.log.debug(f'Downloading manifest from {manifest["uri"]} ...')
|
# build url with a prepared request
|
||||||
r = self.egs.unauth_session.get(manifest['uri'], params=params)
|
manifest_urls.append(Request('GET', manifest['uri'], params=params).prepare().url)
|
||||||
r.raise_for_status()
|
|
||||||
manifest_data = r.content
|
|
||||||
|
|
||||||
return manifest_data, base_urls
|
return manifest_urls, base_urls
|
||||||
|
|
||||||
|
def get_cdn_manifest(self, game, platform_override=''):
|
||||||
|
manifest_urls, base_urls = self.get_cdn_urls(game, platform_override)
|
||||||
|
self.log.debug(f'Downloading manifest from {manifest_urls[0]} ...')
|
||||||
|
r = self.egs.unauth_session.get(manifest_urls[0])
|
||||||
|
r.raise_for_status()
|
||||||
|
return r.content, base_urls
|
||||||
|
|
||||||
def get_uri_manfiest(self, uri):
|
def get_uri_manfiest(self, uri):
|
||||||
if uri.startswith('http'):
|
if uri.startswith('http'):
|
||||||
|
|
Loading…
Reference in a new issue