#95: Id changes to models #99
@@ -2,8 +2,8 @@ namespace Icarus.Constants;
|
||||
|
||||
public class DirectoryPaths
|
||||
{
|
||||
public static string CoverArtPath =>
|
||||
Directory.GetCurrentDirectory() + "/Images/Stock/CoverArt.png";
|
||||
public static string CoverArtDirectory => Directory.GetCurrentDirectory() + "/Images/Stock/";
|
||||
public static string CoverArtFilename => "CoverArt.png";
|
||||
public static string FILENAME_CHARACTERS = "ABCDEF0123456789";
|
||||
public static int FILENAME_LENGTH = 25;
|
||||
}
|
||||
|
||||
@@ -47,11 +47,11 @@ public class CoverArtManager : BaseManager
|
||||
try
|
||||
{
|
||||
var stockCoverArtPath = _rootCoverArtPath + "CoverArt.png";
|
||||
if (!string.Equals(stockCoverArtPath, coverArt.ImagePath,
|
||||
if (!string.Equals(stockCoverArtPath, coverArt.ImagePath(),
|
||||
StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
_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");
|
||||
}
|
||||
else
|
||||
@@ -81,9 +81,8 @@ public class CoverArtManager : BaseManager
|
||||
};
|
||||
|
||||
var segment = coverArt.GenerateFilename(0);
|
||||
var imagePath = dirMgr.SongDirectory + segment + defaultExtension;
|
||||
|
||||
coverArt.ImagePath = imagePath;
|
||||
coverArt.Directory = dirMgr.SongDirectory;
|
||||
coverArt.Filename = segment + defaultExtension;
|
||||
|
||||
var metaData = new MetadataRetriever();
|
||||
var imgBytes = metaData.RetrieveCoverArtBytes(song);
|
||||
@@ -91,17 +90,27 @@ public class CoverArtManager : BaseManager
|
||||
if (imgBytes != null)
|
||||
{
|
||||
_logger.Info("Saving cover art to the filesystem");
|
||||
File.WriteAllBytes(coverArt.ImagePath, imgBytes);
|
||||
File.WriteAllBytes(coverArt.ImagePath(), imgBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Info("Song has no cover art, applying stock cover art");
|
||||
|
||||
var coverArtFilePath = _rootCoverArtPath + $"{segment}{defaultExtension}";
|
||||
coverArt.ImagePath = DirectoryPaths.CoverArtPath;
|
||||
coverArt.Directory = DirectoryPaths.CoverArtDirectory;
|
||||
coverArt.Filename = DirectoryPaths.CoverArtFilename;
|
||||
metaData.UpdateCoverArt(song, coverArt);
|
||||
coverArt.ImagePath = coverArtFilePath;
|
||||
File.WriteAllBytes(coverArt.ImagePath, _stockCoverArt);
|
||||
coverArt.Directory = this._rootCoverArtPath;
|
||||
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;
|
||||
@@ -121,16 +130,19 @@ public class CoverArtManager : BaseManager
|
||||
|
||||
try
|
||||
{
|
||||
MetadataRetriever metaData = new MetadataRetriever();
|
||||
var dirMgr = new DirectoryManager(_rootCoverArtPath);
|
||||
var defaultExtension = ".png";
|
||||
cover.Type = metaData.FileExtensionType(data);
|
||||
var defaultExtension = "." + cover.Type;
|
||||
dirMgr.CreateDirectory(song);
|
||||
|
||||
var segment = cover.GenerateFilename(0);
|
||||
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);
|
||||
}
|
||||
@@ -151,9 +163,10 @@ public class CoverArtManager : BaseManager
|
||||
private void Initialize()
|
||||
{
|
||||
_coverArtContext = new CoverArtContext(_connectionString);
|
||||
var path = DirectoryPaths.CoverArtDirectory + DirectoryPaths.CoverArtFilename;
|
||||
|
||||
if (System.IO.File.Exists(DirectoryPaths.CoverArtPath))
|
||||
_stockCoverArt = File.ReadAllBytes(DirectoryPaths.CoverArtPath);
|
||||
if (System.IO.File.Exists(path))
|
||||
_stockCoverArt = File.ReadAllBytes(path);
|
||||
|
||||
if (!File.Exists(_rootCoverArtPath + "CoverArt.png"))
|
||||
{
|
||||
|
||||
@@ -64,6 +64,48 @@ public class MetadataRetriever
|
||||
_logger.Info($"Year: {song.Year}");
|
||||
_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)
|
||||
{
|
||||
Song song = new Song();
|
||||
@@ -158,7 +200,7 @@ public class MetadataRetriever
|
||||
var pics = tag.Tag.Pictures;
|
||||
Array.Resize(ref pics, 1);
|
||||
|
||||
pics[0] = new Picture(coverArt.ImagePath)
|
||||
pics[0] = new Picture(coverArt.ImagePath())
|
||||
{
|
||||
Description = "Cover Art"
|
||||
};
|
||||
|
||||
@@ -61,7 +61,7 @@ public class CoverArtController : BaseController
|
||||
{
|
||||
_logger.LogInformation("Found cover art record");
|
||||
var coverArtBytes = System.IO.File.ReadAllBytes(
|
||||
coverArt.ImagePath);
|
||||
coverArt.ImagePath());
|
||||
|
||||
return File(coverArtBytes, "application/x-msdownload",
|
||||
coverArt.SongTitle);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
|
||||
<PackageReference Include="DotNetZip" Version="1.15.0" />
|
||||
<PackageReference Include="EntityFramework" Version="6.4.4" />
|
||||
<PackageReference Include="File.TypeChecker" Version="4.1.1" />
|
||||
<PackageReference Include="ID3" Version="0.6.0" />
|
||||
<PackageReference Include="JWT" Version="10.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
|
||||
|
||||
+20
-2
@@ -10,11 +10,29 @@ public class CoverArt
|
||||
[JsonProperty("title")]
|
||||
public string SongTitle { get; set; }
|
||||
[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
|
||||
|
||||
|
||||
#region Methods
|
||||
public string ImagePath()
|
||||
{
|
||||
var fullPath = this.Directory;
|
||||
|
||||
if (fullPath[fullPath.Length -1] != '/')
|
||||
{
|
||||
fullPath += "/";
|
||||
}
|
||||
|
||||
fullPath += Filename;
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
public string GenerateFilename(int flag)
|
||||
{
|
||||
int length = Constants.DirectoryPaths.FILENAME_LENGTH;
|
||||
@@ -27,6 +45,6 @@ public class CoverArt
|
||||
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
|
||||
}
|
||||
|
||||
Regular → Executable
+15
-14
@@ -1,27 +1,28 @@
|
||||
echo "Adding migrations..."
|
||||
|
||||
echo "Adding User migration"
|
||||
dotnet-ef migrations add User --context UserContext
|
||||
~/.dotnet/tools/dotnet-ef migrations add User --context UserContext
|
||||
echo "Adding Album migration"
|
||||
dotnet-ef migrations add Album --context AlbumContext
|
||||
~/.dotnet/tools/dotnet-ef migrations add Album --context AlbumContext
|
||||
echo "Adding Artist migration"
|
||||
dotnet-ef migrations add Artist --context ArtistContext
|
||||
echo "Adding Cover art migration"
|
||||
dotnet-ef migrations add CoverArt --context CoverArtContext
|
||||
~/.dotnet/tools/dotnet-ef migrations add Artist --context ArtistContext
|
||||
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"
|
||||
~/.dotnet/tools/dotnet-ef migrations add CoverArt --context CoverArtContext
|
||||
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 User migration"
|
||||
dotnet-ef database update --context UserContext
|
||||
~/.dotnet/tools/dotnet-ef database update --context UserContext
|
||||
echo "Updating Album migration"
|
||||
dotnet-ef database update --context AlbumContext
|
||||
~/.dotnet/tools/dotnet-ef database update --context AlbumContext
|
||||
echo "Updating Artist migration"
|
||||
dotnet-ef database update --context ArtistContext
|
||||
echo "Updating Cover art migration"
|
||||
dotnet-ef database update --context CoverArtContext
|
||||
~/.dotnet/tools/dotnet-ef database update --context ArtistContext
|
||||
echo "Updating Genre migration"
|
||||
dotnet-ef database update --context GenreContext
|
||||
~/.dotnet/tools/dotnet-ef database update --context GenreContext
|
||||
echo "Updating Cover art migration"
|
||||
~/.dotnet/tools/dotnet-ef database update --context CoverArtContext
|
||||
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 Artist;
|
||||
delete from CoverArt;
|
||||
delete from Genre;
|
||||
delete from CoverArt;
|
||||
delete from Song;
|
||||
delete from User;
|
||||
|
||||
Reference in New Issue
Block a user