def nest_music_file(drive: Drive, file: dict, destination: Path): artist, album, title = (sanitize_name(file[name]) for name in ['artist', 'album', 'title']) filepath = (destination / artist / album / title).with_suffix( file['path'].suffix) output = sanitize_path(filepath) drive.rename(file['path'], output)
def flat_music_file(drive: Drive, file: dict, destination: Path): artist, album, title = (sanitize_name(file[name]) for name in ['artist', 'album', 'title']) name = f'{artist} - {album} - {title}' suffix = file['path'].suffix filepath = destination / (name + suffix) output = sanitize_path(filepath) drive.rename(file['path'], output)
def test_sanitize_path_when_input_is_file(): assert sanitize_path( Path("/path/to/folder/file.ext")) == Path("/path/to/folder/file.ext")
def test_sanitize_path_when_input_is_none(): with pytest.raises(ValueError): sanitize_path(None)
def test_sanitize_path_when_input_is_folder(): assert sanitize_path(Path("/path/to/folder")) == Path("/path/to/folder")