from chardet.universaldetector import UniversalDetector

DEFAULT_ENCODING = "utf-8"

def guess_codec(filenames: list) -> str:
  codec_detector = UniversalDetector()
  for filename in filenames:
    codec_detector.feed(filename.encode('cp437'))
    if codec_detector.done:
      break

  result = codec_detector.close()
  encoding = result.get("encoding")
  return encoding or DEFAULT_ENCODING
  
if __name__=="__main__":
  pass