Added more verbosity in the song uploading process
This commit is contained in:
@@ -195,7 +195,9 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Saving song to the filesystem");
|
||||||
var filePath = Path.Combine(_tempDirectoryRoot, song.FileName);
|
var filePath = Path.Combine(_tempDirectoryRoot, song.FileName);
|
||||||
|
Console.WriteLine("Saving song to the filePath");
|
||||||
await SaveSongToFileSystemTemp(song, filePath);
|
await SaveSongToFileSystemTemp(song, filePath);
|
||||||
System.IO.File.Delete(filePath);
|
System.IO.File.Delete(filePath);
|
||||||
|
|
||||||
@@ -330,41 +332,58 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
Song RetrieveMetaData(string filePath)
|
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;
|
string title, artist, album, genre;
|
||||||
int year, duration;
|
int year, duration;
|
||||||
|
|
||||||
TagLib.File tfile = TagLib.File.Create(filePath);
|
Console.WriteLine("Stripping song metadata");
|
||||||
duration = (int)tfile.Properties.Duration.TotalSeconds;
|
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);
|
Id3Tag tag = mp3.GetTag(Id3TagFamily.Version2X);
|
||||||
title = tag.Title;
|
title = tag.Title;
|
||||||
artist = tag.Artists;
|
Console.WriteLine("Title: {0}", title);
|
||||||
album = tag.Album;
|
newSong.Title = title;
|
||||||
genre = "Not Implemented";
|
artist = tag.Artists;
|
||||||
year = (int)tag.Year;
|
Console.WriteLine("Artist: {0}", artist);
|
||||||
Console.WriteLine("Title: {0}", title);
|
newSong.Artist = artist;
|
||||||
Console.WriteLine("Artist: {0}", artist);
|
album = tag.Album;
|
||||||
Console.WriteLine("Album: {0}", album);
|
Console.WriteLine("Album: {0}", album);
|
||||||
Console.WriteLine("Genre: {0}", genre);
|
newSong.Album = album;
|
||||||
Console.WriteLine("Year: {0}", year);
|
genre = "Not Implemented";
|
||||||
Console.WriteLine("Duration: {0}", duration);
|
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
|
_song = newSong;
|
||||||
{
|
}
|
||||||
Title = title,
|
catch (Exception ex)
|
||||||
Artist = artist,
|
{
|
||||||
Album = album,
|
var msg = ex.Message;
|
||||||
Year = year,
|
Console.WriteLine($"An error occurred when stripping metadata\n{msg}");
|
||||||
Genre = genre,
|
_song = newSong;
|
||||||
Duration = duration,
|
}
|
||||||
SongPath = filePath
|
|
||||||
};
|
|
||||||
|
|
||||||
return _song;
|
return newSong;
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task<SongData> RetrieveSongFromFileSystem(Song details)
|
async Task<SongData> RetrieveSongFromFileSystem(Song details)
|
||||||
@@ -382,9 +401,13 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Retrieving song and storing it in memory");
|
||||||
await song.CopyToAsync(fileStream);
|
await song.CopyToAsync(fileStream);
|
||||||
|
Console.WriteLine($"Retrieving metadata of song from filepath {filePath}");
|
||||||
_song = RetrieveMetaData(filePath);
|
_song = RetrieveMetaData(filePath);
|
||||||
|
Console.WriteLine("Assigning song filename");
|
||||||
_song.Filename = song.FileName;
|
_song.Filename = song.FileName;
|
||||||
|
Console.WriteLine($"Song filename retrieved: {song.FileName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ namespace Icarus.Controllers
|
|||||||
foreach (var sng in songData)
|
foreach (var sng in songData)
|
||||||
{
|
{
|
||||||
if (sng.Length > 0) {
|
if (sng.Length > 0) {
|
||||||
|
Console.WriteLine($"Song filename {sng.FileName}");
|
||||||
await _songMgr.SaveSongToFileSystem(sng);
|
await _songMgr.SaveSongToFileSystem(sng);
|
||||||
var song = _songMgr.SongDetails;
|
var song = _songMgr.SongDetails;
|
||||||
context.SaveSong(song);
|
context.SaveSong(song);
|
||||||
|
|||||||
Reference in New Issue
Block a user