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_name(): assert sanitize_name("My/File") == "MyFile"
def test_sanitize_name_when_input_is_completely_illegal(): assert sanitize_name("***") == "BLANK"
def test_sanitize_name_when_input_is_emtpy(): assert sanitize_name("") == "BLANK"
def test_sanitize_name_when_input_is_none(): assert sanitize_name(None) == "BLANK"