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