from pathlib import Path
import re
import random


def _get_files_and_labels_list(dataset_dir):
    """Get a list of filenames and labels from the dataset directory
    """
    file_list = []
    lib_names = sorted(f.name for f in Path(dataset_dir).iterdir() if re.match(r"^n[0-9]+$", f.name))
    class_id = {v: i for i, v in enumerate(lib_names)}
    for lib in Path(dataset_dir).iterdir():
        for img in lib.iterdir():
            file_list.append([str(img), class_id[lib.name]])
    random.seed(0)
    random.shuffle(file_list)
    return file_list