Skip to content

Commit

Permalink
Merge pull request #378 from NeoCoderMatrix86/development
Browse files Browse the repository at this point in the history
Deploy v6.0
  • Loading branch information
NeoCoderMatrix86 authored Jul 18, 2024
2 parents a524cd8 + bd0f1ac commit 69ce162
Show file tree
Hide file tree
Showing 52 changed files with 1,334 additions and 443 deletions.
28 changes: 23 additions & 5 deletions AudioCuesheetEditor/AudioCuesheetEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<PackageProjectUrl>https://github.com/NeoCoderMatrix86/AudioCuesheetEditor</PackageProjectUrl>
<RazorLangVersion>3.0</RazorLangVersion>
<Version>5.0.0</Version>
<Version>6.0.0</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<PublishTrimmed>true</PublishTrimmed>
<RunAOTCompilation>true</RunAOTCompilation>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
</PropertyGroup>

<ItemGroup>
Expand All @@ -26,6 +27,8 @@
<Content Remove="Resources\Localization\EditSections\en.json" />
<Content Remove="Resources\Localization\EditTrackModal\de.json" />
<Content Remove="Resources\Localization\EditTrackModal\en.json" />
<Content Remove="Resources\Localization\ImportFileView\de.json" />
<Content Remove="Resources\Localization\ImportFileView\en.json" />
<Content Remove="Resources\Localization\MainLayout\de.json" />
<Content Remove="Resources\Localization\MainLayout\en.json" />
<Content Remove="Resources\Localization\ModalDialog\de.json" />
Expand All @@ -34,6 +37,10 @@
<Content Remove="Resources\Localization\ModalExportdialog\en.json" />
<Content Remove="Resources\Localization\OptionsDialog\de.json" />
<Content Remove="Resources\Localization\OptionsDialog\en.json" />
<Content Remove="Resources\Localization\RecordControl\de.json" />
<Content Remove="Resources\Localization\RecordControl\en.json" />
<Content Remove="Resources\Localization\EditRecordOptions\de.json" />
<Content Remove="Resources\Localization\EditRecordOptions\en.json" />
<Content Remove="Resources\Localization\TracksTable\de.json" />
<Content Remove="Resources\Localization\TracksTable\en.json" />
<Content Remove="Resources\Localization\CultureSelector\de.json" />
Expand Down Expand Up @@ -65,6 +72,8 @@
<EmbeddedResource Include="Resources\Localization\EditSections\en.json" />
<EmbeddedResource Include="Resources\Localization\EditTrackModal\de.json" />
<EmbeddedResource Include="Resources\Localization\EditTrackModal\en.json" />
<EmbeddedResource Include="Resources\Localization\ImportFileView\de.json" />
<EmbeddedResource Include="Resources\Localization\ImportFileView\en.json" />
<EmbeddedResource Include="Resources\Localization\MainLayout\en.json" />
<EmbeddedResource Include="Resources\Localization\MainLayout\de.json" />
<EmbeddedResource Include="Resources\Localization\ModalDialog\en.json" />
Expand All @@ -73,6 +82,10 @@
<EmbeddedResource Include="Resources\Localization\ModalExportdialog\en.json" />
<EmbeddedResource Include="Resources\Localization\OptionsDialog\de.json" />
<EmbeddedResource Include="Resources\Localization\OptionsDialog\en.json" />
<EmbeddedResource Include="Resources\Localization\RecordControl\de.json" />
<EmbeddedResource Include="Resources\Localization\RecordControl\en.json" />
<EmbeddedResource Include="Resources\Localization\EditRecordOptions\de.json" />
<EmbeddedResource Include="Resources\Localization\EditRecordOptions\en.json" />
<EmbeddedResource Include="Resources\Localization\TracksTable\de.json" />
<EmbeddedResource Include="Resources\Localization\TracksTable\en.json" />
<EmbeddedResource Include="Resources\Localization\CultureSelector\de.json" />
Expand All @@ -98,18 +111,23 @@

<ItemGroup>
<PackageReference Include="Blazorise.Bootstrap5" Version="1.5.2" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.5.2" />
<PackageReference Include="MetaBrainz.MusicBrainz" Version="6.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.7" PrivateAssets="all" />
<PackageReference Include="BlazorDownloadFile" Version="2.4.0.2" />
<PackageReference Include="Blazorise.Components" Version="1.5.2" />
<PackageReference Include="Howler.Blazor" Version="0.9.8" />
<PackageReference Include="Markdig" Version="0.37.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
<PackageReference Include="Toolbelt.Blazor.HotKeys2" Version="4.1.0.1" />
<PackageReference Include="z440.atl.core" Version="5.22.0" />
<PackageReference Include="Toolbelt.Blazor.HotKeys2" Version="5.1.0" />
<PackageReference Include="z440.atl.core" Version="5.25.0" />
</ItemGroup>

<ItemGroup>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>

</Project>
68 changes: 50 additions & 18 deletions AudioCuesheetEditor/Data/Options/LocalStorageOptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.Options;
using Microsoft.JSInterop;
using System.Linq.Expressions;
using System.Reflection;
using System.Text.Json;

namespace AudioCuesheetEditor.Data.Options
{
public class LocalStorageOptionsProvider
public class LocalStorageOptionsProvider(IJSRuntime jsRuntime)
{
public event EventHandler<IOptions>? OptionSaved;

private readonly IJSRuntime _jsRuntime;
private readonly IJSRuntime _jsRuntime = jsRuntime;

public LocalStorageOptionsProvider(IJSRuntime jsRuntime)
private readonly JsonSerializerOptions SerializerOptions = new()
{
if (jsRuntime is null)
{
throw new ArgumentNullException(nameof(jsRuntime));
}

_jsRuntime = jsRuntime;
}
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
};

public async Task<T> GetOptions<T>() where T : IOptions
{
Expand Down Expand Up @@ -65,17 +63,51 @@ public async Task<T> GetOptions<T>() where T : IOptions

public async Task SaveOptions(IOptions options)
{
if (options == null)
var optionsJson = JsonSerializer.Serialize<object>(options, SerializerOptions);
await _jsRuntime.InvokeVoidAsync(String.Format("{0}.set", options.GetType().Name), optionsJson);
OptionSaved?.Invoke(this, options);
}

public async Task SaveOptionsValue<T>(Expression<Func<T, object>> propertyExpression, object value) where T : class, IOptions, new()
{
var options = await GetOptions<T>();
if (propertyExpression.Body is MemberExpression memberExpression)
{
throw new ArgumentNullException(nameof(options));
var propertyInfo = memberExpression.Member as PropertyInfo;
if (propertyInfo != null)
{
propertyInfo.SetValue(options, Convert.ChangeType(value, propertyInfo.PropertyType));
}
else
{
throw new ArgumentException("The provided expression does not reference a valid property.");
}
}
var serializerOptions = new JsonSerializerOptions
else if (propertyExpression.Body is UnaryExpression unaryExpression && unaryExpression.Operand is MemberExpression unaryMemberExpression)
{
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
};
var optionsJson = JsonSerializer.Serialize<object>(options, serializerOptions);
await _jsRuntime.InvokeVoidAsync(String.Format("{0}.set", options.GetType().Name), optionsJson);
OptionSaved?.Invoke(this, options);
var propertyInfo = unaryMemberExpression.Member as PropertyInfo;
if (propertyInfo != null)
{
propertyInfo.SetValue(options, Convert.ChangeType(value, propertyInfo.PropertyType));
}
else
{
throw new ArgumentException("The provided expression does not reference a valid property.");
}
}
else
{
throw new ArgumentException("The provided expression does not reference a valid property.");
}
Boolean saveOptions = true;
if (options is IValidateable<T> validateable)
{
saveOptions = validateable.Validate(propertyExpression).Status != ValidationStatus.Error;
}
if (saveOptions)
{
await SaveOptions(options);
}
}
}
}
111 changes: 67 additions & 44 deletions AudioCuesheetEditor/Data/Services/MusicBrainzDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,91 +36,114 @@ public class MusicBrainzTrack
public TimeSpan? Length { get; init; }
public String? Disambiguation { get; init; }
}
public class MusicBrainzDataProvider
public class MusicBrainzDataProvider(ILogger<MusicBrainzDataProvider> logger)
{
private readonly ILogger<MusicBrainzDataProvider> _logger = logger;

public const String Application = "AudioCuesheetEditor";
public const String ProjectUrl = "https://github.com/NeoCoderMatrix86/AudioCuesheetEditor";

private String? applicationVersion = null;

public async Task<IReadOnlyCollection<MusicBrainzArtist>> SearchArtistAsync(String searchString)
{
List<MusicBrainzArtist> artistSearchResult = new();
if (String.IsNullOrEmpty(searchString) == false)
List<MusicBrainzArtist> artistSearchResult = [];
try
{
if (String.IsNullOrEmpty(searchString) == false)
{
using var query = new Query(Application, ApplicationVersion, ProjectUrl);
var findArtistsResult = await query.FindArtistsAsync(searchString, simple: true);
artistSearchResult = findArtistsResult.Results.ToList().ConvertAll(x => new MusicBrainzArtist() { Id = x.Item.Id, Name = x.Item.Name, Disambiguation = x.Item.Disambiguation });
}
}
catch (HttpRequestException hre)
{
using var query = new Query(Application, ApplicationVersion, ProjectUrl);
var findArtistsResult = await query.FindArtistsAsync(searchString, simple: true);
artistSearchResult = findArtistsResult.Results.ToList().ConvertAll(x => new MusicBrainzArtist() { Id = x.Item.Id, Name = x.Item.Name, Disambiguation = x.Item.Disambiguation });
_logger.LogError(hre, "Error getting response from MusicBrainz");
}
return artistSearchResult.AsReadOnly();
}

public async Task<IReadOnlyCollection<MusicBrainzTrack>> SearchTitleAsync(String searchString, String? artist = null)
{
List<MusicBrainzTrack> titleSearchResult = new();
if (String.IsNullOrEmpty(searchString) == false)
List<MusicBrainzTrack> titleSearchResult = [];
try
{
using var query = new Query(Application, ApplicationVersion, ProjectUrl);
ISearchResults<ISearchResult<IRecording>> findRecordingsResult;
if (String.IsNullOrEmpty(artist))
if (String.IsNullOrEmpty(searchString) == false)
{
findRecordingsResult = await query.FindRecordingsAsync(searchString, simple: true);
}
else
{
findRecordingsResult = await query.FindRecordingsAsync(String.Format("{0} AND artistname:{1}", searchString, artist));
}
foreach (var result in findRecordingsResult.Results)
{
String artistString = String.Empty;
if (result.Item.ArtistCredit != null)
using var query = new Query(Application, ApplicationVersion, ProjectUrl);
ISearchResults<ISearchResult<IRecording>> findRecordingsResult;
if (String.IsNullOrEmpty(artist))
{
foreach (var artistCredit in result.Item.ArtistCredit)
findRecordingsResult = await query.FindRecordingsAsync(searchString, simple: true);
}
else
{
findRecordingsResult = await query.FindRecordingsAsync(String.Format("{0} AND artistname:{1}", searchString, artist));
}
foreach (var result in findRecordingsResult.Results)
{
String artistString = String.Empty;
if (result.Item.ArtistCredit != null)
{
artistString += artistCredit.Name;
if (String.IsNullOrEmpty(artistCredit.JoinPhrase) == false)
foreach (var artistCredit in result.Item.ArtistCredit)
{
artistString += artistCredit.JoinPhrase;
artistString += artistCredit.Name;
if (String.IsNullOrEmpty(artistCredit.JoinPhrase) == false)
{
artistString += artistCredit.JoinPhrase;
}
}
}
titleSearchResult.Add(new MusicBrainzTrack()
{
Id = result.Item.Id,
Artist = artistString,
Title = result.Item.Title,
Length = result.Item.Length,
Disambiguation = result.Item.Disambiguation
});
}
titleSearchResult.Add(new MusicBrainzTrack()
{
Id = result.Item.Id,
Artist = artistString,
Title = result.Item.Title,
Length = result.Item.Length,
Disambiguation = result.Item.Disambiguation
});
}
}
catch(HttpRequestException hre)
{
_logger.LogError(hre, "Error getting response from MusicBrainz");
}
return titleSearchResult.AsReadOnly();
}

public async Task<MusicBrainzTrack?> GetDetailsAsync(Guid id)
{
MusicBrainzTrack? track = null;
if (id != Guid.Empty)
try
{
var query = new Query(Application, ApplicationVersion, ProjectUrl);
var recording = await query.LookupRecordingAsync(id, Include.Artists);
if (recording != null)
if (id != Guid.Empty)
{
String artist = String.Empty;
if (recording.ArtistCredit != null)
var query = new Query(Application, ApplicationVersion, ProjectUrl);
var recording = await query.LookupRecordingAsync(id, Include.Artists);
if (recording != null)
{
foreach (var artistCredit in recording.ArtistCredit)
String artist = String.Empty;
if (recording.ArtistCredit != null)
{
artist += artistCredit.Name;
if (String.IsNullOrEmpty(artistCredit.JoinPhrase) == false)
foreach (var artistCredit in recording.ArtistCredit)
{
artist += artistCredit.JoinPhrase;
artist += artistCredit.Name;
if (String.IsNullOrEmpty(artistCredit.JoinPhrase) == false)
{
artist += artistCredit.JoinPhrase;
}
}
}
track = new MusicBrainzTrack() { Id = recording.Id, Title = recording.Title, Artist = artist, Length = recording.Length };
}
track = new MusicBrainzTrack() { Id = recording.Id, Title = recording.Title, Artist = artist, Length = recording.Length };
}
}
catch (HttpRequestException hre)
{
_logger.LogError(hre, "Error getting response from MusicBrainz");
}
return track;
}

Expand Down
33 changes: 33 additions & 0 deletions AudioCuesheetEditor/Extensions/SessionStateContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ public CuesheetImportfile? CuesheetImportFile
get { return cuesheetImportFile; }
set
{
if (cuesheetImportFile != null)
{
cuesheetImportFile.AnalysisFinished -= CuesheetImportFile_AnalysisFinished;
}
cuesheetImportFile = value;
if ((CuesheetImportFile != null) && (CuesheetImportFile.Cuesheet != null))
{
CuesheetImportFile.AnalysisFinished += CuesheetImportFile_AnalysisFinished;
ImportCuesheet = CuesheetImportFile.Cuesheet;
}
else
Expand Down Expand Up @@ -128,6 +133,22 @@ public ViewMode CurrentViewMode
}
}

public IImportfile? Importfile
{
get
{
if (TextImportFile != null)
{
return TextImportFile;
}
if (CuesheetImportFile != null)
{
return CuesheetImportFile;
}
return null;
}
}

public void ResetImport()
{
TextImportFile = null;
Expand Down Expand Up @@ -169,5 +190,17 @@ private void Cuesheet_CuesheetImported(object? sender, EventArgs e)
{
CuesheetChanged?.Invoke(this, EventArgs.Empty);
}

void CuesheetImportFile_AnalysisFinished(object? sender, EventArgs e)
{
if (CuesheetImportFile != null)
{
ImportCuesheet = CuesheetImportFile.Cuesheet;
}
else
{
ImportCuesheet = null;
}
}
}
}
Loading

0 comments on commit 69ce162

Please sign in to comment.