This commit is contained in:
@@ -80,11 +80,12 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
var oldSongRecord = songStore.GetSong(song);
|
var oldSongRecord = songStore.GetSong(song);
|
||||||
song.SongPath = oldSongRecord.SongPath;
|
song.SongPath = oldSongRecord.SongPath;
|
||||||
|
var oldSng = ConvertSongToSng(oldSongRecord);
|
||||||
|
var updatedSng = ConvertSongToSng(song);
|
||||||
|
|
||||||
MetadataRetriever updateMetadata = new MetadataRetriever();
|
MetadataRetriever.update_metadata(ref updatedSng, ref oldSng);
|
||||||
updateMetadata.UpdateMetadata(song, oldSongRecord);
|
|
||||||
|
|
||||||
var updatedSong = updateMetadata.UpdatedSongRecord;
|
var updatedSong = ConvertSngToSong(updatedSng);
|
||||||
|
|
||||||
var updatedAlbum = UpdateAlbumInDatabase(oldSongRecord, updatedSong, albumStore);
|
var updatedAlbum = UpdateAlbumInDatabase(oldSongRecord, updatedSong, albumStore);
|
||||||
oldSongRecord.AlbumId = updatedAlbum.AlbumId;
|
oldSongRecord.AlbumId = updatedAlbum.AlbumId;
|
||||||
@@ -221,12 +222,16 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
return new Sng
|
return new Sng
|
||||||
{
|
{
|
||||||
Id = song.Id,
|
Id = (song.Id == 0) ? 0 : song.Id,
|
||||||
Title = song.Title,
|
Title = (string.IsNullOrEmpty(song.Title)) ? string.Empty :
|
||||||
Artist = song.Artist,
|
song.Title,
|
||||||
Album = song.AlbumTitle,
|
Artist = (string.IsNullOrEmpty(song.Artist)) ? string.Empty :
|
||||||
Genre = song.Genre,
|
song.Artist,
|
||||||
Year = song.Year.Value,
|
Album = (string.IsNullOrEmpty(song.AlbumTitle)) ? string.Empty :
|
||||||
|
song.AlbumTitle,
|
||||||
|
Genre = (string.IsNullOrEmpty(song.Genre)) ? string.Empty :
|
||||||
|
song.Genre,
|
||||||
|
Year = (song.Year == null) ? 0 : song.Year.Value,
|
||||||
Duration = song.Duration,
|
Duration = song.Duration,
|
||||||
SongPath = song.SongPath
|
SongPath = song.SongPath
|
||||||
};
|
};
|
||||||
@@ -240,7 +245,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
Artist = song.Artist,
|
Artist = song.Artist,
|
||||||
AlbumTitle = song.Album,
|
AlbumTitle = song.Album,
|
||||||
Genre = song.Genre,
|
Genre = song.Genre,
|
||||||
Year = song.Year,
|
Year = (song.Year == 0) ? 0 : song.Year,
|
||||||
Duration = song.Duration,
|
Duration = song.Duration,
|
||||||
SongPath = song.SongPath
|
SongPath = song.SongPath
|
||||||
};
|
};
|
||||||
@@ -373,7 +378,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
if (!genreStore.DoesGenreExist(song))
|
if (!genreStore.DoesGenreExist(song))
|
||||||
{
|
{
|
||||||
genreStore.SaveGenre(genre);
|
genreStore.SaveGenre(genre);
|
||||||
Console.WriteLine("Going to find genre");
|
|
||||||
genre = genreStore.GetGenre(song);
|
genre = genreStore.GetGenre(song);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -465,13 +469,13 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
_logger.Info("Creating new album record");
|
_logger.Info("Creating new album record");
|
||||||
|
|
||||||
var newAlbumRecord = new Album
|
albumStore.SaveAlbum(new Album
|
||||||
{
|
{
|
||||||
Title = newAlbumTitle,
|
Title = newAlbumTitle,
|
||||||
AlbumArtist = newAlbumArtist
|
AlbumArtist = newAlbumArtist
|
||||||
};
|
});
|
||||||
|
|
||||||
albumStore.SaveAlbum(newAlbumRecord);
|
newSongRecord.AlbumTitle = newAlbumTitle;
|
||||||
|
|
||||||
return albumStore.GetAlbum(newSongRecord, true);
|
return albumStore.GetAlbum(newSongRecord, true);
|
||||||
}
|
}
|
||||||
@@ -651,8 +655,10 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
updatedSongRecord.Genre = newSongRecord.Genre;
|
updatedSongRecord.Genre = newSongRecord.Genre;
|
||||||
}
|
}
|
||||||
if (newSongRecord.Year != null || newSongRecord.Year > 0)
|
if (newSongRecord.Year > 0)
|
||||||
updatedSongRecord.Year = newSongRecord.Year;
|
updatedSongRecord.Year = newSongRecord.Year;
|
||||||
|
else
|
||||||
|
updatedSongRecord.Year = oldSongRecord.Year;
|
||||||
|
|
||||||
_logger.Info("Applied changes to song record");
|
_logger.Info("Applied changes to song record");
|
||||||
|
|
||||||
|
|||||||
@@ -15,17 +15,11 @@ namespace Icarus.Controllers.Utilities
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private static NLog.Logger _logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
|
private static NLog.Logger _logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
|
||||||
private Song _updatedSong;
|
|
||||||
private string _message;
|
private string _message;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public Song UpdatedSongRecord
|
|
||||||
{
|
|
||||||
get => _updatedSong;
|
|
||||||
set => _updatedSong = value;
|
|
||||||
}
|
|
||||||
public string Message
|
public string Message
|
||||||
{
|
{
|
||||||
get => _message;
|
get => _message;
|
||||||
@@ -88,23 +82,6 @@ namespace Icarus.Controllers.Utilities
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateMetadata(Song updatedSong, Song oldSong)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
InitializeUpdatedSong(oldSong);
|
|
||||||
var songValues = CheckSongValues(updatedSong);
|
|
||||||
PerformUpdate(updatedSong, songValues);
|
|
||||||
Message = "Successfully updated metadata";
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var msg = ex.Message;
|
|
||||||
Console.WriteLine($"An error occurred: {msg}");
|
|
||||||
_logger.Error(msg, "An error occurred");
|
|
||||||
Message = "Failed to update metadata";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void UpdateCoverArt(Song song, CoverArt coverArt)
|
public void UpdateCoverArt(Song song, CoverArt coverArt)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Updating song's cover art");
|
Console.WriteLine("Updating song's cover art");
|
||||||
@@ -121,111 +98,6 @@ namespace Icarus.Controllers.Utilities
|
|||||||
tag.Tag.Pictures = pics;
|
tag.Tag.Pictures = pics;
|
||||||
tag.Save();
|
tag.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PerformUpdate(Song updatedSong, SortedDictionary<string, bool> checkedValues)
|
|
||||||
{
|
|
||||||
var filePath = updatedSong.SongPath;
|
|
||||||
var title = updatedSong.Title;
|
|
||||||
var artist = updatedSong.Artist;
|
|
||||||
var album = updatedSong.AlbumTitle;
|
|
||||||
var genre = updatedSong.Genre;
|
|
||||||
var year = updatedSong.Year;
|
|
||||||
TagLib.File fileTag = TagLib.File.Create(filePath);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
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())
|
|
||||||
{
|
|
||||||
case "title":
|
|
||||||
_updatedSong.Title = title;
|
|
||||||
fileTag.Tag.Title = title;
|
|
||||||
break;
|
|
||||||
case "artists":
|
|
||||||
_updatedSong.Artist = artist;
|
|
||||||
fileTag.Tag.Performers = new []{artist};
|
|
||||||
break;
|
|
||||||
case "album":
|
|
||||||
_updatedSong.AlbumTitle = album;
|
|
||||||
fileTag.Tag.Album = album;
|
|
||||||
break;
|
|
||||||
case "genre":
|
|
||||||
_updatedSong.Genre = genre;
|
|
||||||
fileTag.Tag.Genres = new []{genre};
|
|
||||||
break;
|
|
||||||
case "year":
|
|
||||||
_updatedSong.Year = year;
|
|
||||||
fileTag.Tag.Year = (uint)year;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fileTag.Save();
|
|
||||||
|
|
||||||
Console.WriteLine("Successfully updated metadata");
|
|
||||||
_logger.Info("Successfully updated metadata");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var msg = ex.Message;
|
|
||||||
Console.WriteLine($"An error occurred:\n{msg}");
|
|
||||||
_logger.Error(msg, "An error occurred");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void InitializeUpdatedSong(Song song)
|
|
||||||
{
|
|
||||||
_updatedSong = new Song
|
|
||||||
{
|
|
||||||
Id = song.Id,
|
|
||||||
Title = song.Title,
|
|
||||||
AlbumTitle = song.AlbumTitle,
|
|
||||||
Artist = song.Artist,
|
|
||||||
Genre = song.Genre,
|
|
||||||
Year = song.Year,
|
|
||||||
Duration = song.Duration,
|
|
||||||
Filename = song.Filename,
|
|
||||||
SongPath = song.SongPath
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private SortedDictionary<string, bool> CheckSongValues(Song song)
|
|
||||||
{
|
|
||||||
var songValues = new SortedDictionary<string, bool>();
|
|
||||||
Console.WriteLine("Checking for null data");
|
|
||||||
_logger.Info("Checking for null data");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
songValues["Title"] = String.IsNullOrEmpty(song.Title);
|
|
||||||
songValues["Artists"] = String.IsNullOrEmpty(song.Artist);
|
|
||||||
songValues["Album"] = String.IsNullOrEmpty(song.AlbumTitle);
|
|
||||||
songValues["Genre"] = String.IsNullOrEmpty(song.Genre);
|
|
||||||
|
|
||||||
if (song.Year == null)
|
|
||||||
songValues["Year"] = true;
|
|
||||||
else if (song.Year==0)
|
|
||||||
songValues["Year"] = true;
|
|
||||||
else
|
|
||||||
songValues["Year"] = false;
|
|
||||||
|
|
||||||
Console.WriteLine("Checking for null data completed");
|
|
||||||
_logger.Info("Checking for null data completed");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var msg = ex.Message;
|
|
||||||
Console.WriteLine($"An error occurred: \n{msg}");
|
|
||||||
_logger.Error(msg, "An error occurred");
|
|
||||||
}
|
|
||||||
|
|
||||||
return songValues;
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ namespace Icarus.Database.Repositories
|
|||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
||||||
|
Console.WriteLine($"repo alb {song.AlbumTitle}");
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
album = ParseSingleData(reader);
|
album = ParseSingleData(reader);
|
||||||
|
|||||||
Reference in New Issue
Block a user