Minor changes to metadata reading
This commit is contained in:
@@ -58,11 +58,6 @@ namespace Icarus.Controllers.Managers
|
||||
public SongManager()
|
||||
{
|
||||
}
|
||||
|
||||
public SongManager(Song song)
|
||||
{
|
||||
_song = song;
|
||||
}
|
||||
public SongManager(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
@@ -232,6 +227,7 @@ namespace Icarus.Controllers.Managers
|
||||
Album = song.AlbumTitle,
|
||||
Genre = song.Genre,
|
||||
Year = song.Year.Value,
|
||||
Duration = song.Duration,
|
||||
SongPath = song.SongPath
|
||||
};
|
||||
}
|
||||
@@ -245,6 +241,7 @@ namespace Icarus.Controllers.Managers
|
||||
AlbumTitle = song.Album,
|
||||
Genre = song.Genre,
|
||||
Year = song.Year,
|
||||
Duration = song.Duration,
|
||||
SongPath = song.SongPath
|
||||
};
|
||||
}
|
||||
@@ -261,54 +258,22 @@ namespace Icarus.Controllers.Managers
|
||||
}
|
||||
private async Task<Song> SaveSongTemp(IFormFile songFile, string filePath)
|
||||
{
|
||||
var song = new Song();
|
||||
|
||||
|
||||
using (var filestream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
_logger.Info("Saving song to temporary directory");
|
||||
await songFile.CopyToAsync(filestream);
|
||||
}
|
||||
|
||||
//MetadataRetriever meta = new MetadataRetriever();
|
||||
//song = meta.RetrieveMetaData(filePath);
|
||||
Console.WriteLine("try");
|
||||
unsafe
|
||||
{
|
||||
Song *sng = new Sng();
|
||||
var sng = new Sng();
|
||||
MetadataRetriever.retrieve_metadata(ref sng, filePath);
|
||||
Console.WriteLine("Hmmmm");
|
||||
Console.WriteLine($"sng title {sng.Title}");
|
||||
song = ConvertSngToSong(sng);
|
||||
}
|
||||
var song = ConvertSngToSong(sng);
|
||||
|
||||
_logger.Info("Assigning song filename");
|
||||
song.Filename = songFile.FileName;
|
||||
|
||||
Console.WriteLine("what?");
|
||||
return song;
|
||||
}
|
||||
|
||||
/**
|
||||
private async Task SaveSongToFileSystemTemp(IFormFile song, string filePath)
|
||||
{
|
||||
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
Console.WriteLine("Retrieving song and storing it in memory");
|
||||
_logger.Info("Retrieving song and storing it in memory");
|
||||
await song.CopyToAsync(fileStream);
|
||||
Console.WriteLine($"Retrieving metadata of song from filepath {filePath}");
|
||||
_logger.Info($"Retrieving metadata of song from filepath {filePath}");
|
||||
MetadataRetriever meta = new MetadataRetriever();
|
||||
_song = meta.RetrieveMetaData(filePath);
|
||||
|
||||
Console.WriteLine("Assigning song filename");
|
||||
_song.Filename = song.FileName;
|
||||
Console.WriteLine($"Song filename retrieved: {song.FileName}");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private bool SongRecordChanged(Song currentSong, Song songUpdates)
|
||||
{
|
||||
var currentTitle = currentSong.Title;
|
||||
@@ -338,23 +303,24 @@ namespace Icarus.Controllers.Managers
|
||||
var info = "Saving Song to DB";
|
||||
Console.WriteLine(info);
|
||||
_logger.Info(info);
|
||||
|
||||
songStore.SaveSong(song);
|
||||
}
|
||||
private void SaveAlbumToDatabase(ref Song song, AlbumRepository albumStore)
|
||||
{
|
||||
_logger.Info("Starting process to save the album record of the song to the database");
|
||||
|
||||
var album = new Album();
|
||||
|
||||
album.Title = song.AlbumTitle;
|
||||
album.AlbumArtist = song.Artist;
|
||||
var album = new Album()
|
||||
{
|
||||
Title = song.AlbumTitle,
|
||||
AlbumArtist = song.Artist
|
||||
};
|
||||
|
||||
if (!albumStore.DoesAlbumExist(song))
|
||||
{
|
||||
album.SongCount = 1;
|
||||
albumStore.SaveAlbum(album);
|
||||
album = albumStore.GetAlbum(song);
|
||||
Console.WriteLine($"Album Id {album.AlbumId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -371,10 +337,11 @@ namespace Icarus.Controllers.Managers
|
||||
{
|
||||
_logger.Info("Starting process to save the artist record of the song to the database");
|
||||
|
||||
var artist = new Artist();
|
||||
|
||||
artist.Name = song.Artist;
|
||||
artist.SongCount = 1;
|
||||
var artist = new Artist
|
||||
{
|
||||
Name = song.Artist,
|
||||
SongCount = 1
|
||||
};
|
||||
|
||||
if (!artistStore.DoesArtistExist(song))
|
||||
{
|
||||
@@ -794,16 +761,17 @@ namespace Icarus.Controllers.Managers
|
||||
public struct Sng
|
||||
{
|
||||
public int Id;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
|
||||
public string Title;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
|
||||
public string Artist;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
|
||||
public string Album;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
|
||||
public string Genre;
|
||||
public int Year;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
|
||||
public int Duration;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
|
||||
public string SongPath;
|
||||
};
|
||||
#endregion
|
||||
|
||||
@@ -16,12 +16,6 @@ namespace Icarus.Controllers.Utilities
|
||||
private static NLog.Logger _logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
|
||||
private Song _updatedSong;
|
||||
private string _message;
|
||||
private string _title;
|
||||
private string _artist;
|
||||
private string _album;
|
||||
private string _genre;
|
||||
private int _year;
|
||||
private int _duration;
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -39,10 +33,6 @@ namespace Icarus.Controllers.Utilities
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
#endregion
|
||||
|
||||
|
||||
#region Methods
|
||||
public static void PrintMetadata(Song song)
|
||||
{
|
||||
@@ -70,41 +60,11 @@ namespace Icarus.Controllers.Utilities
|
||||
_logger.Info($"Year: {song.Year}");
|
||||
_logger.Info($"Duration: {song.Duration}");
|
||||
}
|
||||
public Song RetrieveMetaData(string filePath)
|
||||
{
|
||||
Song song = new Song();
|
||||
|
||||
try
|
||||
{
|
||||
TagLib.File fileTag = TagLib.File.Create(filePath);
|
||||
_title = fileTag.Tag.Title;
|
||||
_artist = string.Join("", fileTag.Tag.Performers);
|
||||
_album = fileTag.Tag.Album;
|
||||
_genre = string.Join("", fileTag.Tag.Genres);
|
||||
_year = (int)fileTag.Tag.Year;
|
||||
_duration = (int)fileTag.Properties.Duration.TotalSeconds;
|
||||
|
||||
song.Title = _title;
|
||||
song.Artist = _artist;
|
||||
song.AlbumTitle = _album;
|
||||
song.Genre = _genre;
|
||||
song.Year = _year;
|
||||
song.Duration = _duration;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
Console.WriteLine("An error occurred in MetadataRetriever");
|
||||
Console.WriteLine(msg);
|
||||
_logger.Error(msg, "An error occurred in MetadataRetriever");
|
||||
}
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
#region C++ Libs
|
||||
[DllImport("libicarus.so")]
|
||||
//public static extern Icarus.Controllers.Managers.SongManager.Sng retrieve_metadata(string file_path);
|
||||
public static extern void retrieve_metadata(ref Icarus.Controllers.Managers.SongManager.Sng sng, string file_path);
|
||||
#endregion
|
||||
|
||||
public byte[] RetrieveCoverArtBytes(Song song)
|
||||
{
|
||||
@@ -125,28 +85,6 @@ namespace Icarus.Controllers.Utilities
|
||||
return null;
|
||||
}
|
||||
|
||||
public void UpdateMetadata(Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Updating song metadata");
|
||||
_logger.Info("Updating song metadata");
|
||||
var filePath = song.SongPath;
|
||||
TagLib.File fileTag = TagLib.File.Create(filePath);
|
||||
fileTag.Tag.Title = song.Title;
|
||||
fileTag.Tag.Genres = new []{song.Genre};
|
||||
fileTag.Save();
|
||||
Console.WriteLine("Song metadata updated");
|
||||
_logger.Info("Song metadata updated");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
Console.WriteLine($"An error occurred: \n{msg}");
|
||||
_logger.Error(msg, "An error occurred");
|
||||
}
|
||||
}
|
||||
public void UpdateMetadata(Song updatedSong, Song oldSong)
|
||||
{
|
||||
try
|
||||
@@ -253,42 +191,6 @@ namespace Icarus.Controllers.Utilities
|
||||
SongPath = song.SongPath
|
||||
};
|
||||
}
|
||||
private void PrintMetadata()
|
||||
{
|
||||
Console.WriteLine("\n\nMetadata of the song:");
|
||||
Console.WriteLine($"Title: {_title}");
|
||||
Console.WriteLine($"Artist: {_artist}");
|
||||
Console.WriteLine($"Album: {_album}");
|
||||
Console.WriteLine($"Genre: {_genre}");
|
||||
Console.WriteLine($"Year: {_year}");
|
||||
Console.WriteLine($"Duration: {_duration}\n\n");
|
||||
|
||||
_logger.Info("Metadata of the song");
|
||||
_logger.Info($"Title: {_title}");
|
||||
_logger.Info($"Artist: {_artist}");
|
||||
_logger.Info($"Album: {_album}");
|
||||
_logger.Info($"Genre: {_genre}");
|
||||
_logger.Info($"Year: {_year}");
|
||||
_logger.Info($"Duration: {_duration}");
|
||||
}
|
||||
private void PrintMetadata(Song song, string message)
|
||||
{
|
||||
Console.WriteLine($"\n\n{message}");
|
||||
Console.WriteLine($"Title: {song.Title}");
|
||||
Console.WriteLine($"Artist: {song.Artist}");
|
||||
Console.WriteLine($"Album: {song.Album}");
|
||||
Console.WriteLine($"Genre: {song.Genre}");
|
||||
Console.WriteLine($"Year: {song.Year}");
|
||||
Console.WriteLine($"Duration: {song.Duration}\n\n");
|
||||
|
||||
_logger.Info(message);
|
||||
_logger.Info($"Title: {_title}");
|
||||
_logger.Info($"Artist: {_artist}");
|
||||
_logger.Info($"Album: {_album}");
|
||||
_logger.Info($"Genre: {_genre}");
|
||||
_logger.Info($"Year: {_year}");
|
||||
_logger.Info($"Duration: {_duration}");
|
||||
}
|
||||
|
||||
private SortedDictionary<string, bool> CheckSongValues(Song song)
|
||||
{
|
||||
|
||||
@@ -45,11 +45,11 @@ namespace Icarus.Controllers.V1
|
||||
[Authorize("read:song_details")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
List<Song> songs = new List<Song>();
|
||||
var songs = new List<Song>();
|
||||
Console.WriteLine("Attemtping to retrieve songs");
|
||||
_logger.LogInformation("Attempting to retrieve songs");
|
||||
|
||||
SongRepository context = HttpContext.RequestServices
|
||||
var context = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
songs = context.GetAllSongs();
|
||||
@@ -64,14 +64,12 @@ namespace Icarus.Controllers.V1
|
||||
[Authorize("read:song_details")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
SongRepository context = HttpContext.RequestServices
|
||||
var context = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
Song song = new Song { Id = id };
|
||||
var song = new Song { Id = id };
|
||||
song = context.GetSong(song);
|
||||
|
||||
Console.WriteLine("Here");
|
||||
|
||||
if (song.Id != 0)
|
||||
return Ok(song);
|
||||
else
|
||||
@@ -82,19 +80,19 @@ namespace Icarus.Controllers.V1
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult Put(int id, [FromBody] Song song)
|
||||
{
|
||||
SongRepository context = HttpContext.RequestServices
|
||||
var context = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
ArtistRepository artistStore = HttpContext.RequestServices
|
||||
var artistStore = HttpContext.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
|
||||
AlbumRepository albumStore = HttpContext.RequestServices
|
||||
var albumStore = HttpContext.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
|
||||
GenreRepository genreStore = HttpContext.RequestServices
|
||||
var genreStore = HttpContext.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
|
||||
YearRepository yearStore = HttpContext.RequestServices
|
||||
var yearStore = HttpContext.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
song.Id = id;
|
||||
|
||||
@@ -9,14 +9,6 @@ namespace Icarus.Database.Repositories
|
||||
{
|
||||
public class SongRepository : BaseRepository
|
||||
{
|
||||
#region Fields
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public SongRepository(string connectionString)
|
||||
{
|
||||
@@ -165,7 +157,7 @@ namespace Icarus.Database.Repositories
|
||||
|
||||
public List<Song> GetAllSongs()
|
||||
{
|
||||
List<Song> songs = new List<Song>();
|
||||
var songs = new List<Song>();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -174,8 +166,8 @@ namespace Icarus.Database.Repositories
|
||||
{
|
||||
conn.Open();
|
||||
var query = "SELECT * FROM Song";
|
||||
Console.WriteLine("ffff");
|
||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||
|
||||
using (var cmd = new MySqlCommand(query, conn))
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
songs = ParseData(reader);
|
||||
}
|
||||
@@ -269,7 +261,7 @@ namespace Icarus.Database.Repositories
|
||||
private List<Song> ParseData(MySqlDataReader reader)
|
||||
{
|
||||
|
||||
List<Song> songs = new List<Song>();
|
||||
var songs = new List<Song>();
|
||||
while (reader.Read())
|
||||
{
|
||||
songs.Add(new Song
|
||||
@@ -296,7 +288,7 @@ namespace Icarus.Database.Repositories
|
||||
|
||||
private Song ParseSingleData(MySqlDataReader reader)
|
||||
{
|
||||
Song song = new Song();
|
||||
var song = new Song();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
@@ -318,7 +310,6 @@ namespace Icarus.Database.Repositories
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "models.h"
|
||||
|
||||
void fetch_metadata(Song&, const char*);
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
struct Song
|
||||
{
|
||||
int Id;
|
||||
char *Title;
|
||||
char *Artist;
|
||||
char *Album;
|
||||
char *Genre;
|
||||
char Title[1024];
|
||||
char Artist[1024];
|
||||
char Album[1024];
|
||||
char Genre[1024];
|
||||
int Year;
|
||||
char *SongPath;
|
||||
int Duration;
|
||||
char SongPath[1024];
|
||||
};
|
||||
|
||||
@@ -6,74 +6,23 @@
|
||||
|
||||
#include "metadata_retriever.h"
|
||||
|
||||
void fetch_metadata(Song &sng, const char *song_path)
|
||||
{
|
||||
//Song sng;
|
||||
std::cout<<"extracting metadata from: "<<std::endl;
|
||||
std::cout<<song_path<<std::endl;
|
||||
|
||||
TagLib::FileRef file(song_path);
|
||||
//std::cout<<"0"<<std::endl;
|
||||
sng.Title = (char*)file.tag()->title().toCString();
|
||||
//sng->Title = (char*)file.tag()->title().toCString();
|
||||
std::cout<<"Title: "<<sng.Title<<std::endl;
|
||||
//std::cout<<"Title: "<<sng->Title<<std::endl;
|
||||
//std::cout<<"0"<<std::endl;
|
||||
sng.Artist = (char*)file.tag()->artist().toCString();
|
||||
//sng->Artist = (char*)file.tag()->artist().toCString();
|
||||
//std::cout<<"0"<<std::endl;
|
||||
sng.Album = (char*)file.tag()->album().toCString();
|
||||
//sng->Album = (char*)file.tag()->album().toCString();
|
||||
//std::cout<<"0"<<std::endl;
|
||||
sng.Genre = (char*)file.tag()->genre().toCString();
|
||||
//sng->Genre = (char*)file.tag()->genre().toCString();
|
||||
//std::cout<<"0"<<std::endl;
|
||||
sng.Year = file.tag()->year();
|
||||
//sng->Year = file.tag()->year();
|
||||
//std::cout<<"0"<<std::endl;
|
||||
sng.SongPath = (char*)song_path;
|
||||
//sng->SongPath = (char*)song_path;
|
||||
//std::cout<<"0"<<std::endl;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void retrieve_metadata(Song*, char*);
|
||||
|
||||
void retrieve_metadata(Song *song, char* song_path)
|
||||
void retrieve_metadata(Song *sng, char* song_path)
|
||||
{
|
||||
std::cout<<"extern C"<<std::endl;
|
||||
//Song sng;
|
||||
Song *sng;
|
||||
//fetch_metadata(sn,song_path);
|
||||
//
|
||||
//
|
||||
TagLib::FileRef file(song_path);
|
||||
//std::cout<<"0"<<std::endl;
|
||||
//sng.Title = (char*)file.tag()->title().toCString();
|
||||
sng->Title = (char*)file.tag()->title().toCString();
|
||||
//strcpy(sng->Title, file.tag()->title().toCString());
|
||||
//std::cout<<"Title: "<<sng.Title<<std::endl;
|
||||
std::cout<<"Title: "<<sng->Title<<std::endl;
|
||||
//std::cout<<"0"<<std::endl;
|
||||
//sng.Artist = (char*)file.tag()->artist().toCString();
|
||||
sng->Artist = (char*)file.tag()->artist().toCString();
|
||||
//std::cout<<"0"<<std::endl;
|
||||
//sng.Album = (char*)file.tag()->album().toCString();
|
||||
sng->Album = (char*)file.tag()->album().toCString();
|
||||
//std::cout<<"0"<<std::endl;
|
||||
//sng.Genre = (char*)file.tag()->genre().toCString();
|
||||
sng->Genre = (char*)file.tag()->genre().toCString();
|
||||
//std::cout<<"0"<<std::endl;
|
||||
//sng.Year = file.tag()->year();
|
||||
|
||||
strcpy(sng->Title, file.tag()->title().toCString());
|
||||
strcpy(sng->Artist, file.tag()->artist().toCString());
|
||||
strcpy(sng->Album, file.tag()->album().toCString());
|
||||
strcpy(sng->Genre, file.tag()->genre().toCString());
|
||||
sng->Year = file.tag()->year();
|
||||
//std::cout<<"0"<<std::endl;
|
||||
//sng.SongPath = (char*)song_path;
|
||||
sng->SongPath = (char*)song_path;
|
||||
//std::cout<<"res"<<std::endl<<sn.Title<<std::endl;
|
||||
//*song = sn;
|
||||
std::cout<<"done"<<std::endl;
|
||||
sng->Duration = file.audioProperties()->lengthInSeconds();
|
||||
strcpy(sng->SongPath, song_path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user