Handling song being moved on the c++ side #55
This commit is contained in:
@@ -100,6 +100,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
[DllImport("libicarus.so")]
|
[DllImport("libicarus.so")]
|
||||||
public static extern void copy_stock_cover_art(string target_path, string source_path);
|
public static extern void copy_stock_cover_art(string target_path, string source_path);
|
||||||
[DllImport("libicarus.so")]
|
[DllImport("libicarus.so")]
|
||||||
|
public static extern void copy_song(string target_path, string source_path);
|
||||||
|
[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);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -98,16 +98,12 @@ namespace Icarus.Controllers.Managers
|
|||||||
oldSongRecord.ArtistId = updatedArtist.ArtistId;
|
oldSongRecord.ArtistId = updatedArtist.ArtistId;
|
||||||
|
|
||||||
var updatedGenre = UpdateGenreInDatabase(oldSongRecord, updatedSong, genreStore);
|
var updatedGenre = UpdateGenreInDatabase(oldSongRecord, updatedSong, genreStore);
|
||||||
Console.WriteLine($"Old Genre Id {oldSongRecord.GenreId}");
|
|
||||||
oldSongRecord.GenreId = updatedGenre.GenreId;
|
oldSongRecord.GenreId = updatedGenre.GenreId;
|
||||||
Console.WriteLine($"Updated Genre Id {updatedGenre.GenreId}");
|
|
||||||
|
|
||||||
var updatedYear = UpdateYearInDatabase(oldSongRecord, updatedSong, yearStore);
|
var updatedYear = UpdateYearInDatabase(oldSongRecord, updatedSong, yearStore);
|
||||||
oldSongRecord.YearId = updatedYear.YearId;
|
oldSongRecord.YearId = updatedYear.YearId;
|
||||||
|
|
||||||
UpdateSongInDatabase(ref oldSongRecord, ref updatedSong, songStore, ref result);
|
UpdateSongInDatabase(ref oldSongRecord, ref updatedSong, songStore, ref result);
|
||||||
|
|
||||||
DeleteEmptyDirectories(ref oldSongRecord, ref updatedSong);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -329,7 +325,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
Artist = song.Artist,
|
Artist = song.Artist,
|
||||||
Album = song.AlbumTitle,
|
Album = song.AlbumTitle,
|
||||||
Genre = song.Genre,
|
Genre = song.Genre,
|
||||||
Year = song.Year.Value
|
Year = song.Year.Value,
|
||||||
|
SongPath = song.SongPath
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -581,6 +578,28 @@ namespace Icarus.Controllers.Managers
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Song SongCopy(Song song)
|
||||||
|
{
|
||||||
|
var updatedSongRecord = new Song
|
||||||
|
{
|
||||||
|
Id = song.Id,
|
||||||
|
Title = song.Title,
|
||||||
|
Artist = song.Artist,
|
||||||
|
AlbumTitle = song.AlbumTitle,
|
||||||
|
Genre = song.Genre,
|
||||||
|
Year = song.Year,
|
||||||
|
Duration = song.Duration,
|
||||||
|
Filename = song.Filename,
|
||||||
|
SongPath = song.SongPath,
|
||||||
|
ArtistId = song.ArtistId,
|
||||||
|
AlbumId = song.AlbumId,
|
||||||
|
GenreId = song.GenreId,
|
||||||
|
YearId = song.YearId
|
||||||
|
};
|
||||||
|
|
||||||
|
return updatedSongRecord;
|
||||||
|
}
|
||||||
|
|
||||||
private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord, AlbumRepository albumStore)
|
private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord, AlbumRepository albumStore)
|
||||||
{
|
{
|
||||||
var albumRecord = albumStore.GetAlbum(oldSongRecord, true);
|
var albumRecord = albumStore.GetAlbum(oldSongRecord, true);
|
||||||
@@ -769,22 +788,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
private void UpdateSongInDatabase(ref Song oldSongRecord, ref Song newSongRecord, SongRepository songStore,
|
private void UpdateSongInDatabase(ref Song oldSongRecord, ref Song newSongRecord, SongRepository songStore,
|
||||||
ref SongResult result)
|
ref SongResult result)
|
||||||
{
|
{
|
||||||
var updatedSongRecord = new Song
|
var updatedSongRecord = SongCopy(oldSongRecord);
|
||||||
{
|
|
||||||
Id = oldSongRecord.Id,
|
|
||||||
Title = oldSongRecord.Title,
|
|
||||||
Artist = oldSongRecord.Artist,
|
|
||||||
AlbumTitle = oldSongRecord.AlbumTitle,
|
|
||||||
Genre = oldSongRecord.Genre,
|
|
||||||
Year = oldSongRecord.Year,
|
|
||||||
Filename = oldSongRecord.Filename,
|
|
||||||
SongPath = oldSongRecord.SongPath,
|
|
||||||
ArtistId = oldSongRecord.ArtistId,
|
|
||||||
AlbumId = oldSongRecord.AlbumId,
|
|
||||||
GenreId = oldSongRecord.GenreId,
|
|
||||||
YearId = oldSongRecord.YearId
|
|
||||||
|
|
||||||
};
|
|
||||||
var artistOrAlbumChanged = false;
|
var artistOrAlbumChanged = false;
|
||||||
|
|
||||||
if (!SongRecordChanged(oldSongRecord, newSongRecord))
|
if (!SongRecordChanged(oldSongRecord, newSongRecord))
|
||||||
@@ -822,35 +826,20 @@ 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);
|
var rootPath = _config.GetValue<string>("RootMusicPath");
|
||||||
var oldSongPath = updatedSongRecord.SongPath;
|
var strCount = rootPath.Length + updatedSongRecord.Artist.Length +
|
||||||
var newSongPath = dirMgr.GenerateSongPath(updatedSongRecord);
|
updatedSongRecord.AlbumTitle.Length + 2;
|
||||||
var filename = updatedSongRecord.Filename;
|
var updatedPath = new StringBuilder(strCount);
|
||||||
|
|
||||||
Console.WriteLine($"Old song path {oldSongPath}");
|
DirectoryManager.create_directory(ConvertSongToSng(updatedSongRecord),
|
||||||
Console.WriteLine($"New song path {newSongPath}");
|
rootPath, updatedPath);
|
||||||
|
|
||||||
_logger.Info("Copying song to the new path");
|
var newSongPath = updatedPath.ToString().Substring(0, strCount) +
|
||||||
|
updatedSongRecord.Filename;
|
||||||
|
|
||||||
System.IO.File.Copy(oldSongPath, newSongPath + filename, true);
|
DirectoryManager.copy_song(newSongPath, updatedSongRecord.SongPath);
|
||||||
|
|
||||||
_logger.Info("Checking to see if song successfully copied");
|
updatedSongRecord.SongPath = newSongPath;
|
||||||
|
|
||||||
if (!System.IO.File.Exists(newSongPath + filename))
|
|
||||||
{
|
|
||||||
_logger.Info("Song did not successfully copy");
|
|
||||||
|
|
||||||
Console.WriteLine("New path does not exist when it should");
|
|
||||||
}
|
|
||||||
|
|
||||||
updatedSongRecord.SongPath = newSongPath + filename;
|
|
||||||
|
|
||||||
_logger.Info("Deleting old song path");
|
|
||||||
|
|
||||||
System.IO.File.Delete(oldSongPath);
|
|
||||||
|
|
||||||
if (System.IO.File.Exists(oldSongPath))
|
|
||||||
Console.WriteLine("Old path exists when it should not");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Info("Saving song metadata to the database");
|
_logger.Info("Saving song metadata to the database");
|
||||||
@@ -944,6 +933,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
public string Album;
|
public string Album;
|
||||||
public string Genre;
|
public string Genre;
|
||||||
public int Year;
|
public int Year;
|
||||||
|
public string SongPath;
|
||||||
};
|
};
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace Icarus.Controllers.V1
|
|||||||
#region HTTP endpoints
|
#region HTTP endpoints
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("stream:songs")]
|
[Authorize("stream:songs")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public IActionResult Get(int id)
|
||||||
{
|
{
|
||||||
var songStore= HttpContext.RequestServices
|
var songStore= HttpContext.RequestServices
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ struct Song
|
|||||||
char *Album;
|
char *Album;
|
||||||
char *Genre;
|
char *Genre;
|
||||||
int Year;
|
int Year;
|
||||||
|
char *SongPath;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -73,6 +73,18 @@ void copy_stock_to_root(const char *target, const std::string buff)
|
|||||||
|
|
||||||
std::cout<<"copy finished"<<std::endl;
|
std::cout<<"copy finished"<<std::endl;
|
||||||
}
|
}
|
||||||
|
void copy_song_to_path(const char *target, const char *source)
|
||||||
|
{
|
||||||
|
std::cout<<"starting process to copy song"<<std::endl;
|
||||||
|
auto target_path = fs::path(target);
|
||||||
|
auto src_path = fs::path(source);
|
||||||
|
|
||||||
|
std::cout<<"copting over to "<<target_path.string()<<std::endl;
|
||||||
|
fs::copy(src_path, target_path);
|
||||||
|
|
||||||
|
fs::remove(source);
|
||||||
|
std::cout<<"copy finished"<<std::endl;
|
||||||
|
}
|
||||||
void delete_cover_art_file(const std::string cov_path)
|
void delete_cover_art_file(const std::string cov_path)
|
||||||
{
|
{
|
||||||
auto cov = fs::path(cov_path);
|
auto cov = fs::path(cov_path);
|
||||||
@@ -84,6 +96,7 @@ 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 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)
|
||||||
@@ -97,6 +110,10 @@ void copy_stock_cover_art(const char *target, const char *source)
|
|||||||
const auto buff = read_cover_art(source);
|
const auto buff = read_cover_art(source);
|
||||||
copy_stock_to_root(target, buff);
|
copy_stock_to_root(target, buff);
|
||||||
}
|
}
|
||||||
|
void copy_song(const char *target, const char *source)
|
||||||
|
{
|
||||||
|
copy_song_to_path(target, source);
|
||||||
|
}
|
||||||
void delete_cover_art(const char *cover_path, const char *stock_path)
|
void delete_cover_art(const char *cover_path, const char *stock_path)
|
||||||
{
|
{
|
||||||
std::cout<<"starting process to delete cover art"<<std::endl;
|
std::cout<<"starting process to delete cover art"<<std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user