* #94: Saving the file type of cover art, but there is still some work to do The filename of cover art is hard coded to have the png extension. Need to correct this * #94: Added a TODO * #94: Corrected file extension being saved in the db * Cleanup * Saving databasescripts
This commit was merged in pull request #100.
This commit is contained in:
@@ -2,8 +2,8 @@ namespace Icarus.Constants;
|
|||||||
|
|
||||||
public class DirectoryPaths
|
public class DirectoryPaths
|
||||||
{
|
{
|
||||||
public static string CoverArtPath =>
|
public static string CoverArtDirectory => Directory.GetCurrentDirectory() + "/Images/Stock/";
|
||||||
Directory.GetCurrentDirectory() + "/Images/Stock/CoverArt.png";
|
public static string CoverArtFilename => "CoverArt.png";
|
||||||
public static string FILENAME_CHARACTERS = "ABCDEF0123456789";
|
public static string FILENAME_CHARACTERS = "ABCDEF0123456789";
|
||||||
public static int FILENAME_LENGTH = 25;
|
public static int FILENAME_LENGTH = 25;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,11 +48,11 @@ public class CoverArtManager : BaseManager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var stockCoverArtPath = _rootCoverArtPath + "CoverArt.png";
|
var stockCoverArtPath = _rootCoverArtPath + "CoverArt.png";
|
||||||
if (!string.Equals(stockCoverArtPath, coverArt.ImagePath,
|
if (!string.Equals(stockCoverArtPath, coverArt.ImagePath(),
|
||||||
StringComparison.CurrentCultureIgnoreCase))
|
StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
_logger.Info("Song does not contain the stock cover art");
|
_logger.Info("Song does not contain the stock cover art");
|
||||||
File.Delete(coverArt.ImagePath);
|
File.Delete(coverArt.ImagePath());
|
||||||
_logger.Info("Cover art deleted from the filesystem");
|
_logger.Info("Cover art deleted from the filesystem");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -82,9 +82,8 @@ public class CoverArtManager : BaseManager
|
|||||||
};
|
};
|
||||||
|
|
||||||
var segment = coverArt.GenerateFilename(0);
|
var segment = coverArt.GenerateFilename(0);
|
||||||
var imagePath = dirMgr.SongDirectory + segment + defaultExtension;
|
coverArt.Directory = dirMgr.SongDirectory;
|
||||||
|
coverArt.Filename = segment + defaultExtension;
|
||||||
coverArt.ImagePath = imagePath;
|
|
||||||
|
|
||||||
var metaData = new MetadataRetriever();
|
var metaData = new MetadataRetriever();
|
||||||
var imgBytes = metaData.RetrieveCoverArtBytes(song);
|
var imgBytes = metaData.RetrieveCoverArtBytes(song);
|
||||||
@@ -92,17 +91,27 @@ public class CoverArtManager : BaseManager
|
|||||||
if (imgBytes != null)
|
if (imgBytes != null)
|
||||||
{
|
{
|
||||||
_logger.Info("Saving cover art to the filesystem");
|
_logger.Info("Saving cover art to the filesystem");
|
||||||
File.WriteAllBytes(coverArt.ImagePath, imgBytes);
|
File.WriteAllBytes(coverArt.ImagePath(), imgBytes);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Info("Song has no cover art, applying stock cover art");
|
_logger.Info("Song has no cover art, applying stock cover art");
|
||||||
|
|
||||||
var coverArtFilePath = _rootCoverArtPath + $"{segment}{defaultExtension}";
|
var coverArtFilePath = _rootCoverArtPath + $"{segment}{defaultExtension}";
|
||||||
coverArt.ImagePath = DirectoryPaths.CoverArtPath;
|
coverArt.Directory = DirectoryPaths.CoverArtDirectory;
|
||||||
|
coverArt.Filename = DirectoryPaths.CoverArtFilename;
|
||||||
metaData.UpdateCoverArt(song, coverArt);
|
metaData.UpdateCoverArt(song, coverArt);
|
||||||
coverArt.ImagePath = coverArtFilePath;
|
coverArt.Directory = this._rootCoverArtPath;
|
||||||
File.WriteAllBytes(coverArt.ImagePath, _stockCoverArt);
|
coverArt.Filename = $"{segment}{defaultExtension}";
|
||||||
|
File.WriteAllBytes(coverArt.ImagePath(), _stockCoverArt);
|
||||||
|
}
|
||||||
|
|
||||||
|
coverArt.Type = metaData.CoverArtFileExtensionType(coverArt);
|
||||||
|
if (string.IsNullOrEmpty(coverArt.Type))
|
||||||
|
{
|
||||||
|
Console.WriteLine("File type is empty");
|
||||||
|
Console.WriteLine($"Directory: {coverArt.Directory}");
|
||||||
|
Console.WriteLine($"Filename: {coverArt.Filename}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return coverArt;
|
return coverArt;
|
||||||
@@ -122,16 +131,19 @@ public class CoverArtManager : BaseManager
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
MetadataRetriever metaData = new MetadataRetriever();
|
||||||
var dirMgr = new DirectoryManager(_rootCoverArtPath);
|
var dirMgr = new DirectoryManager(_rootCoverArtPath);
|
||||||
var defaultExtension = ".png";
|
cover.Type = metaData.FileExtensionType(data);
|
||||||
|
var defaultExtension = "." + cover.Type;
|
||||||
dirMgr.CreateDirectory(song);
|
dirMgr.CreateDirectory(song);
|
||||||
|
|
||||||
var segment = cover.GenerateFilename(0);
|
var segment = cover.GenerateFilename(0);
|
||||||
var imagePath = dirMgr.SongDirectory + segment + defaultExtension;
|
var imagePath = dirMgr.SongDirectory + segment + defaultExtension;
|
||||||
|
|
||||||
cover.ImagePath = imagePath;
|
cover.Directory = dirMgr.SongDirectory;
|
||||||
|
cover.Filename = segment + defaultExtension;
|
||||||
|
|
||||||
using (var fileStream = new FileStream(imagePath, FileMode.Create))
|
using (var fileStream = new FileStream(cover.ImagePath(), FileMode.Create))
|
||||||
{
|
{
|
||||||
data.CopyTo(fileStream);
|
data.CopyTo(fileStream);
|
||||||
}
|
}
|
||||||
@@ -152,9 +164,10 @@ public class CoverArtManager : BaseManager
|
|||||||
private void Initialize()
|
private void Initialize()
|
||||||
{
|
{
|
||||||
_coverArtContext = new CoverArtContext(_connectionString);
|
_coverArtContext = new CoverArtContext(_connectionString);
|
||||||
|
var path = DirectoryPaths.CoverArtDirectory + DirectoryPaths.CoverArtFilename;
|
||||||
|
|
||||||
if (System.IO.File.Exists(DirectoryPaths.CoverArtPath))
|
if (System.IO.File.Exists(path))
|
||||||
_stockCoverArt = File.ReadAllBytes(DirectoryPaths.CoverArtPath);
|
_stockCoverArt = File.ReadAllBytes(path);
|
||||||
|
|
||||||
if (!File.Exists(_rootCoverArtPath + "CoverArt.png"))
|
if (!File.Exists(_rootCoverArtPath + "CoverArt.png"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,6 +68,48 @@ public class MetadataRetriever
|
|||||||
_logger.Info($"Year: {song.Year}");
|
_logger.Info($"Year: {song.Year}");
|
||||||
_logger.Info($"Duration: {song.Duration}");
|
_logger.Info($"Duration: {song.Duration}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string CoverArtFileExtensionType(CoverArt cover)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Retrieving CoverArt file extension type");
|
||||||
|
|
||||||
|
using (var fileStream = System.IO.File.OpenRead(cover.ImagePath()))
|
||||||
|
{
|
||||||
|
var isRecognizableType = FileTypeChecker.FileTypeValidator.IsTypeRecognizable(fileStream);
|
||||||
|
|
||||||
|
if (!isRecognizableType)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileType = FileTypeChecker.FileTypeValidator.GetFileType(fileStream);
|
||||||
|
|
||||||
|
Console.WriteLine($"Filetype: {fileType}");
|
||||||
|
|
||||||
|
return fileType.Extension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string FileExtensionType(IFormFile file)
|
||||||
|
{
|
||||||
|
using (var fileStream = file.OpenReadStream())
|
||||||
|
{
|
||||||
|
var isRecognizableType = FileTypeChecker.FileTypeValidator.IsTypeRecognizable(fileStream);
|
||||||
|
|
||||||
|
if (!isRecognizableType)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var fileType = FileTypeChecker.FileTypeValidator.GetFileType(fileStream);
|
||||||
|
Console.WriteLine($"Filetype: {fileType}");
|
||||||
|
Console.WriteLine($"Extension: {fileType.Extension}");
|
||||||
|
|
||||||
|
return fileType.Extension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Song RetrieveMetaData(string filePath)
|
public Song RetrieveMetaData(string filePath)
|
||||||
{
|
{
|
||||||
Song song = new Song();
|
Song song = new Song();
|
||||||
@@ -162,7 +204,7 @@ public class MetadataRetriever
|
|||||||
var pics = tag.Tag.Pictures;
|
var pics = tag.Tag.Pictures;
|
||||||
Array.Resize(ref pics, 1);
|
Array.Resize(ref pics, 1);
|
||||||
|
|
||||||
pics[0] = new Picture(coverArt.ImagePath)
|
pics[0] = new Picture(coverArt.ImagePath())
|
||||||
{
|
{
|
||||||
Description = "Cover Art"
|
Description = "Cover Art"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class CoverArtController : BaseController
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Found cover art record");
|
_logger.LogInformation("Found cover art record");
|
||||||
var coverArtBytes = System.IO.File.ReadAllBytes(
|
var coverArtBytes = System.IO.File.ReadAllBytes(
|
||||||
coverArt.ImagePath);
|
coverArt.ImagePath());
|
||||||
|
|
||||||
return File(coverArtBytes, "application/x-msdownload",
|
return File(coverArtBytes, "application/x-msdownload",
|
||||||
coverArt.SongTitle);
|
coverArt.SongTitle);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
|
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
|
||||||
<PackageReference Include="DotNetZip" Version="1.15.0" />
|
<PackageReference Include="DotNetZip" Version="1.15.0" />
|
||||||
<PackageReference Include="EntityFramework" Version="6.4.4" />
|
<PackageReference Include="EntityFramework" Version="6.4.4" />
|
||||||
|
<PackageReference Include="File.TypeChecker" Version="4.1.1" />
|
||||||
<PackageReference Include="ID3" Version="0.6.0" />
|
<PackageReference Include="ID3" Version="0.6.0" />
|
||||||
<PackageReference Include="JWT" Version="10.1.1" />
|
<PackageReference Include="JWT" Version="10.1.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
|
||||||
|
|||||||
+20
-2
@@ -10,11 +10,29 @@ public class CoverArt
|
|||||||
[JsonProperty("title")]
|
[JsonProperty("title")]
|
||||||
public string SongTitle { get; set; }
|
public string SongTitle { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string ImagePath { get; set; }
|
public string Directory { get; set; }
|
||||||
|
[JsonProperty("filename")]
|
||||||
|
public string Filename { get; set; }
|
||||||
|
[JsonProperty("type")]
|
||||||
|
public string Type { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
public string ImagePath()
|
||||||
|
{
|
||||||
|
var fullPath = this.Directory;
|
||||||
|
|
||||||
|
if (fullPath[fullPath.Length -1] != '/')
|
||||||
|
{
|
||||||
|
fullPath += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath += Filename;
|
||||||
|
|
||||||
|
return fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
public string GenerateFilename(int flag)
|
public string GenerateFilename(int flag)
|
||||||
{
|
{
|
||||||
int length = Constants.DirectoryPaths.FILENAME_LENGTH;
|
int length = Constants.DirectoryPaths.FILENAME_LENGTH;
|
||||||
@@ -27,6 +45,6 @@ public class CoverArt
|
|||||||
return (flag == 0) ? filename : $"{filename}{extension}";
|
return (flag == 0) ? filename : $"{filename}{extension}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<byte[]> GetData() => await File.ReadAllBytesAsync(this.ImagePath);
|
public async Task<byte[]> GetData() => await File.ReadAllBytesAsync(this.ImagePath());
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Regular → Executable
+13
-12
@@ -1,27 +1,28 @@
|
|||||||
echo "Adding migrations..."
|
echo "Adding migrations..."
|
||||||
|
|
||||||
echo "Adding User migration"
|
echo "Adding User migration"
|
||||||
dotnet-ef migrations add User --context UserContext
|
~/.dotnet/tools/dotnet-ef migrations add User --context UserContext
|
||||||
echo "Adding Album migration"
|
echo "Adding Album migration"
|
||||||
dotnet-ef migrations add Album --context AlbumContext
|
~/.dotnet/tools/dotnet-ef migrations add Album --context AlbumContext
|
||||||
echo "Adding Artist migration"
|
echo "Adding Artist migration"
|
||||||
dotnet-ef migrations add Artist --context ArtistContext
|
~/.dotnet/tools/dotnet-ef migrations add Artist --context ArtistContext
|
||||||
echo "Adding Genre migration"
|
echo "Adding Genre migration"
|
||||||
dotnet-ef migrations add Genre --context GenreContext
|
~/.dotnet/tools/dotnet-ef migrations add Genre --context GenreContext
|
||||||
echo "Adding Cover art migration"
|
echo "Adding Cover art migration"
|
||||||
dotnet-ef migrations add CoverArt --context CoverArtContext
|
~/.dotnet/tools/dotnet-ef migrations add CoverArt --context CoverArtContext
|
||||||
echo "Adding Song migration"
|
echo "Adding Song migration"
|
||||||
dotnet-ef migrations add Song --context SongContext
|
~/.dotnet/tools/dotnet-ef migrations add Song --context SongContext
|
||||||
|
|
||||||
echo "Updating migrations.."
|
echo "Updating migrations.."
|
||||||
echo "Updating User migration"
|
echo "Updating User migration"
|
||||||
dotnet-ef database update --context UserContext
|
~/.dotnet/tools/dotnet-ef database update --context UserContext
|
||||||
echo "Updating Album migration"
|
echo "Updating Album migration"
|
||||||
dotnet-ef database update --context AlbumContext
|
~/.dotnet/tools/dotnet-ef database update --context AlbumContext
|
||||||
echo "Updating Artist migration"
|
echo "Updating Artist migration"
|
||||||
dotnet-ef database update --context ArtistContext
|
~/.dotnet/tools/dotnet-ef database update --context ArtistContext
|
||||||
echo "Updating Genre migration"
|
echo "Updating Genre migration"
|
||||||
dotnet-ef database update --context GenreContext
|
~/.dotnet/tools/dotnet-ef database update --context GenreContext
|
||||||
echo "Updating Cover art migration"
|
echo "Updating Cover art migration"
|
||||||
dotnet-ef database update --context CoverArtContext
|
~/.dotnet/tools/dotnet-ef database update --context CoverArtContext
|
||||||
echo "Updating Song migration"
|
echo "Updating Song migration"
|
||||||
dotnet-ef database update --context SongContext
|
~/.dotnet/tools/dotnet-ef database update --context SongContext
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
delete from Song;
|
|
||||||
delete from Album;
|
delete from Album;
|
||||||
delete from Artist;
|
delete from Artist;
|
||||||
|
delete from CoverArt;
|
||||||
delete from Genre;
|
delete from Genre;
|
||||||
delete from CoverArt;
|
delete from CoverArt;
|
||||||
|
delete from Song;
|
||||||
|
delete from User;
|
||||||
|
|||||||
Reference in New Issue
Block a user