MCPcopy
hub / github.com/Blizzard/s2client-proto / get_replay_pack

Function get_replay_pack

samples/replay-api/download_replays.py:81–117  ·  view source on GitHub ↗
(client_version, client_key, client_secret, replays_dir, extract=False)

Source from the content-addressed store, hash-verified

79
80
81def get_replay_pack(client_version, client_key, client_secret, replays_dir, extract=False):
82 try:
83 # Get OAuth token from us region
84 access_token = get_bnet_oauth_access_token("https://us.battle.net/oauth/token", client_key, client_secret)
85
86 # Get the base url for downloading replay packs
87 download_base_url = get_base_url(access_token)
88
89 # Get meta file infos for the give client version
90 print 'Searching replay packs with client version=' + client_version
91 meta_file_urls = search_by_client_version(access_token, client_version)
92 if len(meta_file_urls) == 0:
93 print 'No matching replay packs found for the client version!'
94 return
95
96 # For each meta file, construct full url to download replay packs
97 print 'Building urls for downloading replay packs. num_files={0}'.format(len(meta_file_urls))
98 download_urls=[]
99 for meta_file_url in meta_file_urls:
100 meta_file_info = get_meta_file_info(access_token, meta_file_url)
101 file_path = meta_file_info['path']
102 download_urls.append(urlparse.urljoin(download_base_url, file_path))
103
104 # Download replay packs.
105 files = []
106 for archive_url in sorted(download_urls):
107 print 'Downloading replay packs. url=' + archive_url
108 files.append(download_file(archive_url, replays_dir))
109
110 if extract:
111 for file in files:
112 s = '7z e {0} -o{1} -piagreetotheeula'.format(file, os.path.dirname(file))
113 subprocess.call(s)
114 os.remove(file)
115 except Exception as e:
116 import traceback
117 print 'Failed to download replay packs. traceback={}'.format(traceback.format_exc())
118
119
120def parse_args():

Callers 1

mainFunction · 0.85

Calls 5

get_base_urlFunction · 0.85
search_by_client_versionFunction · 0.85
get_meta_file_infoFunction · 0.85
download_fileFunction · 0.85

Tested by

no test coverage detected