This commit is contained in:
@@ -50,50 +50,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
public void CreateDirectory()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_songDirectory = AlbumDirectory();
|
|
||||||
|
|
||||||
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}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"An error occurred {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void CreateDirectory(Song song)
|
|
||||||
{
|
|
||||||
_song = song;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_songDirectory = AlbumDirectory();
|
|
||||||
|
|
||||||
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}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var msg = ex.Message;
|
|
||||||
_logger.Error(msg, "An error occurred");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#region C++ libs
|
#region C++ libs
|
||||||
[DllImport("libicarus.so")]
|
[DllImport("libicarus.so")]
|
||||||
public static extern void create_directory(SongManager.Sng song, string root_path, StringBuilder created_dir);
|
public static extern void create_directory(SongManager.Sng song, string root_path, StringBuilder created_dir);
|
||||||
@@ -103,104 +59,12 @@ namespace Icarus.Controllers.Managers
|
|||||||
public static extern void copy_song(string target_path, string source_path);
|
public static extern void copy_song(string target_path, string source_path);
|
||||||
[DllImport("libicarus.so")]
|
[DllImport("libicarus.so")]
|
||||||
public static extern void delete_cover_art(string cover_art_path, string stock_path);
|
public static extern void delete_cover_art(string cover_art_path, string stock_path);
|
||||||
|
[DllImport("libicarus.so")]
|
||||||
|
public static extern void delete_empty_directories(SongManager.Sng song, string root_path);
|
||||||
|
[DllImport("libicarus.so")]
|
||||||
|
public static extern void delete_song_empty_directories(SongManager.Sng song, string root_path);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public void DeleteEmptyDirectories()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var albumDirectory = AlbumDirectory();
|
|
||||||
var artistDirectory = ArtistDirectory();
|
|
||||||
if (IsDirectoryEmpty(albumDirectory))
|
|
||||||
{
|
|
||||||
Directory.Delete(albumDirectory);
|
|
||||||
Console.WriteLine($"directory {albumDirectory} deleted");
|
|
||||||
}
|
|
||||||
if (IsDirectoryEmpty(artistDirectory))
|
|
||||||
{
|
|
||||||
Directory.Delete(artistDirectory);
|
|
||||||
Console.WriteLine($"directory {artistDirectory} deleted");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var exMsg = ex.Message;
|
|
||||||
Console.WriteLine($"An error occurred {exMsg}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void DeleteEmptyDirectories(Song song)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var albumDirectory = AlbumDirectory(song);
|
|
||||||
var artistDirectory = ArtistDirectory(song);
|
|
||||||
|
|
||||||
if (IsDirectoryEmpty(albumDirectory))
|
|
||||||
{
|
|
||||||
Directory.Delete(albumDirectory);
|
|
||||||
_logger.Info("Album directory deleted");
|
|
||||||
}
|
|
||||||
if (IsDirectoryEmpty(artistDirectory))
|
|
||||||
{
|
|
||||||
Directory.Delete(artistDirectory);
|
|
||||||
_logger.Info("Artist directory deleted");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var msg = ex.Message;
|
|
||||||
_logger.Error(msg, "An error occurred");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string RetrieveAlbumPath(Song song)
|
|
||||||
{
|
|
||||||
_logger.Info("Retrieving album song path");
|
|
||||||
|
|
||||||
var albumPath = string.Empty;
|
|
||||||
albumPath = AlbumDirectory(song);
|
|
||||||
|
|
||||||
return albumPath;
|
|
||||||
}
|
|
||||||
public string RetrieveArtistPath(Song song)
|
|
||||||
{
|
|
||||||
_logger.Info("Retrieving artist path");
|
|
||||||
|
|
||||||
var artistPath = string.Empty;
|
|
||||||
artistPath = ArtistDirectory(song);
|
|
||||||
|
|
||||||
return artistPath;
|
|
||||||
}
|
|
||||||
public string GenerateSongPath(Song song)
|
|
||||||
{
|
|
||||||
_logger.Info("Generating song path");
|
|
||||||
|
|
||||||
var songPath = string.Empty;
|
|
||||||
var artistPath = ArtistDirectory(song);
|
|
||||||
var albumPath = AlbumDirectory(song);
|
|
||||||
|
|
||||||
if (!Directory.Exists(artistPath))
|
|
||||||
{
|
|
||||||
_logger.Info("Artist path does not exist");
|
|
||||||
|
|
||||||
Directory.CreateDirectory(artistPath);
|
|
||||||
|
|
||||||
_logger.Info("Creating artist path");
|
|
||||||
}
|
|
||||||
if (!Directory.Exists(albumPath))
|
|
||||||
{
|
|
||||||
_logger.Info("Album path does not exist");
|
|
||||||
|
|
||||||
Directory.CreateDirectory(albumPath);
|
|
||||||
|
|
||||||
_logger.Info("Created album path");
|
|
||||||
}
|
|
||||||
|
|
||||||
songPath = albumPath;
|
|
||||||
|
|
||||||
return songPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Initialize(DirectoryType dirTypes = DirectoryType.Music)
|
private void Initialize(DirectoryType dirTypes = DirectoryType.Music)
|
||||||
{
|
{
|
||||||
switch (dirTypes)
|
switch (dirTypes)
|
||||||
@@ -213,42 +77,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsDirectoryEmpty(string path)
|
|
||||||
{
|
|
||||||
return !Directory.EnumerateFileSystemEntries(path).Any();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string AlbumDirectory()
|
|
||||||
{
|
|
||||||
string directory = _rootSongDirectory;
|
|
||||||
directory += $@"{_song.Artist}/{_song.AlbumTitle}/";
|
|
||||||
|
|
||||||
return directory;
|
|
||||||
}
|
|
||||||
private string AlbumDirectory(Song song)
|
|
||||||
{
|
|
||||||
var directory = _rootSongDirectory;
|
|
||||||
directory += $@"{song.Artist}/{song.AlbumTitle}/";
|
|
||||||
Console.WriteLine($"Album directory {directory}");
|
|
||||||
|
|
||||||
return directory;
|
|
||||||
}
|
|
||||||
private string ArtistDirectory()
|
|
||||||
{
|
|
||||||
var directory = _rootSongDirectory;
|
|
||||||
directory += $@"{_song.Artist}/";
|
|
||||||
|
|
||||||
return directory;
|
|
||||||
}
|
|
||||||
private string ArtistDirectory(Song song)
|
|
||||||
{
|
|
||||||
var directory = _rootSongDirectory;
|
|
||||||
directory += $@"{song.Artist}/";
|
|
||||||
Console.WriteLine($"Artist directory {directory}");
|
|
||||||
|
|
||||||
return directory;
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,25 +117,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool DeleteSongFromFileSystem(Song songMetaData)
|
|
||||||
{
|
|
||||||
bool successful = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var songPath = songMetaData.SongPath;
|
|
||||||
System.IO.File.Delete(songPath);
|
|
||||||
successful = true;
|
|
||||||
DirectoryManager dirMgr = new DirectoryManager(_config, songMetaData);
|
|
||||||
dirMgr.DeleteEmptyDirectories();
|
|
||||||
Console.WriteLine("Song successfully deleted");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var exMsg = ex.Message;
|
|
||||||
}
|
|
||||||
|
|
||||||
return successful;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteSong(Song song, SongRepository songStore,
|
public void DeleteSong(Song song, SongRepository songStore,
|
||||||
AlbumRepository albumStore, ArtistRepository artistStore,
|
AlbumRepository albumStore, ArtistRepository artistStore,
|
||||||
@@ -144,12 +125,9 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (DeleteSongFromFilesystem(song))
|
DirectoryManager.delete_song_empty_directories(
|
||||||
{
|
ConvertSongToSng(song),
|
||||||
_logger.Error("Failed to delete the song");
|
_config.GetValue<string>("RootMusicPath"));
|
||||||
|
|
||||||
throw new Exception("Failed to delete the song");
|
|
||||||
}
|
|
||||||
_logger.Info("Song deleted from the filesystem");
|
_logger.Info("Song deleted from the filesystem");
|
||||||
|
|
||||||
var coverMgr = new CoverArtManager(_config.GetValue<string>(
|
var coverMgr = new CoverArtManager(_config.GetValue<string>(
|
||||||
@@ -168,78 +146,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SaveSongToFileSystem(IFormFile song)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
Console.WriteLine($"Writing song to the directory: {filePath}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var exMsg = ex.Message;
|
|
||||||
Console.WriteLine($"An error occurred: {exMsg}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository sStoreContext,
|
|
||||||
AlbumRepository alStoreContext, ArtistRepository arStoreContext)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_logger.Info("Starting process to save song to the filesystem");
|
|
||||||
var fileTempPath = Path.Combine(_tempDirectoryRoot, songFile.FileName);
|
|
||||||
var song = await SaveSongTemp(songFile, fileTempPath);
|
|
||||||
System.IO.File.Delete(fileTempPath);
|
|
||||||
|
|
||||||
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
|
||||||
dirMgr.CreateDirectory();
|
|
||||||
var filePath = dirMgr.SongDirectory;
|
|
||||||
|
|
||||||
if (!songFile.FileName.EndsWith(".mp3"))
|
|
||||||
filePath += $"{songFile.FileName}.mp3";
|
|
||||||
else
|
|
||||||
filePath += $"{songFile.FileName}";
|
|
||||||
|
|
||||||
_logger.Info($"Absolute song path: {filePath}");
|
|
||||||
|
|
||||||
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
|
||||||
{
|
|
||||||
await (songFile.CopyToAsync(fileStream));
|
|
||||||
song.SongPath = filePath;
|
|
||||||
|
|
||||||
_logger.Info("Song Successfully saved");
|
|
||||||
}
|
|
||||||
SaveSongToDatabase(song, sStoreContext, alStoreContext, arStoreContext);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var msg = ex.Message;
|
|
||||||
_logger.Error(msg, "An error occurred");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository songStore,
|
public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository songStore,
|
||||||
AlbumRepository albumStore, ArtistRepository artistStore,
|
AlbumRepository albumStore, ArtistRepository artistStore,
|
||||||
GenreRepository genreStore, YearRepository yearStore,
|
GenreRepository genreStore, YearRepository yearStore,
|
||||||
@@ -394,29 +300,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeleteEmptyDirectories(ref Song oldSong, ref Song updatedSong)
|
|
||||||
{
|
|
||||||
DirectoryManager mgr = new DirectoryManager(_config);
|
|
||||||
|
|
||||||
_logger.Info("Checking to see if there are any directories to delete");
|
|
||||||
mgr.DeleteEmptyDirectories(oldSong);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SaveSongToDatabase(Song song, SongRepository songStore, AlbumRepository albumStore,
|
|
||||||
ArtistRepository artistStore)
|
|
||||||
{
|
|
||||||
_logger.Info("Starting process to save the song to the database");
|
|
||||||
|
|
||||||
MetadataRetriever.PrintMetadata(song);
|
|
||||||
SaveAlbumToDatabase(ref song, albumStore);
|
|
||||||
MetadataRetriever.PrintMetadata(song);
|
|
||||||
SaveArtistToDatabase(ref song, artistStore);
|
|
||||||
MetadataRetriever.PrintMetadata(song);
|
|
||||||
|
|
||||||
_logger.Info($"Song;\nTitle {song.Title}\nAlbum {song.AlbumTitle}\nAlbum Id {song.AlbumId}\nArtist {song.ArtistId}");
|
|
||||||
|
|
||||||
songStore.SaveSong(song);
|
|
||||||
}
|
|
||||||
private void SaveSongToDatabase(Song song, SongRepository songStore, AlbumRepository albumStore,
|
private void SaveSongToDatabase(Song song, SongRepository songStore, AlbumRepository albumStore,
|
||||||
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)
|
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)
|
||||||
{
|
{
|
||||||
@@ -500,10 +383,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
genreStore.SaveGenre(genre);
|
genreStore.SaveGenre(genre);
|
||||||
Console.WriteLine("Going to find genre");
|
Console.WriteLine("Going to find genre");
|
||||||
genre = genreStore.GetGenre(song);
|
genre = genreStore.GetGenre(song);
|
||||||
var genreDump = $"Genre id {genre.GenreId} GenreName {genre.GenreName}" +
|
|
||||||
$" Genre song Count {genre.SongCount}";
|
|
||||||
Console.WriteLine(genreDump);
|
|
||||||
_logger.Info(genreDump);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -543,41 +422,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
song.YearId = year.YearId;
|
song.YearId = year.YearId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool DeleteSongFromFilesystem(Song song)
|
|
||||||
{
|
|
||||||
var songPath = song.SongPath;
|
|
||||||
|
|
||||||
_logger.Info("Deleting song from the filesystem");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
System.IO.File.Delete(songPath);
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
var msg = ex.Message;
|
|
||||||
_logger.Error(msg, "An error occurred when attempting to delete the song from the filesystem");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return DoesSongExistOnFilesystem(song);
|
|
||||||
}
|
|
||||||
private bool DoesSongExistOnFilesystem(Song song)
|
|
||||||
{
|
|
||||||
var songPath = song.SongPath;
|
|
||||||
|
|
||||||
if (!System.IO.File.Exists(songPath))
|
|
||||||
{
|
|
||||||
_logger.Info("Song does not exist on the filesystem");
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info("Song exists on the filesystem");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Song SongCopy(Song song)
|
public Song SongCopy(Song song)
|
||||||
{
|
{
|
||||||
var updatedSongRecord = new Song
|
var updatedSongRecord = new Song
|
||||||
@@ -814,8 +658,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
if (!string.IsNullOrEmpty(newSongRecord.Genre))
|
if (!string.IsNullOrEmpty(newSongRecord.Genre))
|
||||||
{
|
{
|
||||||
updatedSongRecord.Genre = newSongRecord.Genre;
|
updatedSongRecord.Genre = newSongRecord.Genre;
|
||||||
Console.WriteLine("Genre changed");
|
|
||||||
Console.WriteLine($"{updatedSongRecord.Genre} {newSongRecord.Genre}");
|
|
||||||
}
|
}
|
||||||
if (newSongRecord.Year != null || newSongRecord.Year > 0)
|
if (newSongRecord.Year != null || newSongRecord.Year > 0)
|
||||||
updatedSongRecord.Year = newSongRecord.Year;
|
updatedSongRecord.Year = newSongRecord.Year;
|
||||||
|
|||||||
@@ -130,7 +130,6 @@ namespace Icarus.Controllers.V1
|
|||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
var songMetaData = new Song{ Id = id };
|
var songMetaData = new Song{ Id = id };
|
||||||
Console.WriteLine($"Id {songMetaData.Id}");
|
|
||||||
songMetaData = _songRepository.GetSong(songMetaData);
|
songMetaData = _songRepository.GetSong(songMetaData);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(songMetaData.Title))
|
if (string.IsNullOrEmpty(songMetaData.Title))
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
<PackageReference Include="BCrypt.Net-Next" Version="3.1.3" />
|
<PackageReference Include="BCrypt.Net-Next" Version="3.1.3" />
|
||||||
<PackageReference Include="DotNetZip" Version="1.13.3" />
|
<PackageReference Include="DotNetZip" Version="1.13.3" />
|
||||||
<PackageReference Include="EntityFramework" Version="6.2.0" />
|
<PackageReference Include="EntityFramework" Version="6.2.0" />
|
||||||
<PackageReference Include="ID3" Version="0.6.0" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||||
@@ -24,7 +23,6 @@
|
|||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.1" />
|
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.1" />
|
||||||
<PackageReference Include="RestSharp" Version="106.6.9" />
|
<PackageReference Include="RestSharp" Version="106.6.9" />
|
||||||
<PackageReference Include="SevenZip" Version="19.0.0" />
|
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.4.0" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.4.0" />
|
||||||
<PackageReference Include="taglib" Version="2.1.0" />
|
<PackageReference Include="taglib" Version="2.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
project(icarus)
|
project(icarus CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|||||||
@@ -90,6 +90,44 @@ void delete_cover_art_file(const std::string cov_path)
|
|||||||
auto cov = fs::path(cov_path);
|
auto cov = fs::path(cov_path);
|
||||||
fs::remove(cov);
|
fs::remove(cov);
|
||||||
}
|
}
|
||||||
|
void delete_directories(Song song, const char *root_path)
|
||||||
|
{
|
||||||
|
std::cout<<"checking to for empty directories to delete"<<std::endl;
|
||||||
|
const std::string art{root_path + std::string{"/"} + song.Artist};
|
||||||
|
const std::string alb{art + "/" + song.Album};
|
||||||
|
|
||||||
|
auto alb_path = fs::path(alb);
|
||||||
|
|
||||||
|
if (!fs::exists(alb_path)) {
|
||||||
|
std::cout<<"directory does not exists"<<std::endl;
|
||||||
|
} else if (fs::is_empty(alb_path)) {
|
||||||
|
fs::remove(alb_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto art_path = fs::path(art);
|
||||||
|
|
||||||
|
if (!fs::exists(art_path)) {
|
||||||
|
std::cout<<"directory does not exists"<<std::endl;
|
||||||
|
return;
|
||||||
|
} else if (fs::is_empty(art_path)) {
|
||||||
|
fs::remove(art_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<"deleted empty directory or directories"<<std::endl;
|
||||||
|
}
|
||||||
|
void delete_song(Song song)
|
||||||
|
{
|
||||||
|
std::cout<<"deleting song"<<std::endl;
|
||||||
|
auto song_path = fs::path(song.SongPath);
|
||||||
|
|
||||||
|
if (!fs::exists(song_path)) {
|
||||||
|
std::cout<<"song does not exists"<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::remove(song_path);
|
||||||
|
std::cout<<"deleted song"<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@@ -97,6 +135,9 @@ extern "C"
|
|||||||
void create_directory(Song, const char*, char*);
|
void create_directory(Song, const char*, char*);
|
||||||
void copy_stock_cover_art(const char*, const char*);
|
void copy_stock_cover_art(const char*, const char*);
|
||||||
void copy_song(const char*, const char*);
|
void copy_song(const char*, const char*);
|
||||||
|
void delete_cover_art(const char*, const char*);
|
||||||
|
void delete_empty_directories(Song, const char*);
|
||||||
|
void delete_song_empty_directories(Song, const char*);
|
||||||
void print_song_details(const Song);
|
void print_song_details(const Song);
|
||||||
|
|
||||||
void create_directory(Song song, const char *root_path, char *dir)
|
void create_directory(Song song, const char *root_path, char *dir)
|
||||||
@@ -126,6 +167,15 @@ void delete_cover_art(const char *cover_path, const char *stock_path)
|
|||||||
std::cout<<"cover art is the stock path and will not be deleted"<<std::endl;
|
std::cout<<"cover art is the stock path and will not be deleted"<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void delete_empty_directories(Song song, const char *root_path)
|
||||||
|
{
|
||||||
|
delete_directories(song, root_path);
|
||||||
|
}
|
||||||
|
void delete_song_empty_directories(Song song, const char *root_path)
|
||||||
|
{
|
||||||
|
delete_song(song);
|
||||||
|
delete_directories(song, root_path);
|
||||||
|
}
|
||||||
void print_song_details(const Song song)
|
void print_song_details(const Song song)
|
||||||
{
|
{
|
||||||
std::cout<<"song details"<<std::endl;
|
std::cout<<"song details"<<std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user