code: def _replay_index(replay_dir):
      """Output information for a directory of replays."""
      run_config = run_configs.get()
      replay_dir = run_config.abs_replay_path(replay_dir)
      print("Checking:", replay_dir)
      replay_paths = list(run_config.replay_paths(replay_dir))
      print("Found %s replays" % len(replay_paths))
  
      if not replay_paths:
          return
  
      data = run_config.replay_data(replay_paths[0])
      ver = replay.get_replay_version(data)
      FLAGS.set_default("sc2_version", ver.game_version)
      run_config = run_configs.get()  # In case the version changed.
      print("Launching version:", run_config.version.game_version)
      with run_config.start(want_rgb=False) as controller:
          print("-" * 60)
          print(
              ",".join(
                  (
                      "filename",
                      "version",
                      "map_name",
                      "game_duration_loops",
                      "players",
                      "P1-outcome",
                      "P1-race",
                      "P1-apm",
                      "P2-race",
                      "P2-apm",
                  )
              )
          )
  
          bad_replays = []
          try:
              for file_path in replay_paths:
                  file_name = os.path.basename(file_path)
                  data = run_config.replay_data(file_path)
                  try:
                      info = controller.replay_info(data)
                  except remote_controller.RequestError as e:
                      bad_replays.append("%s: %s" % (file_name, e))
                      continue
                  if info.HasField("error"):
                      print(
                          "failed:",
                          file_name,
                          info.error,
                          info.error_details,
                      )
                      bad_replays.append(file_name)
                  else:
                      out = [
                          file_name,
                          info.game_version,
                          info.map_name,
                          info.game_duration_loops,
                          len(info.player_info),
                          sc_pb.Result.Name(
                              info.player_info[0].player_result.result
                          ),
                          sc_common.Race.Name(
                              info.player_info[
                                  0
                              ].player_info.race_actual
                          ),
                          info.player_info[0].player_apm,
                      ]
                      if len(info.player_info) >= 2:
                          out += [
                              sc_common.Race.Name(
                                  info.player_info[
                                      1
                                  ].player_info.race_actual
                              ),
                              info.player_info[1].player_apm,
                          ]
                      print(",".join(str(s) for s in out))
          except KeyboardInterrupt:
              pass
          finally:
              if bad_replays:
                  print("\n")
                  print("Replays with errors:")
                  print("\n".join(bad_replays))
  
file_path: pysc2/pysc2/bin/replay_info.py
imports: import os
  from absl import app
  from absl import flags
  from pysc2 import run_configs
  from pysc2.lib import remote_controller
  from pysc2.lib import replay
  from pysc2.lib import gfile
  from s2clientprotocol import common_pb2
  from s2clientprotocol import sc2api_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: _replay_index(replay_dir) without return types