Added functionality to save the stock cover art to a song if the song does not contain a cover art #50

This commit is contained in:
amazing-username
2019-07-14 22:40:49 -04:00
parent 59895af3b4
commit e4be56101a
7 changed files with 78 additions and 13 deletions
+28 -7
View File
@@ -103,16 +103,21 @@ namespace Icarus.Controllers.Utilities
public byte[] RetrieveCoverArtBytes(Song song)
{
Console.WriteLine("Fetching image");
var tag = TagLib.File.Create(song.SongPath);
byte[] imgBytes = tag.Tag.Pictures[0].Data.Data;
if (imgBytes == null)
try
{
Console.WriteLine("Null image");
return null;
Console.WriteLine("Fetching image");
var tag = TagLib.File.Create(song.SongPath);
byte[] imgBytes = tag.Tag.Pictures[0].Data.Data;
return imgBytes;
}
catch (Exception ex)
{
var msg = ex.Message;
_logger.Error(msg, "An error occurred in MetadataRetriever");
}
return imgBytes;
return null;
}
public void UpdateMetadata(Song song)
@@ -154,6 +159,22 @@ namespace Icarus.Controllers.Utilities
Message = "Failed to update metadata";
}
}
public void UpdateCoverArt(Song song, CoverArt coverArt)
{
Console.WriteLine("Updating song's cover art");
var tag = TagLib.File.Create(song.SongPath);
var pics = tag.Tag.Pictures;
Array.Resize(ref pics, 1);
pics[0] = new Picture(coverArt.ImagePath)
{
Description = "Cover Art"
};
tag.Tag.Pictures = pics;
tag.Save();
}
private void PerformUpdate(Song updatedSong, SortedDictionary<string, bool> checkedValues)
{