Refactoring
This commit is contained in:
@@ -81,6 +81,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
var dirMgr = new DirectoryManager(_rootCoverArtPath);
|
var dirMgr = new DirectoryManager(_rootCoverArtPath);
|
||||||
dirMgr.CreateDirectory(song);
|
dirMgr.CreateDirectory(song);
|
||||||
|
// TODO: Do not use metadata for file structure
|
||||||
var imagePath = dirMgr.SongDirectory + song.Title + ".png";
|
var imagePath = dirMgr.SongDirectory + song.Title + ".png";
|
||||||
var coverArt = new CoverArt
|
var coverArt = new CoverArt
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Icarus.Types;
|
|||||||
|
|
||||||
namespace Icarus.Controllers.Managers
|
namespace Icarus.Controllers.Managers
|
||||||
{
|
{
|
||||||
|
// NOTE: Do not use metadata for the song's metadata
|
||||||
public class DirectoryManager : BaseManager
|
public class DirectoryManager : BaseManager
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
@@ -157,6 +158,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
return artistPath;
|
return artistPath;
|
||||||
}
|
}
|
||||||
|
//TODO: Change this so the song's metadata is not being used
|
||||||
public string GenerateSongPath(Song song)
|
public string GenerateSongPath(Song song)
|
||||||
{
|
{
|
||||||
_logger.Info("Generating song path");
|
_logger.Info("Generating song path");
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var oldSongRecord = _songContext.RetrieveRecord(song);
|
var oldSongRecord = _songContext.RetrieveRecord(song);
|
||||||
song.SongPath = oldSongRecord.SongPath;
|
song.Filename = oldSongRecord.Filename;
|
||||||
|
song.SongDirectory = oldSongRecord.SongDirectory;
|
||||||
|
|
||||||
MetadataRetriever updateMetadata = new MetadataRetriever();
|
MetadataRetriever updateMetadata = new MetadataRetriever();
|
||||||
updateMetadata.UpdateMetadata(song, oldSongRecord);
|
updateMetadata.UpdateMetadata(song, oldSongRecord);
|
||||||
@@ -109,7 +110,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
bool successful = false;
|
bool successful = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var songPath = songMetaData.SongPath;
|
var songPath = songMetaData.SongPath();
|
||||||
System.IO.File.Delete(songPath);
|
System.IO.File.Delete(songPath);
|
||||||
successful = true;
|
successful = true;
|
||||||
DirectoryManager dirMgr = new DirectoryManager(_config, songMetaData);
|
DirectoryManager dirMgr = new DirectoryManager(_config, songMetaData);
|
||||||
@@ -163,7 +164,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
var fileTempPath = Path.Combine(_tempDirectoryRoot, songFile.FileName);
|
var fileTempPath = Path.Combine(_tempDirectoryRoot, songFile.FileName);
|
||||||
var song = await SaveSongTemp(songFile, fileTempPath);
|
var song = await SaveSongTemp(songFile, fileTempPath);
|
||||||
song.SongPath = fileTempPath;
|
song.SongDirectory = _tempDirectoryRoot;
|
||||||
|
song.Filename = songFile.FileName;
|
||||||
|
|
||||||
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
||||||
dirMgr.CreateDirectory();
|
dirMgr.CreateDirectory();
|
||||||
@@ -184,7 +186,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
||||||
{
|
{
|
||||||
await (songFile.CopyToAsync(fileStream));
|
await (songFile.CopyToAsync(fileStream));
|
||||||
song.SongPath = filePath;
|
song.SongDirectory = dirMgr.SongDirectory;
|
||||||
|
|
||||||
|
|
||||||
_logger.Info("Song successfully saved to filesystem");
|
_logger.Info("Song successfully saved to filesystem");
|
||||||
}
|
}
|
||||||
@@ -225,7 +228,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
private async Task<SongData> RetrieveSongFromFileSystem(Song details)
|
private async Task<SongData> RetrieveSongFromFileSystem(Song details)
|
||||||
{
|
{
|
||||||
byte[] uncompressedSong = await System.IO.File.ReadAllBytesAsync(details.SongPath);
|
byte[] uncompressedSong = await System.IO.File.ReadAllBytesAsync(details.SongPath());
|
||||||
|
|
||||||
return new SongData
|
return new SongData
|
||||||
{
|
{
|
||||||
@@ -403,7 +406,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
private bool DeleteSongFromFilesystem(Song song)
|
private bool DeleteSongFromFilesystem(Song song)
|
||||||
{
|
{
|
||||||
var songPath = song.SongPath;
|
var songPath = song.SongPath();
|
||||||
|
|
||||||
_logger.Info("Deleting song from the filesystem");
|
_logger.Info("Deleting song from the filesystem");
|
||||||
|
|
||||||
@@ -422,7 +425,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
}
|
}
|
||||||
private bool DoesSongExistOnFilesystem(Song song)
|
private bool DoesSongExistOnFilesystem(Song song)
|
||||||
{
|
{
|
||||||
var songPath = song.SongPath;
|
var songPath = song.SongPath();
|
||||||
|
|
||||||
if (!System.IO.File.Exists(songPath))
|
if (!System.IO.File.Exists(songPath))
|
||||||
{
|
{
|
||||||
@@ -598,7 +601,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
Genre = oldSongRecord.Genre,
|
Genre = oldSongRecord.Genre,
|
||||||
Year = oldSongRecord.Year,
|
Year = oldSongRecord.Year,
|
||||||
Filename = oldSongRecord.Filename,
|
Filename = oldSongRecord.Filename,
|
||||||
SongPath = oldSongRecord.SongPath,
|
SongDirectory = oldSongRecord.SongDirectory,
|
||||||
ArtistID = oldSongRecord.ArtistID,
|
ArtistID = oldSongRecord.ArtistID,
|
||||||
AlbumID = oldSongRecord.AlbumID,
|
AlbumID = oldSongRecord.AlbumID,
|
||||||
GenreID = oldSongRecord.GenreID
|
GenreID = oldSongRecord.GenreID
|
||||||
@@ -644,7 +647,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
_logger.Info("Change to song's album or artist");
|
_logger.Info("Change to song's album or artist");
|
||||||
|
|
||||||
DirectoryManager dirMgr = new DirectoryManager(_config);
|
DirectoryManager dirMgr = new DirectoryManager(_config);
|
||||||
var oldSongPath = updatedSongRecord.SongPath;
|
var oldSongPath = updatedSongRecord.SongPath();
|
||||||
var newSongPath = dirMgr.GenerateSongPath(updatedSongRecord);
|
var newSongPath = dirMgr.GenerateSongPath(updatedSongRecord);
|
||||||
var filename = updatedSongRecord.Filename;
|
var filename = updatedSongRecord.Filename;
|
||||||
|
|
||||||
@@ -664,7 +667,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
Console.WriteLine("New path does not exist when it should");
|
Console.WriteLine("New path does not exist when it should");
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedSongRecord.SongPath = newSongPath + filename;
|
updatedSongRecord.SongDirectory = newSongPath;
|
||||||
|
updatedSongRecord.Filename = filename;
|
||||||
|
|
||||||
_logger.Info("Deleting old song path");
|
_logger.Info("Deleting old song path");
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
Console.WriteLine($"AlbumID: {song.AlbumID}");
|
Console.WriteLine($"AlbumID: {song.AlbumID}");
|
||||||
Console.WriteLine($"ArtistID: {song.ArtistID}");
|
Console.WriteLine($"ArtistID: {song.ArtistID}");
|
||||||
Console.WriteLine($"GenreID: {song.GenreID}");
|
Console.WriteLine($"GenreID: {song.GenreID}");
|
||||||
Console.WriteLine($"Song Path: {song.SongPath}");
|
Console.WriteLine($"Song Path: {song.SongPath()}");
|
||||||
Console.WriteLine($"Filename: {song.Filename}");
|
Console.WriteLine($"Filename: {song.Filename}");
|
||||||
Console.WriteLine("\n");
|
Console.WriteLine("\n");
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine("Fetching image");
|
Console.WriteLine("Fetching image");
|
||||||
var tag = TagLib.File.Create(song.SongPath);
|
var tag = TagLib.File.Create(song.SongPath());
|
||||||
byte[] imgBytes = tag.Tag.Pictures[0].Data.Data;
|
byte[] imgBytes = tag.Tag.Pictures[0].Data.Data;
|
||||||
|
|
||||||
return imgBytes;
|
return imgBytes;
|
||||||
@@ -125,7 +125,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Updating song metadata");
|
Console.WriteLine("Updating song metadata");
|
||||||
_logger.Info("Updating song metadata");
|
_logger.Info("Updating song metadata");
|
||||||
var filePath = song.SongPath;
|
var filePath = song.SongPath();
|
||||||
TagLib.File fileTag = TagLib.File.Create(filePath);
|
TagLib.File fileTag = TagLib.File.Create(filePath);
|
||||||
fileTag.Tag.Title = song.Title;
|
fileTag.Tag.Title = song.Title;
|
||||||
fileTag.Tag.Genres = new []{song.Genre};
|
fileTag.Tag.Genres = new []{song.Genre};
|
||||||
@@ -162,7 +162,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Updating song's cover art");
|
Console.WriteLine("Updating song's cover art");
|
||||||
|
|
||||||
var tag = TagLib.File.Create(song.SongPath);
|
var tag = TagLib.File.Create(song.SongPath());
|
||||||
var pics = tag.Tag.Pictures;
|
var pics = tag.Tag.Pictures;
|
||||||
Array.Resize(ref pics, 1);
|
Array.Resize(ref pics, 1);
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
|
|
||||||
private void PerformUpdate(Song updatedSong, SortedDictionary<string, bool> checkedValues)
|
private void PerformUpdate(Song updatedSong, SortedDictionary<string, bool> checkedValues)
|
||||||
{
|
{
|
||||||
var filePath = updatedSong.SongPath;
|
var filePath = updatedSong.SongPath();
|
||||||
var title = updatedSong.Title;
|
var title = updatedSong.Title;
|
||||||
var artist = updatedSong.Artist;
|
var artist = updatedSong.Artist;
|
||||||
var album = updatedSong.AlbumTitle;
|
var album = updatedSong.AlbumTitle;
|
||||||
@@ -244,7 +244,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
Year = song.Year,
|
Year = song.Year,
|
||||||
Duration = song.Duration,
|
Duration = song.Duration,
|
||||||
Filename = song.Filename,
|
Filename = song.Filename,
|
||||||
SongPath = song.SongPath
|
SongDirectory = song.SongDirectory
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
private void PrintMetadata()
|
private void PrintMetadata()
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace Icarus.Controllers.V1
|
|||||||
|
|
||||||
var song = context.Songs.FirstOrDefault(sng => sng.SongID == id);
|
var song = context.Songs.FirstOrDefault(sng => sng.SongID == id);
|
||||||
|
|
||||||
var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read);
|
var stream = new FileStream(song.SongPath(), FileMode.Open, FileAccess.Read);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var filename = $"{song.Title}.mp3";
|
var filename = $"{song.Title}.mp3";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user