Implemented directory manager to enforce a structured music directory #13
This commit is contained in:
@@ -48,6 +48,14 @@ namespace Icarus.Controllers.Managers
|
||||
try
|
||||
{
|
||||
_songDirectory = CreateDirectoryFromSong();
|
||||
|
||||
if (!Directory.Exists(_songDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(_songDirectory);
|
||||
Console.WriteLine("The directory has been created");
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine($"The song will be saved in the following" +
|
||||
$" directory: {_songDirectory}");
|
||||
}
|
||||
@@ -65,7 +73,7 @@ namespace Icarus.Controllers.Managers
|
||||
string CreateDirectoryFromSong()
|
||||
{
|
||||
string directory = _rootSongDirectory;
|
||||
directory += $"{_song.Artist}//{_song.Album}//{_song.Title}.mp3";
|
||||
directory += $"{_song.Artist}//{_song.Album}//";
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
@@ -166,10 +166,18 @@ namespace Icarus.Controllers.Managers
|
||||
DirectoryManager dirMgr = new DirectoryManager(_config, _song);
|
||||
dirMgr.CreateDirectory();
|
||||
filePath = dirMgr.SongDirectory;
|
||||
if (!song.FileName.EndsWith(".mp3"))
|
||||
filePath += $"{song.FileName}.mp3";
|
||||
else
|
||||
filePath += $"{song.FileName}";
|
||||
|
||||
Console.WriteLine($"Full path {filePath}");
|
||||
|
||||
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
await song.CopyToAsync(fileStream);
|
||||
_song.SongPath = filePath;
|
||||
SaveSongDetails();
|
||||
|
||||
|
||||
Console.WriteLine($"Writing song to the directory: {filePath}");
|
||||
@@ -293,7 +301,6 @@ namespace Icarus.Controllers.Managers
|
||||
await song.CopyToAsync(fileStream);
|
||||
_song = RetrieveMetaData(filePath);
|
||||
_song.Filename = song.FileName;
|
||||
SaveSongDetails();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ namespace Icarus.Controllers
|
||||
Console.WriteLine($"Song Root Path {uploads}");
|
||||
foreach (var sng in songData)
|
||||
{
|
||||
byte[] data;
|
||||
if (sng.Length > 0) {
|
||||
await _songMgr.SaveSongToFileSystem(sng);
|
||||
}
|
||||
|
||||
@@ -9,5 +9,6 @@
|
||||
"ConnectionStrings": {
|
||||
"IcarusDev":"Server=; User=; Password=; Database=; Port="
|
||||
},
|
||||
"RootMusicPath":"/root/of/music/path/
|
||||
"RootMusicPath":"/root/music/path/",
|
||||
"TemporaryMusicPath":"/root/temp/music/path/"
|
||||
}
|
||||
|
||||
+2
-1
@@ -8,5 +8,6 @@
|
||||
"ConnectionStrings": {
|
||||
"IcarusProd":"Server=; User=; Password=; Database=; Port="
|
||||
},
|
||||
"RootMusicPath":"/root/of/music/path/"
|
||||
"RootMusicPath":"/root/of/music/path/",
|
||||
"TemporaryMusicPath":"/root/temp/music/path/"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user