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