def convert_size_to_bytes(size_str):
    """Convert human filesizes to bytes.
    Based on: https://stackoverflow.com/a/51253225/435093
    """
    multipliers = {
        "kilobyte": 1000,
        "megabyte": 1000 ** 2,
        "gigabyte": 1000 ** 3,
        "k": 1000,
        "kb": 1000,
        "m": 1000 ** 2,
        "mb": 1000 ** 2,
        "g": 1000 ** 3,
        "gb": 1000 ** 3,
        "kibibyte": 1024,
        "mebibyte": 1024 ** 2,
        "gibibyte": 1024 ** 3,
        "kib": 1024,
        "mib": 1024 ** 2,
        "gib": 1024 ** 3,
    }

    for suffix in multipliers:
        size_str = size_str.lower().strip().strip("s")
        if size_str.lower().endswith(suffix):
            return int(float(size_str[0 : -len(suffix)]) * multipliers[suffix])
    else:
        if size_str.endswith("b"):
            size_str = size_str[0:-1]
        elif size_str.endswith("byte"):
            size_str = size_str[0:-4]
    return int(size_str)