#93: Add flac support (#101)

* Added script shell to convert wav files to flac

* #93: Minor change to script to convert wav files to flac

* #93: Added more code to for the music file conversion

* #93: Script to convert wav files to flac files is done

* #93: Clean up

* #93: Starting work to implement flac support

* #93: Minor update to conversion script

* #93: Added dotnet manifest file

Includes the dotnet-ef tool

* #93: Updated README and migration script

* #93: Created skeleton for saving flac files

* #93: Making some changes to how the file extension is determined

* #93: Updated gitignore

* #93: Another gitignore update

* #93: Making some changes to the process of saving a song to the filesystem

* #93: Adding SQL script to drop and create database

* #93: Saving uploaded song to a temporary location for processing

* #93: Initializing some properties in the song model earlier

* #93: Uploading wav songs works. Moving on to flac support

* #93: Added more code to save flac files

* #93: Updated some code that affects filename generation for audio files

* #93: Song Model changes and support for different file types

* #93: Working on build errors, removed DotnetZip dependency, and added new Ionic.Zlip.Netstandard dependency

* #93: Reduce build errors

* #93: Removed ID3 dependency

* #93: Cleanup
This commit was merged in pull request #101.
This commit is contained in:
KD
2024-07-27 13:19:12 -04:00
committed by GitHub
parent 4b3fa78336
commit 8900afdfd2
50 changed files with 787 additions and 493 deletions
+4 -2
View File
@@ -6,16 +6,18 @@ namespace Icarus.Models;
public class Album
{
#region Properties
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
public string? Title { get; set; }
[JsonProperty("album_artist")]
[Column("Artist")]
public string AlbumArtist { get; set; }
public string? AlbumArtist { get; set; }
[JsonProperty("song_count")]
[NotMapped]
public int SongCount { get; set; }
[JsonProperty("year")]
public int Year { get; set; }
#endregion
}
+3 -1
View File
@@ -6,12 +6,14 @@ namespace Icarus.Models;
public class Artist
{
#region Properties
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
[Column("Artist")]
public string Name { get; set; }
public string? Name { get; set; }
[JsonProperty("song_count")]
[NotMapped]
public int SongCount { get; set; }
#endregion
}
+1 -1
View File
@@ -5,5 +5,5 @@ namespace Icarus.Models;
public class BaseResult
{
[JsonProperty("message")]
public string Message { get; set; }
public string? Message { get; set; }
}
+5 -5
View File
@@ -8,13 +8,13 @@ public class CoverArt
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("title")]
public string SongTitle { get; set; }
public string? SongTitle { get; set; }
[JsonIgnore]
public string Directory { get; set; }
public string? Directory { get; set; }
[JsonProperty("filename")]
public string Filename { get; set; }
public string? Filename { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
public string? Type { get; set; }
#endregion
@@ -23,7 +23,7 @@ public class CoverArt
{
var fullPath = this.Directory;
if (fullPath[fullPath.Length -1] != '/')
if (fullPath![fullPath.Length -1] != '/')
{
fullPath += "/";
}
+3 -1
View File
@@ -6,12 +6,14 @@ namespace Icarus.Models;
public class Genre
{
#region Properties
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("genre")]
[Column("Category")]
public string GenreName { get; set; }
public string? GenreName { get; set; }
[JsonProperty("song_count")]
[NotMapped]
public int SongCount { get; set; }
#endregion
}
+5 -3
View File
@@ -4,14 +4,16 @@ namespace Icarus.Models;
public class LoginResult : BaseResult
{
#region Properties
[JsonProperty("user_id")]
public int UserId { get; set; }
[JsonProperty("username")]
public string Username { get; set; }
public string? Username { get; set; }
[JsonProperty("token")]
public string Token { get; set; }
public string? Token { get; set; }
[JsonProperty("token_type")]
public string TokenType { get; set; }
public string? TokenType { get; set; }
[JsonProperty("expiration")]
public int Expiration { get; set; }
#endregion
}
+3 -1
View File
@@ -4,8 +4,10 @@ namespace Icarus.Models;
public class RegisterResult : BaseResult
{
#region Properties
[JsonProperty("username")]
public string Username { get; set; }
public string? Username { get; set; }
[JsonProperty("successfully_registered")]
public bool SuccessfullyRegistered { get; set; }
#endregion
}
+56 -14
View File
@@ -10,24 +10,26 @@ public class Song
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
public string? Title { get; set; }
[JsonProperty("album")]
[Column("Album")]
public string AlbumTitle { get; set; }
public string? AlbumTitle { get; set; }
[JsonProperty("artist")]
public string Artist { get; set; }
public string? Artist { get; set; }
[JsonProperty("album_artist")]
public string AlbumArtist { get; set; }
public string? AlbumArtist { get; set; }
[JsonProperty("year")]
public int? Year { get; set; }
[JsonProperty("genre")]
public string Genre { get; set; }
public string? Genre { get; set; }
[JsonProperty("duration")]
public int Duration { get; set; }
[JsonProperty("filename")]
public string Filename { get; set; }
public string? Filename { get; set; }
[JsonIgnore]
public string SongDirectory { get; set; }
public string? SongDirectory { get; set; }
[JsonProperty("audio_type")]
public string? AudioType { get; set; }
[JsonProperty("track")]
public int Track { get; set; } = 0;
[JsonProperty("track_count")]
@@ -56,11 +58,29 @@ public class Song
#region Methods
public void PrintMetadata()
{
Console.WriteLine("\n\nMetadata of the song:");
Console.WriteLine($"ID: {this.Id}");
Console.WriteLine($"Title: {this.Title}");
Console.WriteLine($"Artist: {this.Artist}");
Console.WriteLine($"Album: {this.AlbumTitle}");
Console.WriteLine($"Genre: {this.Genre}");
Console.WriteLine($"Year: {this.Year}");
Console.WriteLine($"Duration: {this.Duration}");
Console.WriteLine($"AlbumID: {this.AlbumId}");
Console.WriteLine($"ArtistID: {this.ArtistId}");
Console.WriteLine($"GenreID: {this.GenreId}");
Console.WriteLine($"Song Path: {this.SongPath()}");
Console.WriteLine($"Filename: {this.Filename}");
Console.WriteLine("\n");
}
public string SongPath()
{
var fullPath = SongDirectory;
if (fullPath[fullPath.Length -1] != '/')
if (fullPath![fullPath.Length -1] != '/')
{
fullPath += "/";
}
@@ -70,26 +90,41 @@ public class Song
return fullPath;
}
public string GenerateFilename(int flag = 0)
public string GenerateFilename(bool includeExtension = false, AudioFileExtensionsType flag = AudioFileExtensionsType.Default)
{
int length = Constants.DirectoryPaths.FILENAME_LENGTH;
string chars = Constants.DirectoryPaths.FILENAME_CHARACTERS;
var filename = this.Generate(length, chars);
var extension = Icarus.Constants.FileExtensions.WAV_EXTENSION;
var extension = this.DetermineFileExtension(flag);
return flag == 0 ? filename : $"{filename}{extension}";
return includeExtension ? $"{filename}{extension}" : filename;
}
public async Task<string> GenerateFilenameAsync(int flag = 0)
public async Task<string> GenerateFilenameAsync(bool includeExtension = false, AudioFileExtensionsType flag = AudioFileExtensionsType.Default)
{
int length = Constants.DirectoryPaths.FILENAME_LENGTH;
string chars = Constants.DirectoryPaths.FILENAME_CHARACTERS;
var extension = Icarus.Constants.FileExtensions.WAV_EXTENSION;
var extension = this.DetermineFileExtension(flag);
var filename = await Task.Run(() =>
{
return this.Generate(length, chars);
});
return flag == 0 ? filename : $"{filename}{extension}";
return includeExtension ? $"{filename}{extension}" : filename;
}
private string DetermineFileExtension(AudioFileExtensionsType flag)
{
switch (flag)
{
case AudioFileExtensionsType.Default:
return Constants.FileExtensions.DEFAULT_AUDIO_EXTENSION;
case AudioFileExtensionsType.WAV:
return Constants.FileExtensions.WAV_EXTENSION;
case AudioFileExtensionsType.FLAC:
return Constants.FileExtensions.FLAC_EXTENSION;
default:
return "";
}
}
private string Generate(int length, string chars)
@@ -101,3 +136,10 @@ public class Song
}
#endregion
}
public enum AudioFileExtensionsType
{
Default = 0,
WAV = 1,
FLAC = 2
}
+3 -1
View File
@@ -2,7 +2,9 @@ namespace Icarus.Models;
public class SongData
{
#region Properties
public int ID { get; set; }
public byte[] Data { get; set; }
public byte[]? Data { get; set; }
public int SongID { get; set; }
#endregion
}
+4 -2
View File
@@ -4,8 +4,10 @@ namespace Icarus.Models;
public class SongResult
{
#region Properties
[JsonProperty("message")]
public string Message { get; set; }
public string? Message { get; set; }
[JsonProperty("song_title")]
public string SongTitle { get; set; }
public string? SongTitle { get; set; }
#endregion
}
+6 -14
View File
@@ -1,6 +1,3 @@
using System;
using System.Linq;
using Newtonsoft.Json;
@@ -10,13 +7,13 @@ public class Token
{
#region Properties
[JsonProperty("scope")]
public string Scope { get; set; }
public string? Scope { get; set; }
[JsonProperty("exp")]
public int Expiration { get; set; }
[JsonProperty("aud")]
public string Audience { get; set; }
public string? Audience { get; set; }
[JsonProperty("iss")]
public string Issuer { get; set; }
public string? Issuer { get; set; }
[JsonProperty("iat")]
public int Issued { get; set; }
#endregion
@@ -24,29 +21,24 @@ public class Token
#region Methods
public bool TokenExpired()
{
var result = false;
var currentDate = DateTime.Now;
var currentDateInSeconds = Math.Floor((currentDate - DateTime.UnixEpoch).TotalSeconds);
result = (currentDateInSeconds >= Expiration) ? true : false;
var result = (currentDateInSeconds >= Expiration) ? true : false;
return result;
}
public bool ContainsScope(string desiredScope)
{
var result = false;
result = Scope.Contains(desiredScope);
var result = Scope!.Contains(desiredScope);
return result;
}
public bool Erroneous()
{
var result = true;
Func<string, bool> isEmpty = a => string.IsNullOrEmpty(a);
result = (!isEmpty(Scope) && !isEmpty(Audience) && !isEmpty(Issuer) &&
var result = (!isEmpty(Scope!) && !isEmpty(Audience!) && !isEmpty(Issuer!) &&
Expiration > 0 && Issued > 0) ? false : true;
return result;
+10 -10
View File
@@ -14,39 +14,39 @@ public class User
[Key]
public int Id { get; set; }
[JsonProperty("username")]
public string Username { get; set; }
public string? Username { get; set; }
[JsonProperty("password")]
public string Password { get; set; }
public string? Password { get; set; }
[JsonProperty("email")]
public string Email { get; set; }
public string? Email { get; set; }
[JsonProperty("phone")]
[Column("Phone")]
public string Phone { get; set; }
public string? Phone { get; set; }
[JsonProperty("firstname")]
public string Firstname { get; set; }
public string? Firstname { get; set; }
[JsonProperty("lastname")]
public string Lastname { get; set; }
public string? Lastname { get; set; }
[JsonProperty("email_verified")]
[NotMapped]
public bool EmailVerified { get; set; }
[JsonProperty("date_created")]
public DateTime DateCreated { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
public string? Status { get; set; }
[JsonProperty("last_login")]
public DateTime? LastLogin { get; set; }
[JsonIgnore]
[NotMapped]
public System.Collections.Generic.IEnumerable<string> Roles { get; set; }
public System.Collections.Generic.IEnumerable<string>? Roles { get; set; }
#endregion
#region Methods
public System.Collections.Generic.IEnumerable<System.Security.Claims.Claim> Claims()
{
var claims = new System.Collections.Generic.List<System.Security.Claims.Claim> { new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Name, Username) };
claims.AddRange(Roles.Select(role => new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, role)));
var claims = new System.Collections.Generic.List<System.Security.Claims.Claim> { new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Name, Username!) };
claims.AddRange(Roles!.Select(role => new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, role)));
return claims;
}