import pathlib
from typing import Optional
from typing import List


def files_to_list(file_path: pathlib.Path, separator: Optional[str] = '|') -> List[pathlib.Path]:
    """Returns list of file path, which are listed in input file (one file path at a line).

    Args:
        file_path: Path to the input file.
        separator: Each line from the input file will be split at this separator. The first (0 index) item will
            be treated as an audio file path. If None, lines will note be split (the whole line is an audio file path)

    Returns: list of file paths

    """
    from_dir = file_path.parent
    with file_path.open() as f:
        if separator is not None:
            file_lines = [line.split('|')[0].strip() for line in f.readlines()]
        else:
            file_lines = [line.strip() for line in f.readlines()]

        file_paths = [from_dir / file_path for file_path in file_lines]

    return file_paths