From 991d2e0d6a8325f75153c86539e070a9547763a9 Mon Sep 17 00:00:00 2001 From: amazing-username Date: Sun, 19 May 2019 02:33:57 -0400 Subject: [PATCH] Continuing with #37 --- Controllers/Managers/SongManager.cs | 52 +++++++++++++++++----- Controllers/Utilities/MetadataRetriever.cs | 11 ++++- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/Controllers/Managers/SongManager.cs b/Controllers/Managers/SongManager.cs index 403881a..09ebb18 100644 --- a/Controllers/Managers/SongManager.cs +++ b/Controllers/Managers/SongManager.cs @@ -100,20 +100,28 @@ namespace Icarus.Controllers.Managers ArtistStoreContext artistStore, GenreStoreContext genreStore, YearStoreContext yearStore) { - var oldSongRecord = songStore.GetSong(song.Id); - song.SongPath = oldSongRecord.SongPath; + try + { + var oldSongRecord = songStore.GetSong(song); + song.SongPath = oldSongRecord.SongPath; - MetadataRetriever updateMetadata = new MetadataRetriever(); - updateMetadata.UpdateMetadata(song, oldSongRecord); + MetadataRetriever updateMetadata = new MetadataRetriever(); + updateMetadata.UpdateMetadata(song, oldSongRecord); - var updatedSong = updateMetadata.UpdatedSongRecord; + var updatedSong = updateMetadata.UpdatedSongRecord; - // TODO: Add the following methods - // UpdateAlbumInDatabase(oldSongRecord, newSongRecord, albumStore) - // UpdateArtistInDatabase(oldSongRecord, newSongRecord, artistStore - // UpdateeGenreInDatabase(oldSongRecord, newSongRecord, genreStore) - // UpdateYearInDatabase(oldSongRecord, newSongRecord, yearStore) - // UpdateSongInDatabase(oldSongRecord, newSongRecord, songStore) + // TODO: Add the following methods + UpdateAlbumInDatabase(oldSongRecord, updatedSong, albumStore); + // UpdateArtistInDatabase(oldSongRecord, newSongRecord, artistStore + // UpdateeGenreInDatabase(oldSongRecord, newSongRecord, genreStore) + // UpdateYearInDatabase(oldSongRecord, newSongRecord, yearStore) + // UpdateSongInDatabase(oldSongRecord, newSongRecord, songStore) + } + catch (Exception ex) + { + var msg = ex.Message; + _logger.Error(msg, "An error occurred"); + } return new SongResult(); } @@ -712,6 +720,28 @@ namespace Icarus.Controllers.Managers song.YearId = year.YearId; } + private void UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord, AlbumStoreContext albumStore) + { + var albumRecord = albumStore.GetAlbum(oldSongRecord); + var oldAlbumTitle = oldSongRecord.AlbumTitle; + var newAlbumTitle = newSongRecord.AlbumTitle; + + var info = string.Empty; + + Console.WriteLine($"{oldAlbumTitle}\n{newAlbumTitle}"); + + if (!oldAlbumTitle.Equals(newAlbumTitle)) + { + info = "Change to the song's album"; + _logger.Info(info); + } + else + { + info = "No change to the song's album"; + _logger.Info(info); + } + } + private async Task PopulateSongDetails() { foreach (DataRow row in _results.Rows) diff --git a/Controllers/Utilities/MetadataRetriever.cs b/Controllers/Utilities/MetadataRetriever.cs index e539d33..a6f28b4 100644 --- a/Controllers/Utilities/MetadataRetriever.cs +++ b/Controllers/Utilities/MetadataRetriever.cs @@ -128,9 +128,12 @@ namespace Icarus.Controllers.Utilities { Console.WriteLine($"Updating metadata of {title}"); _logger.Info($"Updating metadata of {title}"); + foreach (var key in checkedValues.Keys) { bool result = checkedValues[key]; + + if (!result) { switch (key.ToLower()) @@ -158,7 +161,9 @@ namespace Icarus.Controllers.Utilities } } } + fileTag.Save(); + Console.WriteLine("Successfully updated metadata"); _logger.Info("Successfully updated metadata"); } @@ -232,7 +237,11 @@ namespace Icarus.Controllers.Utilities songValues["Artists"] = String.IsNullOrEmpty(song.Artist); songValues["Album"] = String.IsNullOrEmpty(song.AlbumTitle); songValues["Genre"] = String.IsNullOrEmpty(song.Genre); - if (song.Year==0) + if (song.Year == null) + { + songValues["Year"] = true; + } + else if (song.Year==0) { songValues["Year"] = true; }