def match_transport(pl, songs): """Return a playlist with matches (search paths) for transport playlist pl in the song collection songs.""" found_songs = [None]*len(pl["playlist"]) if not ts.valid_playlist(pl): raise Exception("Invalid playlist format!") return [] if not ts.allowed_match("levenshtein", pl): raise Exception("Playlist requires unsupported match method!") return [] for song in songs: title, artist, location = song if not None in found_songs: # We've already found all songs! break for i in xrange(len(pl["playlist"])): if found_songs[i] != None: # Already found song continue pls_song = pl["playlist"][i] if levenshtein_ok(fl_title=title, fl_artist=artist, ls_artist=pls_song["artist"], ls_title=pls_song["title"]): found_songs[i] = location break return found_songs
def test_parse_reference_playlist(): from playlist import transport as ts from datetime import date REFERENCE_PLAYLIST = os.path.join(TESTDIR, "reference.json") playlist = ts.load(REFERENCE_PLAYLIST) assert ts.allowed_match("levenshtein", playlist) assert playlist['tags'][0] == "ebm" assert type(ts.updated(playlist)) == date assert ts.valid_playlist(playlist)