/// <summary> /// Put the tags of the Spotify song in the local songs. /// </summary> /// <param name="spotifySong">The song from Spotify.</param> /// <param name="localSong">The local song.</param> public static void mergeTags(SpotifySong spotifySong, LocalSong localSong) { //Retrieve taglib ref TagLib.File localFile = localSong.getTrack(); //Perform merge localFile.Tag.Clear(); localFile.Tag.Performers = spotifySong.getPerformers(); localFile.Tag.Album = spotifySong.getNameAlbum(); localFile.Tag.AlbumArtists = spotifySong.getArtistsAlbum(); localFile.Tag.BeatsPerMinute = 320; localFile.Tag.Comment = "Spotify Local Tagger by Adrien P."; localFile.Tag.Disc = spotifySong.getDiskNumber(); localFile.Tag.Title = spotifySong.getTitle(); localFile.Tag.Track = spotifySong.getTrackNumber(); localFile.Tag.TrackCount = spotifySong.getTrackNumber(); localFile.Tag.Year = spotifySong.getYearAlbum(); //Pic TagLib.IPicture[] pictFrames = { spotifySong.getAlbumImage() }; localFile.Tag.Pictures = pictFrames; //Save localFile.Save(); }
/// <summary> /// Compare the two songs by their elements. /// </summary> /// <param name="spotifySong">The Spotify song.</param> /// <param name="localSong">The local song.</param> /// <returns>0 if does not match, 1 if it matches, 2 if the localSong has only the valid title.</returns> private static int compareByElements(SpotifySong spotifySong, LocalSong localSong) { //We have a score and we evaluate if this is sufficiently good to merge the two songs string localMatchString = localSong.getMatchingString(); string spotifyMatchString = spotifySong.getMatchingString(); //1. Look for the artists string[] performers = spotifySong.getPerformers(); int nbOK = 0; if (localSong.getTrack().Tag.Performers != null && localSong.getTrack().Tag.Performers.Count() != 0) { foreach (string performer in performers) { spotifySong.initMatchingString(performer); spotifySong.processMatchingString(); foreach (string performerLocal in localSong.getTrack().Tag.Performers) { localSong.initMatchingString(performerLocal); localSong.processMatchingString(); if (localSong.getMatchingString().Contains(spotifySong.getMatchingString())) { nbOK++; break; } } if (nbOK > 0) { break; } } } if (localSong.getTrack().Tag.Performers == null || localSong.getTrack().Tag.Performers.Count() == 0 || nbOK == 0) { foreach (string performer in performers) { spotifySong.initMatchingString(performer); spotifySong.processMatchingString(); if (localMatchString.Contains(spotifySong.getMatchingString())) { nbOK++; break; } } } localSong.initMatchingString(localMatchString); //2. Look for the title bool hasGoodTitle = false; /*spotifySong.initMatchingString(spotifySong.getTitle()); * spotifySong.processMatchingString();*/ spotifySong.processMatchingStringWithTitle(); if (localMatchString.Contains(spotifySong.getMatchingString())) { hasGoodTitle = true; } //3. Reinit matching strings /**spotifySong.initMatchingString(); * spotifySong.processMatchingString();**/ spotifySong.initMatchingString(spotifyMatchString); localSong.initMatchingString(localMatchString); if (nbOK > 0 && hasGoodTitle) { //Console.WriteLine(spotifySong.getMatchingString() + " -- " + localSong.getMatchingString()); return(1); } if (hasGoodTitle) { return(2); } return(0); }