From 4d1013950a106517ebfea3136eefe595a99f0f9c Mon Sep 17 00:00:00 2001 From: amazing-username Date: Sun, 28 Apr 2019 23:54:13 +0000 Subject: [PATCH] Added more verbosity in the song uploading process --- Controllers/Managers/SongManager.cs | 73 +++++++++++++++++++---------- Controllers/SongDataController.cs | 1 + 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/Controllers/Managers/SongManager.cs b/Controllers/Managers/SongManager.cs index ef6eba8..7767d15 100644 --- a/Controllers/Managers/SongManager.cs +++ b/Controllers/Managers/SongManager.cs @@ -195,7 +195,9 @@ namespace Icarus.Controllers.Managers { try { + Console.WriteLine("Saving song to the filesystem"); var filePath = Path.Combine(_tempDirectoryRoot, song.FileName); + Console.WriteLine("Saving song to the filePath"); await SaveSongToFileSystemTemp(song, filePath); System.IO.File.Delete(filePath); @@ -330,41 +332,58 @@ namespace Icarus.Controllers.Managers Song RetrieveMetaData(string filePath) { + Song newSong = new Song + { + Title = "Untitled", + Artist = "Untitled", + Album = "Untitled", + Year = 0, + Genre = "Untitled", + Duration = 0, + SongPath = "" + }; string title, artist, album, genre; int year, duration; - TagLib.File tfile = TagLib.File.Create(filePath); - duration = (int)tfile.Properties.Duration.TotalSeconds; + Console.WriteLine("Stripping song metadata"); + try + { + TagLib.File tfile = TagLib.File.Create(filePath); - using (var mp3 = new Mp3(filePath)) + using (var mp3 = new Mp3(filePath)) { Id3Tag tag = mp3.GetTag(Id3TagFamily.Version2X); - title = tag.Title; - artist = tag.Artists; - album = tag.Album; - genre = "Not Implemented"; - year = (int)tag.Year; - Console.WriteLine("Title: {0}", title); - Console.WriteLine("Artist: {0}", artist); - Console.WriteLine("Album: {0}", album); - Console.WriteLine("Genre: {0}", genre); - Console.WriteLine("Year: {0}", year); - Console.WriteLine("Duration: {0}", duration); + title = tag.Title; + Console.WriteLine("Title: {0}", title); + newSong.Title = title; + artist = tag.Artists; + Console.WriteLine("Artist: {0}", artist); + newSong.Artist = artist; + album = tag.Album; + Console.WriteLine("Album: {0}", album); + newSong.Album = album; + genre = "Not Implemented"; + Console.WriteLine("Genre: {0}", genre); + newSong.Genre = genre; + year = (int)tag.Year; + Console.WriteLine("Year: {0}", year); + newSong.Year = year; + duration = (int)tfile.Properties.Duration.TotalSeconds; + Console.WriteLine("Duration: {0}", duration); + newSong.Duration = duration; } - _song = new Song - { - Title = title, - Artist = artist, - Album = album, - Year = year, - Genre = genre, - Duration = duration, - SongPath = filePath - }; + _song = newSong; + } + catch (Exception ex) + { + var msg = ex.Message; + Console.WriteLine($"An error occurred when stripping metadata\n{msg}"); + _song = newSong; + } - return _song; + return newSong; } async Task RetrieveSongFromFileSystem(Song details) @@ -382,9 +401,13 @@ namespace Icarus.Controllers.Managers { using (var fileStream = new FileStream(filePath, FileMode.Create)) { + Console.WriteLine("Retrieving song and storing it in memory"); await song.CopyToAsync(fileStream); + Console.WriteLine($"Retrieving metadata of song from filepath {filePath}"); _song = RetrieveMetaData(filePath); + Console.WriteLine("Assigning song filename"); _song.Filename = song.FileName; + Console.WriteLine($"Song filename retrieved: {song.FileName}"); } } diff --git a/Controllers/SongDataController.cs b/Controllers/SongDataController.cs index c6e3041..336a35f 100644 --- a/Controllers/SongDataController.cs +++ b/Controllers/SongDataController.cs @@ -75,6 +75,7 @@ namespace Icarus.Controllers foreach (var sng in songData) { if (sng.Length > 0) { + Console.WriteLine($"Song filename {sng.FileName}"); await _songMgr.SaveSongToFileSystem(sng); var song = _songMgr.SongDetails; context.SaveSong(song);