#93: Starting work to implement flac support
This commit is contained in:
@@ -207,6 +207,7 @@ public class SongManager : BaseManager
|
||||
}
|
||||
}
|
||||
|
||||
// Change the name of this method to only focus on wav files
|
||||
public void SaveSongToFileSystem(IFormFile songFile, IFormFile coverArtData, Song song)
|
||||
{
|
||||
song.SongDirectory = _tempDirectoryRoot;
|
||||
|
||||
@@ -9,6 +9,8 @@ public class MetadataRetriever
|
||||
{
|
||||
#region Fields
|
||||
private static NLog.Logger _logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
|
||||
private List<string> _supportedAudioFileTypes = new List<string> {"wav", "flac"};
|
||||
private List<string> _supportedImageFileTypes = new List<string> {"jpeg", "jpg", "png"};
|
||||
private Song _updatedSong;
|
||||
private string _message;
|
||||
private string _title;
|
||||
@@ -106,6 +108,22 @@ public class MetadataRetriever
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSupportedFile(IFormFile file)
|
||||
{
|
||||
var supportedTypes = this._supportedAudioFileTypes;
|
||||
this._supportedImageFileTypes.ForEach(t =>
|
||||
{
|
||||
if (!supportedTypes.Contains(t))
|
||||
{
|
||||
supportedTypes.Add(t);
|
||||
}
|
||||
});
|
||||
|
||||
var extensionType = this.FileExtensionType(file).ToLower();
|
||||
|
||||
return supportedTypes.Contains(extensionType);
|
||||
}
|
||||
|
||||
public Song RetrieveMetaData(string filePath)
|
||||
{
|
||||
Song song = new Song();
|
||||
|
||||
@@ -103,6 +103,20 @@ public class SongDataController : BaseController
|
||||
{
|
||||
if (up.SongData.Length > 0 && up.CoverArtData.Length > 0 && !string.IsNullOrEmpty(up.SongFile))
|
||||
{
|
||||
var meta = new Utilities.MetadataRetriever();
|
||||
if (!meta.IsSupportedFile(up.SongData) && !meta.IsSupportedFile(up.CoverArtData))
|
||||
{
|
||||
return BadRequest("Media is not supported");
|
||||
}
|
||||
else if (!meta.IsSupportedFile(up.SongData))
|
||||
{
|
||||
return BadRequest("Song is not supported");
|
||||
}
|
||||
else if (!meta.IsSupportedFile(up.CoverArtData))
|
||||
{
|
||||
return BadRequest("Cover art is not supported");
|
||||
}
|
||||
|
||||
var song = Newtonsoft.Json.JsonConvert.DeserializeObject<Song>(up.SongFile);
|
||||
var tokMgr = new TokenManager(this._config);
|
||||
var accessToken = Request.Headers["Authorization"];
|
||||
@@ -115,6 +129,9 @@ public class SongDataController : BaseController
|
||||
|
||||
_logger.LogInformation($"Song title: {song.Title}");
|
||||
|
||||
|
||||
// TODO: Identify the song file type. Then save the media.
|
||||
// Create a new method to save song flac files
|
||||
_songMgr.SaveSongToFileSystem(up.SongData, up.CoverArtData, song);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user