#93: Starting work to implement flac support

This commit is contained in:
kdeng00
2024-07-08 19:08:26 -04:00
parent fbb761fb5c
commit bde264fedc
4 changed files with 39 additions and 0 deletions
+3
View File
@@ -11,6 +11,9 @@ public class FileExtensions
// Contains file extension with period at the beginning // Contains file extension with period at the beginning
public static string JPG_EXTENSION = ".jpg"; public static string JPG_EXTENSION = ".jpg";
// Contains file extension with period at the beginning
public static string FLAC_EXTENSION = ".flac";
// Contains file extension with period at the beginning // Contains file extension with period at the beginning
public static string ZIP_EXTENSION = ".zip"; public static string ZIP_EXTENSION = ".zip";
} }
+1
View File
@@ -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) public void SaveSongToFileSystem(IFormFile songFile, IFormFile coverArtData, Song song)
{ {
song.SongDirectory = _tempDirectoryRoot; song.SongDirectory = _tempDirectoryRoot;
@@ -9,6 +9,8 @@ public class MetadataRetriever
{ {
#region Fields #region Fields
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 List<string> _supportedAudioFileTypes = new List<string> {"wav", "flac"};
private List<string> _supportedImageFileTypes = new List<string> {"jpeg", "jpg", "png"};
private Song _updatedSong; private Song _updatedSong;
private string _message; private string _message;
private string _title; 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) public Song RetrieveMetaData(string filePath)
{ {
Song song = new Song(); Song song = new Song();
+17
View File
@@ -103,6 +103,20 @@ public class SongDataController : BaseController
{ {
if (up.SongData.Length > 0 && up.CoverArtData.Length > 0 && !string.IsNullOrEmpty(up.SongFile)) 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 song = Newtonsoft.Json.JsonConvert.DeserializeObject<Song>(up.SongFile);
var tokMgr = new TokenManager(this._config); var tokMgr = new TokenManager(this._config);
var accessToken = Request.Headers["Authorization"]; var accessToken = Request.Headers["Authorization"];
@@ -115,6 +129,9 @@ public class SongDataController : BaseController
_logger.LogInformation($"Song title: {song.Title}"); _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); _songMgr.SaveSongToFileSystem(up.SongData, up.CoverArtData, song);
} }
} }