import pathlib
import secrets


def get_album_dir(destination: str, artist: str, album: str) -> str:
    """Returns absolute path to the album directory
    where songs will be saved.
    """

    destination_path = pathlib.Path(destination)
    destination_path.mkdir(mode=0o755, parents=True, exist_ok=True)
    album_dir_name = f'{album}_{artist}' if album else f'{artist}'

    append = ''
    while True:
        _album_dir_name = f'{album_dir_name}{append}'
        album_dir_path = destination_path / _album_dir_name

        try:
            album_dir_path.mkdir(mode=0o755, parents=False, exist_ok=False)
            return str(album_dir_path.resolve())
        except FileExistsError:
            append = f'_{secrets.token_hex(5)}'