import os
import sys
import json
import xxhash

def write(xxh):
  object = {}
  directory = os.getcwd()

  for root, dirs, files in os.walk(directory):
    for name in files:
      if name == os.path.basename(sys.argv[0]):
        continue

      hash = xxh()
      path = os.path.join(root, name)

      with open(path, "rb") as file:
        while True:
          data = file.read(4096)

          if not data:
            break

          hash.update(data)
          object[os.path.relpath(path, directory)] = hash.intdigest()

    with open("download_list.json", 'w') as file:
      json.dump(object, file)

if __name__ == "__main__":
  type = int(input("\n1. xxh32\n2. xxh3_64\n\n"))

  if type == 1:
    xxh = xxhash.xxh32
  elif type == 2:
    xxh = xxhash.xxh3_64

  write(xxh)
