Switched to the TagLib library for stripping metadata. Included TODO for updating a song's metadata for both the database and the tag of the MP3 file #36
This commit is contained in:
@@ -218,7 +218,6 @@ namespace Icarus.Controllers.Managers
|
||||
_song.SongPath = filePath;
|
||||
|
||||
Console.WriteLine($"Writing song to the directory: {filePath}");
|
||||
Console.WriteLine("Song successfully saved");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -404,7 +403,9 @@ namespace Icarus.Controllers.Managers
|
||||
Console.WriteLine("Retrieving song and storing it in memory");
|
||||
await song.CopyToAsync(fileStream);
|
||||
Console.WriteLine($"Retrieving metadata of song from filepath {filePath}");
|
||||
_song = RetrieveMetaData(filePath);
|
||||
MetadataRetriever meta = new MetadataRetriever();
|
||||
_song = meta.RetrieveMetaData(filePath);
|
||||
//_song = RetrieveMetaData(filePath);
|
||||
Console.WriteLine("Assigning song filename");
|
||||
_song.Filename = song.FileName;
|
||||
Console.WriteLine($"Song filename retrieved: {song.FileName}");
|
||||
|
||||
@@ -68,20 +68,14 @@ namespace Icarus.Controllers
|
||||
return song;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Post([FromBody] Song song)
|
||||
{
|
||||
MusicStoreContext context = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(MusicStoreContext))
|
||||
as MusicStoreContext;
|
||||
|
||||
context.SaveSong(song);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] Song song)
|
||||
public IActionResult Put(int id, [FromBody] Song song)
|
||||
{
|
||||
// TODO: Implement updating of song metadata
|
||||
SongResult songResult = new SongResult();
|
||||
|
||||
return Ok(songResult);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
|
||||
@@ -89,11 +89,6 @@ namespace Icarus.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] SongData song)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize("delete:songs")]
|
||||
public void Delete(int id)
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
|
||||
using TagLib;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Controllers.Utilities
|
||||
{
|
||||
public class MetadataRetriever
|
||||
{
|
||||
#region Fields
|
||||
private string _title;
|
||||
private string _artist;
|
||||
private string _album;
|
||||
private string _genre;
|
||||
private int _year;
|
||||
private int _duration;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
#endregion
|
||||
|
||||
|
||||
#region Methods
|
||||
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.Artists);
|
||||
_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.Album = _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);
|
||||
}
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user