Working on migrating metadata over to c++

This commit is contained in:
kdeng00
2019-08-08 18:40:15 -04:00
parent 47723c7d94
commit ead71da802
4 changed files with 98 additions and 15 deletions
+33 -4
View File
@@ -235,6 +235,19 @@ namespace Icarus.Controllers.Managers
SongPath = song.SongPath
};
}
public static Song ConvertSngToSong(Sng song)
{
return new Song
{
Id = song.Id,
Title = song.Title,
Artist = song.Artist,
AlbumTitle = song.Album,
Genre = song.Genre,
Year = song.Year,
SongPath = song.SongPath
};
}
private async Task<SongData> RetrieveSongFromFileSystem(Song details)
@@ -257,15 +270,26 @@ namespace Icarus.Controllers.Managers
await songFile.CopyToAsync(filestream);
}
MetadataRetriever meta = new MetadataRetriever();
song = meta.RetrieveMetaData(filePath);
//MetadataRetriever meta = new MetadataRetriever();
//song = meta.RetrieveMetaData(filePath);
Console.WriteLine("try");
unsafe
{
Song *sng = new Sng();
MetadataRetriever.retrieve_metadata(ref sng, filePath);
Console.WriteLine("Hmmmm");
Console.WriteLine($"sng title {sng.Title}");
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))
@@ -283,6 +307,7 @@ namespace Icarus.Controllers.Managers
Console.WriteLine($"Song filename retrieved: {song.FileName}");
}
}
*/
private bool SongRecordChanged(Song currentSong, Song songUpdates)
{
@@ -761,20 +786,24 @@ namespace Icarus.Controllers.Managers
if (year.SongCount <= 1)
yearStore.DeleteYear(year);
}
#endregion
#region Structs
[StructLayout(LayoutKind.Sequential)]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Sng
{
public int Id;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
public string Title;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
public string Artist;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
public string Album;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
public string Genre;
public int Year;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
public string SongPath;
};
#endregion
+2 -1
View File
@@ -103,7 +103,8 @@ namespace Icarus.Controllers.Utilities
}
[DllImport("libicarus.so")]
public static extern Icarus.Controllers.Managers.SongManager.Sng retrieve_metadata(string file_path);
//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);
public byte[] RetrieveCoverArtBytes(Song song)
{
+1 -1
View File
@@ -2,4 +2,4 @@
#include "models.h"
Song fetch_metadata(const char*);
void fetch_metadata(Song&, const char*);
+62 -9
View File
@@ -1,26 +1,79 @@
#include <iostream>
#include <string>
#include <taglib/tag.h>
#include <taglib/fileref.h>
#include <string.h>
#include "metadata_retriever.h"
Song fetch_metadata(const char *song_path)
void fetch_metadata(Song &sng, const char *song_path)
{
Song sng;
std::string title = "ddd";
sng.Title = (char*)title.c_str();
sng.SongPath = (char*)song_path;
//Song sng;
std::cout<<"extracting metadata from: "<<std::endl;
std::cout<<song_path<<std::endl;
return sng;
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"
{
Song retrieve_metadata(const char*);
void retrieve_metadata(Song*, char*);
Song retrieve_metadata(const char* song_path)
void retrieve_metadata(Song *song, char* song_path)
{
return fetch_metadata(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();
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;
}
}