8900afdfd2
* 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
146 lines
4.4 KiB
C#
146 lines
4.4 KiB
C#
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Icarus.Models;
|
|
|
|
public class Song
|
|
{
|
|
#region Properties
|
|
[JsonProperty("id")]
|
|
public int Id { get; set; }
|
|
[JsonProperty("title")]
|
|
public string? Title { get; set; }
|
|
[JsonProperty("album")]
|
|
[Column("Album")]
|
|
public string? AlbumTitle { get; set; }
|
|
[JsonProperty("artist")]
|
|
public string? Artist { get; set; }
|
|
[JsonProperty("album_artist")]
|
|
public string? AlbumArtist { get; set; }
|
|
[JsonProperty("year")]
|
|
public int? Year { get; set; }
|
|
[JsonProperty("genre")]
|
|
public string? Genre { get; set; }
|
|
[JsonProperty("duration")]
|
|
public int Duration { get; set; }
|
|
[JsonProperty("filename")]
|
|
public string? Filename { get; set; }
|
|
[JsonIgnore]
|
|
public string? SongDirectory { get; set; }
|
|
[JsonProperty("audio_type")]
|
|
public string? AudioType { get; set; }
|
|
[JsonProperty("track")]
|
|
public int Track { get; set; } = 0;
|
|
[JsonProperty("track_count")]
|
|
public int TrackCount { get; set; } = 0;
|
|
[JsonProperty("disc")]
|
|
public int Disc { get; set; } = 0;
|
|
[JsonProperty("disc_count")]
|
|
public int DiscCount { get; set; } = 0;
|
|
[JsonIgnore]
|
|
public int? AlbumId { get; set; }
|
|
[JsonIgnore]
|
|
public int? ArtistId { get; set; }
|
|
[JsonIgnore]
|
|
public int? GenreId { get; set; }
|
|
[JsonIgnore]
|
|
public int? CoverArtId { get; set; }
|
|
[JsonProperty("date_created")]
|
|
public DateTime DateCreated { get; set; }
|
|
[JsonProperty("user_id")]
|
|
public int UserId { get; set; }
|
|
#endregion
|
|
|
|
|
|
#region Constructors
|
|
#endregion
|
|
|
|
|
|
#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] != '/')
|
|
{
|
|
fullPath += "/";
|
|
}
|
|
|
|
fullPath += Filename;
|
|
|
|
return fullPath;
|
|
}
|
|
|
|
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 = this.DetermineFileExtension(flag);
|
|
|
|
return includeExtension ? $"{filename}{extension}" : filename;
|
|
}
|
|
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 = this.DetermineFileExtension(flag);
|
|
var filename = await Task.Run(() =>
|
|
{
|
|
return this.Generate(length, chars);
|
|
});
|
|
|
|
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)
|
|
{
|
|
var random = new Random();
|
|
var filename = new string(Enumerable.Repeat(chars, length).Select(s =>
|
|
s[random.Next(s.Length)]).ToArray());
|
|
return filename;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
public enum AudioFileExtensionsType
|
|
{
|
|
Default = 0,
|
|
WAV = 1,
|
|
FLAC = 2
|
|
}
|