def test_split_and_standardize(self): test_cases = ( ("Fall, The", "The Fall", None), ("The Fall feat. T-Pain", "The Fall", "T-Pain"), ("The Fall (Featuring T-Pain )", "The Fall", "T-Pain"), ("The Fall [WITH T-Pain]", "The Fall", "T-Pain"), (" The Fall w/ T-Pain", "The Fall", "T-Pain"), ("The Fall and T-Pain", "The Fall", "T-Pain"), ("Fall, The [& T-Pain]", "The Fall", "T-Pain"), ("The Fall feat. T-Pain & Cher", "The Fall", "T-Pain & Cher"), # If there are multiple places where we can split, we choose # the longest possible primary. ("Black, Frank & the Catholics", "Frank Black & the Catholics", None), ("Frank Black & T-Pain", "Frank Black", "T-Pain"), ("Frank Black & the Catholics feat. T-Pain", "Frank Black & the Catholics", "T-Pain"), ("Frank Black & the Catholics & T-Pain", "Frank Black & the Catholics", "T-Pain"), # The main artist has to be on our whitelist, but not the # secondary artist(s). ("Unknown Artist", None, None), ("Unknown Artist Feat. T-Pain", None, None), ("The Fall feat. Unknown Artist", "The Fall", "Unknown Artist"), ) for text, expected_head, expected_tail in test_cases: head, tail = artists.split_and_standardize(text) self.assertEqual(expected_head, head) self.assertEqual(expected_tail, tail)
def test_split_and_standardize(self): test_cases = ( ("Fall, The", "The Fall", None), ("The Fall feat. T-Pain", "The Fall", "T-Pain"), ("The Fall (Featuring T-Pain )", "The Fall", "T-Pain"), ("The Fall [WITH T-Pain]", "The Fall", "T-Pain"), (" The Fall w/ T-Pain", "The Fall", "T-Pain"), ("The Fall and T-Pain", "The Fall", "T-Pain"), ("Fall, The [& T-Pain]", "The Fall", "T-Pain"), ("The Fall feat. T-Pain & Cher", "The Fall", "T-Pain & Cher"), # If there are multiple places where we can split, we choose # the longest possible primary. ("Black, Frank & the Catholics", "Frank Black & the Catholics", None), ("Frank Black & T-Pain", "Frank Black", "T-Pain"), ("Frank Black & the Catholics feat. T-Pain", "Frank Black & the Catholics", "T-Pain"), ("Frank Black & the Catholics & T-Pain", "Frank Black & the Catholics", "T-Pain"), # The main artist has to be on our whitelist, but not the # secondary artist(s). # For these values to equal None, the artist name must not # be in the whitelist. ("Literally Unknown Artist", None, None), ("Literally Unknown Artist Feat. T-Pain", None, None), ("The Fall feat. Unknown Artist", "The Fall", "Unknown Artist"), ) for text, expected_head, expected_tail in test_cases: head, tail = artists.split_and_standardize(text) self.assertEqual(expected_head, head) self.assertEqual(expected_tail, tail)
order.verify_and_standardize(all_trck) except order.BadOrderError, ex: raise AlbumError(str(ex)) # Construct a set of all of the artist names attached to these # tracks. all_tpe1 = set( unicode(au_file.mutagen_id3["TPE1"]) for au_file in all_au_files) for au_file in all_au_files: tit2 = unicode(au_file.mutagen_id3["TIT2"]) # If artist name's don't all match, attempt to extract # guest artists and move them into the song titles. if len(all_tpe1) > 1: tpe1 = unicode(au_file.mutagen_id3["TPE1"]) new_tpe1, guest = artists.split_and_standardize(tpe1) if new_tpe1 is None: raise AlbumError("Bad TPE1: %s" % repr(tpe1)) elif tpe1 != new_tpe1: au_file.mutagen_id3["TPE1"].text = [new_tpe1] if guest is not None: guest_str = constants.TIT2_IMPORT_GUEST_FORMAT % { 'guest': guest } # We need to append the guest artist in a way that # respects any [tags] in the song title. tit2 = titles.append(tit2, guest_str) # Standardize and store the track name. std_tit2 = titles.standardize(tit2) if std_tit2 is None: raise AlbumError("Bad track name: %s" % tit2)
order.verify_and_standardize(all_trck) except order.BadOrderError, ex: raise AlbumError(str(ex)) # Construct a set of all of the artist names attached to these # tracks. all_tpe1 = set(unicode(au_file.mutagen_id3["TPE1"]) for au_file in all_au_files) for au_file in all_au_files: tit2 = unicode(au_file.mutagen_id3["TIT2"]) # If artist name's don't all match, attempt to extract # guest artists and move them into the song titles. if len(all_tpe1) > 1: tpe1 = unicode(au_file.mutagen_id3["TPE1"]) new_tpe1, guest = artists.split_and_standardize(tpe1) if new_tpe1 is None: raise AlbumError("Bad TPE1: %s" % repr(tpe1)) elif tpe1 != new_tpe1: au_file.mutagen_id3["TPE1"].text = [new_tpe1] if guest is not None: guest_str = constants.TIT2_IMPORT_GUEST_FORMAT % { 'guest': guest } # We need to append the guest artist in a way that # respects any [tags] in the song title. tit2 = titles.append(tit2, guest_str) # Standardize and store the track name. std_tit2 = titles.standardize(tit2) if std_tit2 is None: raise AlbumError("Bad track name: %s" % tit2) au_file.mutagen_id3["TIT2"].text = [std_tit2]