code: def update_battle_net_cache(replays, bnet_base):
      """Download the battle.net cache files needed by replays."""
      test_looks_like_battle_net(bnet_base)
  
      downloaded = 0
      failed = set()
      for replay_path in replays:
          try:
              archive = mpyq.MPQArchive(replay_path)
          except ValueError:
              print("Failed to parse replay:", replay_path)
              continue
          extracted = archive.extract()
          contents = archive.header["user_data_header"]["content"]
          header = s2versions.latest().decode_replay_header(contents)
          base_build = header["m_version"]["m_baseBuild"]
          prot = s2versions.build(base_build)
  
          details_bytes = extracted.get(
              b"replay.details"
          ) or extracted.get(b"replay.details.backup")
          details = prot.decode_replay_details(details_bytes)
  
          for map_handle in details["m_cacheHandles"]:
              # server = map_handle[4:8].decode("utf-8").strip("\x00 ")
              map_hash = binascii.b2a_hex(map_handle[8:]).decode("utf8")
              file_type = map_handle[0:4].decode("utf8")
  
              cache_path = os.path.join(
                  bnet_base,
                  "Cache",
                  map_hash[0:2],
                  map_hash[2:4],
                  "%s.%s" % (map_hash, file_type),
              )
  
              url = DEPOT_URL_TEMPLATE.format(
                  hash=map_hash, type=file_type
              )
              if not os.path.exists(cache_path) and url not in failed:
                  mkdirs(os.path.dirname(cache_path))
                  print(url)
                  try:
                      urllib.request.urlretrieve(url, cache_path)
                  except urllib.error.HTTPError as e:
                      print("Download failed:", e)
                      failed.add(url)
                  else:
                      downloaded += 1
      return downloaded
  
file_path: pysc2/pysc2/bin/update_battle_net_cache.py
imports: import binascii
  import os
  import urllib
  from absl import app
  from absl import flags
  import mpyq
  from s2protocol import versions
  from pysc2 import run_configs
label_desc: Use image node_id 4 for calling a global function with example usage: update_battle_net_cache(replays, bnet_base) and returns: downloaded