Working on implementing song compression to reduce file size of the song
This commit is contained in:
@@ -15,6 +15,7 @@ using MySql.Data.MySqlClient;
|
|||||||
using TagLib;
|
using TagLib;
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
using Icarus.Controllers.Utilities;
|
||||||
|
|
||||||
namespace Icarus.Controllers.Managers
|
namespace Icarus.Controllers.Managers
|
||||||
{
|
{
|
||||||
@@ -281,6 +282,20 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
public async Task<SongData> RetrieveCompressedSong(int id)
|
||||||
|
{
|
||||||
|
SongData song = new SongData();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_song = await RetrieveSongDetails(id);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var exMsg = ex.Message;
|
||||||
|
Console.WriteLine($"An error occurred: {exMsg}");
|
||||||
|
}
|
||||||
|
return song;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Song RetrieveMetaData(string filePath)
|
Song RetrieveMetaData(string filePath)
|
||||||
@@ -324,10 +339,11 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
SongData RetrieveSongFromFileSystem(Song details)
|
SongData RetrieveSongFromFileSystem(Song details)
|
||||||
{
|
{
|
||||||
|
byte[] uncompressedSong = System.IO.File.ReadAllBytes(details.SongPath);
|
||||||
|
|
||||||
return new SongData
|
return new SongData
|
||||||
{
|
{
|
||||||
Data = System.IO.File.ReadAllBytes(details.SongPath)
|
Data = uncompressedSong
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ namespace Icarus.Controllers
|
|||||||
song = await _songMgr.RetrieveSong(id);
|
song = await _songMgr.RetrieveSong(id);
|
||||||
|
|
||||||
return File(song.Data, "application/x-msdownload", _songMgr.SongDetails.Filename);
|
return File(song.Data, "application/x-msdownload", _songMgr.SongDetails.Filename);
|
||||||
|
//return File(song.Data, "application/x-msdownload", "demo.zip");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
|
using SevenZip.Compression.LZMA;
|
||||||
|
|
||||||
|
namespace Icarus.Controllers.Utilities
|
||||||
|
{
|
||||||
|
public class SongCompression
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
byte[] _uncompressedSong;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Propterties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public SongCompression()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public SongCompression(byte[] uncompressedSong)
|
||||||
|
{
|
||||||
|
_uncompressedSong = uncompressedSong;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
//public async Task<byte[]> CompressedSong(byte[] uncompressedSong)
|
||||||
|
public async Task<byte[]> CompressedSong(byte[] uncompressedSong)
|
||||||
|
{
|
||||||
|
byte[] compressedSong = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//compressedSong = SevenZip.Compression.LZMA.SevenZipHelper.Compress(uncompressedSong);
|
||||||
|
MemoryStream output = new MemoryStream();
|
||||||
|
using (DeflateStream dstream = new DeflateStream(output, CompressionLevel.Optimal))
|
||||||
|
{
|
||||||
|
dstream.Write(uncompressedSong, 0, uncompressedSong.Length);
|
||||||
|
compressedSong = output.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var exMsg = ex.Message;
|
||||||
|
Console.WriteLine("An error ocurred:");
|
||||||
|
Console.WriteLine(exMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return compressedSong;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="mysql.data" Version="8.0.15" />
|
<PackageReference Include="mysql.data" Version="8.0.15" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||||
|
<PackageReference Include="SevenZip" Version="19.0.0" />
|
||||||
<PackageReference Include="taglib" Version="2.1.0" />
|
<PackageReference Include="taglib" Version="2.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user