Contining work on #55
This commit is contained in:
@@ -13,18 +13,18 @@ namespace Icarus.Controllers.Utilities
|
||||
public class SongCompression
|
||||
{
|
||||
#region Fields
|
||||
string _compressedSongFilename;
|
||||
string _tempDirectory;
|
||||
string _compressedSongFilename;
|
||||
string _tempDirectory;
|
||||
byte[] _uncompressedSong;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Propterties
|
||||
public string CompressedSongFilename
|
||||
{
|
||||
get => _compressedSongFilename;
|
||||
set => _compressedSongFilename = value;
|
||||
}
|
||||
public string CompressedSongFilename
|
||||
{
|
||||
get => _compressedSongFilename;
|
||||
set => _compressedSongFilename = value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@ namespace Icarus.Controllers.Utilities
|
||||
public SongCompression()
|
||||
{
|
||||
}
|
||||
public SongCompression(string tempDirectory)
|
||||
{
|
||||
_tempDirectory = tempDirectory;
|
||||
}
|
||||
public SongCompression(string tempDirectory)
|
||||
{
|
||||
_tempDirectory = tempDirectory;
|
||||
}
|
||||
public SongCompression(byte[] uncompressedSong)
|
||||
{
|
||||
_uncompressedSong = uncompressedSong;
|
||||
@@ -44,60 +44,60 @@ namespace Icarus.Controllers.Utilities
|
||||
|
||||
|
||||
#region Methods
|
||||
public async Task<SongData> RetrieveCompressedSong(Song song)
|
||||
{
|
||||
SongData songData = new SongData();
|
||||
try
|
||||
{
|
||||
var archivePath = RetrieveCompressesSongPath(song);
|
||||
Console.WriteLine($"Compressed song saved to: {archivePath}");
|
||||
|
||||
songData.Data = System.IO.File.ReadAllBytes(archivePath);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
var exMsg = ex.Message;
|
||||
Console.WriteLine($"An error ocurred: \n{exMsg}");
|
||||
}
|
||||
public async Task<SongData> RetrieveCompressedSong(Song song)
|
||||
{
|
||||
SongData songData = new SongData();
|
||||
try
|
||||
{
|
||||
var archivePath = RetrieveCompressesSongPath(song);
|
||||
Console.WriteLine($"Compressed song saved to: {archivePath}");
|
||||
|
||||
songData.Data = await System.IO.File.ReadAllBytesAsync(archivePath);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
var exMsg = ex.Message;
|
||||
Console.WriteLine($"An error ocurred: \n{exMsg}");
|
||||
}
|
||||
|
||||
return songData;
|
||||
}
|
||||
return songData;
|
||||
}
|
||||
|
||||
public string RetrieveCompressesSongPath(Song songDetails)
|
||||
{
|
||||
string tmpZipFilePath = _tempDirectory + songDetails.Filename;
|
||||
public string RetrieveCompressesSongPath(Song songDetails)
|
||||
{
|
||||
string tmpZipFilePath = _tempDirectory + songDetails.Filename;
|
||||
|
||||
try
|
||||
{
|
||||
using (ZipFile zip = new ZipFile())
|
||||
{
|
||||
zip.AddFile(songDetails.SongPath);
|
||||
zip.Save(tmpZipFilePath);
|
||||
}
|
||||
Console.WriteLine("Successfully compressed");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var exMsg = ex.Message;
|
||||
Console.WriteLine("An error ocurred");
|
||||
Console.WriteLine(exMsg);
|
||||
}
|
||||
try
|
||||
{
|
||||
using (ZipFile zip = new ZipFile())
|
||||
{
|
||||
zip.AddFile(songDetails.SongPath);
|
||||
zip.Save(tmpZipFilePath);
|
||||
}
|
||||
Console.WriteLine("Successfully compressed");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var exMsg = ex.Message;
|
||||
Console.WriteLine("An error ocurred");
|
||||
Console.WriteLine(exMsg);
|
||||
}
|
||||
|
||||
if (songDetails.Filename.Contains(".mp3"))
|
||||
{
|
||||
_compressedSongFilename = StripMP3Extension(songDetails.Filename);
|
||||
}
|
||||
if (songDetails.Filename.Contains(".mp3"))
|
||||
{
|
||||
_compressedSongFilename = StripMP3Extension(songDetails.Filename);
|
||||
}
|
||||
|
||||
return tmpZipFilePath;
|
||||
}
|
||||
return tmpZipFilePath;
|
||||
}
|
||||
|
||||
// Method not being used
|
||||
// Method not being used
|
||||
public byte[] CompressedSong(byte[] uncompressedSong)
|
||||
{
|
||||
byte[] compressedSong = null;
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Song has been successfully compressed");
|
||||
Console.WriteLine("Song has been successfully compressed");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -110,20 +110,20 @@ namespace Icarus.Controllers.Utilities
|
||||
}
|
||||
|
||||
|
||||
string StripMP3Extension(string filename)
|
||||
{
|
||||
Console.WriteLine($"Before: {filename}");
|
||||
int filenameLength = filename.Length;
|
||||
Console.WriteLine($"Filename length {filenameLength}");
|
||||
var endIndex = filenameLength - 1;
|
||||
var startIndex = endIndex - 3;
|
||||
Console.WriteLine($"Starting index {startIndex} and ending index {endIndex}");
|
||||
var stripped = filename.Remove(startIndex, 4);
|
||||
stripped += ".zip";
|
||||
Console.WriteLine($"After {stripped}");
|
||||
string StripMP3Extension(string filename)
|
||||
{
|
||||
Console.WriteLine($"Before: {filename}");
|
||||
int filenameLength = filename.Length;
|
||||
Console.WriteLine($"Filename length {filenameLength}");
|
||||
var endIndex = filenameLength - 1;
|
||||
var startIndex = endIndex - 3;
|
||||
Console.WriteLine($"Starting index {startIndex} and ending index {endIndex}");
|
||||
var stripped = filename.Remove(startIndex, 4);
|
||||
stripped += ".zip";
|
||||
Console.WriteLine($"After {stripped}");
|
||||
|
||||
return stripped;
|
||||
}
|
||||
return stripped;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user