From 3a6a1ba630df3eb65906213d631fde036f1b0802 Mon Sep 17 00:00:00 2001 From: Steven Hildreth Date: Sun, 12 Apr 2020 15:01:45 -0500 Subject: [PATCH] Updated NuGet pacakges. --- Inspector/Inspector.csproj | 4 +- Inspector/PreInspectScript.ps1 | 4 +- Inspector/Properties/launchSettings.json | 2 +- .../Roadie.Library.Tests.csproj | 4 +- .../Engines/ArtistLookupEngine.cs | 154 +++++++++--------- .../Engines/IArtistLookupEngine.cs | 1 + .../Engines/LabelLookupEngine.cs | 10 +- .../Engines/LookupEngineBase.cs | 1 - .../Engines/ReleaseLookupEngine.cs | 122 ++++++++------ Roadie.Api.Library/FilePlugins/Audio.cs | 22 +-- Roadie.Api.Library/FilePlugins/PluginBase.cs | 1 - Roadie.Api.Library/Inspect/Inspector.cs | 2 +- .../Processors/FileProcessor.cs | 46 +++--- .../Processors/IFileProcessor.cs | 7 +- Roadie.Api.Library/Roadie.Library.csproj | 30 ++-- Roadie.Api.Services/ArtistService.cs | 6 +- Roadie.Api.Services/ReleaseService.cs | 6 +- .../Roadie.Api.Services.csproj | 6 +- Roadie.Api.Services/TrackService.cs | 4 +- Roadie.Api/LoggingTraceListener.cs | 35 ++++ Roadie.Api/Program.cs | 29 ---- Roadie.Api/Roadie.Api.csproj | 26 +-- 22 files changed, 271 insertions(+), 251 deletions(-) create mode 100644 Roadie.Api/LoggingTraceListener.cs diff --git a/Inspector/Inspector.csproj b/Inspector/Inspector.csproj index de2a1b1..72d4498 100644 --- a/Inspector/Inspector.csproj +++ b/Inspector/Inspector.csproj @@ -21,8 +21,8 @@ - - + + diff --git a/Inspector/PreInspectScript.ps1 b/Inspector/PreInspectScript.ps1 index d432676..284cefe 100644 --- a/Inspector/PreInspectScript.ps1 +++ b/Inspector/PreInspectScript.ps1 @@ -1,2 +1,2 @@ -gci -Path "N:\_complete" -r -include *.zip,*.rar,*.7z | foreach { & 'C:\Program Files\7-Zip\7z.exe' x $_.FullName -y -o"$('"'+$_.DirectoryName+'"')"} -Remove-Item –path N:\_complete -include *.7z,*.zip,*.rar -recurse \ No newline at end of file +gci -Path "G:\_complete" -r -include *.zip,*.rar,*.7z | foreach { & 'C:\Program Files\7-Zip\7z.exe' x $_.FullName -y -o"$('"'+$_.DirectoryName+'"')"} +Remove-Item –path G:\_complete -include *.7z,*.zip,*.rar -recurse \ No newline at end of file diff --git a/Inspector/Properties/launchSettings.json b/Inspector/Properties/launchSettings.json index b227ac7..1fc8ef5 100644 --- a/Inspector/Properties/launchSettings.json +++ b/Inspector/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Inspector": { "commandName": "Project", - "commandLineArgs": "-f \"N:\\_complete\" -d \"M:\\inbound\"" + "commandLineArgs": "-f \"G:\\_complete\\_\" -d \"M:\\inbound\"" } } } \ No newline at end of file diff --git a/Roadie.Api.Library.Tests/Roadie.Library.Tests.csproj b/Roadie.Api.Library.Tests/Roadie.Library.Tests.csproj index 9ad0f4d..5af2fb9 100644 --- a/Roadie.Api.Library.Tests/Roadie.Library.Tests.csproj +++ b/Roadie.Api.Library.Tests/Roadie.Library.Tests.csproj @@ -23,8 +23,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all diff --git a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs index 0477a36..17389ef 100644 --- a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs +++ b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs @@ -69,7 +69,7 @@ namespace Roadie.Library.Engines try { var artistGenreTables = artist.Genres; - var artistImages = artist.Images ?? new List(); + var artistImages = artist.Images ?? new List(); var now = DateTime.UtcNow; artist.AlternateNames = artist.AlternateNames.AddToDelimitedList(new[] { artist.Name.ToAlphanumericName() }); artist.Genres = null; @@ -82,45 +82,41 @@ namespace Roadie.Library.Engines }; } var addArtistResult = DbContext.Artists.Add(artist); - var inserted = 0; - inserted = await DbContext.SaveChangesAsync(); + var inserted = await DbContext.SaveChangesAsync().ConfigureAwait(false); _addedArtistIds.Add(artist.Id); if (artist.Id < 1 && addArtistResult.Entity.Id > 0) artist.Id = addArtistResult.Entity.Id; if (inserted > 0 && artist.Id > 0) { if (artistGenreTables != null) { - if (artistGenreTables != null) + foreach (var artistGenreTable in artistGenreTables.Where(x => x?.Genre?.Name != null).Select(x => x.Genre?.Name).Distinct()) { - foreach (var artistGenreTable in artistGenreTables.Where(x => x?.Genre?.Name != null).Select(x => x.Genre?.Name).Distinct()) + var genreName = artistGenreTable.ToAlphanumericName().ToTitleCase(); + var normalizedName = genreName.ToUpper(); + if (string.IsNullOrEmpty(genreName)) continue; + if (genreName.Length > 100) { - var genreName = artistGenreTable.ToAlphanumericName().ToTitleCase(); - var normalizedName = genreName.ToUpper(); - if (string.IsNullOrEmpty(genreName)) continue; - if (genreName.Length > 100) - { - var originalName = genreName; - genreName = genreName.Substring(0, 99); - Logger.LogWarning($"Genre Name Too long was [{originalName}] truncated to [{genreName}]"); - } - var genre = DbContext.Genres.FirstOrDefault(x => x.NormalizedName == normalizedName); - if (genre == null) - { - genre = new Genre - { - Name = genreName, - NormalizedName = normalizedName - }; - DbContext.Genres.Add(genre); - await DbContext.SaveChangesAsync(); - } - DbContext.ArtistGenres.Add(new ArtistGenre - { - ArtistId = artist.Id, - GenreId = genre.Id - }); - await DbContext.SaveChangesAsync(); + var originalName = genreName; + genreName = genreName.Substring(0, 99); + Logger.LogWarning($"Genre Name Too long was [{originalName}] truncated to [{genreName}]"); } + var genre = DbContext.Genres.FirstOrDefault(x => x.NormalizedName == normalizedName); + if (genre == null) + { + genre = new Genre + { + Name = genreName, + NormalizedName = normalizedName + }; + DbContext.Genres.Add(genre); + await DbContext.SaveChangesAsync().ConfigureAwait(false); + } + DbContext.ArtistGenres.Add(new ArtistGenre + { + ArtistId = artist.Id, + GenreId = genre.Id + }); + await DbContext.SaveChangesAsync().ConfigureAwait(false); } } @@ -131,7 +127,7 @@ namespace Roadie.Library.Engines string releaseImageFilename; foreach (var artistImage in artistImages) { - if (artistImage?.Bytes == null || artistImage?.Bytes.Any() == false) + if (!(artistImage?.Bytes.Length > 0)) { continue; } @@ -177,7 +173,6 @@ namespace Roadie.Library.Engines } try { - var searchName = name.NormalizeName().ToLower(); var searchSortName = !string.IsNullOrEmpty(sortName) ? sortName.NormalizeName().ToLower() : searchName; var specialSearchName = name.ToAlphanumericName(); @@ -191,21 +186,21 @@ namespace Roadie.Library.Engines var specialSearchNameEnd = $"|{specialSearchName}"; return await (from a in DbContext.Artists - where a.Name.ToLower() == searchName || - a.Name.ToLower() == specialSearchName || - a.SortName.ToLower() == searchName || - a.SortName.ToLower() == searchSortName || - a.SortName.ToLower() == specialSearchName || - a.AlternateNames.ToLower().Equals(searchName) || - a.AlternateNames.ToLower().StartsWith(searchNameStart) || - a.AlternateNames.ToLower().Contains(searchNameIn) || - a.AlternateNames.ToLower().EndsWith(searchNameEnd) || - a.AlternateNames.ToLower().Equals(specialSearchName) || - a.AlternateNames.ToLower().StartsWith(specialSearchNameStart) || - a.AlternateNames.ToLower().Contains(specialSearchNameIn) || - a.AlternateNames.ToLower().EndsWith(specialSearchNameEnd) - select a - ).ToArrayAsync(); + where a.Name.ToLower() == searchName || + a.Name.ToLower() == specialSearchName || + a.SortName.ToLower() == searchName || + a.SortName.ToLower() == searchSortName || + a.SortName.ToLower() == specialSearchName || + a.AlternateNames.ToLower().Equals(searchName) || + a.AlternateNames.ToLower().StartsWith(searchNameStart) || + a.AlternateNames.ToLower().Contains(searchNameIn) || + a.AlternateNames.ToLower().EndsWith(searchNameEnd) || + a.AlternateNames.ToLower().Equals(specialSearchName) || + a.AlternateNames.ToLower().StartsWith(specialSearchNameStart) || + a.AlternateNames.ToLower().Contains(specialSearchNameIn) || + a.AlternateNames.ToLower().EndsWith(specialSearchNameEnd) + select a + ).ToArrayAsync().ConfigureAwait(false); } catch (Exception ex) { @@ -236,9 +231,9 @@ namespace Roadie.Library.Engines }; } - var artist = (await DatabaseQueryForArtistName(artistName)).FirstOrDefault(); + var artist = (await DatabaseQueryForArtistName(artistName).ConfigureAwait(false)).FirstOrDefault(); sw.Stop(); - if (artist == null || !artist.IsValid) + if (artist?.IsValid != true) { Logger.LogTrace("ArtistLookupEngine: Artist Not Found By Name [{0}]", artistName); if (doFindIfNotInDatabase) @@ -257,7 +252,7 @@ namespace Roadie.Library.Engines if (!string.IsNullOrEmpty(releaseRoadieDataFilename) && File.Exists(releaseRoadieDataFilename)) { artist = JsonConvert.DeserializeObject(File.ReadAllText(releaseRoadieDataFilename)); - var addResult = await Add(artist); + var addResult = await Add(artist).ConfigureAwait(false); if (!addResult.IsSuccess) { sw.Stop(); @@ -267,7 +262,8 @@ namespace Roadie.Library.Engines OperationTime = sw.ElapsedMilliseconds, Errors = addResult.Errors }; - } else + } + else { File.Delete(releaseRoadieDataFilename); } @@ -277,20 +273,19 @@ namespace Roadie.Library.Engines { try { - artistSearch = await PerformMetaDataProvidersArtistSearch(metaData); + artistSearch = await PerformMetaDataProvidersArtistSearch(metaData).ConfigureAwait(false); if (artistSearch.IsSuccess) { artist = artistSearch.Data; // See if Artist already exist with either Name or Sort Name - var alreadyExists = (await DatabaseQueryForArtistName(artistSearch.Data.Name, artistSearch.Data.SortNameValue)).FirstOrDefault(); - if (alreadyExists == null || !alreadyExists.IsValid) + var alreadyExists = (await DatabaseQueryForArtistName(artistSearch.Data.Name, artistSearch.Data.SortNameValue).ConfigureAwait(false)).FirstOrDefault(); + if (alreadyExists?.IsValid != true) { - var addResult = await Add(artist); + var addResult = await Add(artist).ConfigureAwait(false); if (!addResult.IsSuccess) { sw.Stop(); - Logger.LogWarning("Unable To Add Artist For MetaData [{0}]", - metaData.ToString()); + Logger.LogWarning("Unable To Add Artist For MetaData [{0}]", metaData.ToString()); return new OperationResult { OperationTime = sw.ElapsedMilliseconds, @@ -314,7 +309,10 @@ namespace Roadie.Library.Engines } } - if (artist != null && artist.IsValid) CacheManager.Add(cacheKey, artist); + if (artist?.IsValid == true) + { + CacheManager.Add(cacheKey, artist); + } return new OperationResult { IsSuccess = artist != null, @@ -351,7 +349,7 @@ namespace Roadie.Library.Engines if (ITunesArtistSearchEngine.IsEnabled) { var sw2 = Stopwatch.StartNew(); - var iTunesResult = await ITunesArtistSearchEngine.PerformArtistSearch(artistName, 1); + var iTunesResult = await ITunesArtistSearchEngine.PerformArtistSearch(artistName, 1).ConfigureAwait(false); if (iTunesResult.IsSuccess) { var i = iTunesResult.Data.First(); @@ -408,7 +406,7 @@ namespace Roadie.Library.Engines if (MusicBrainzArtistSearchEngine.IsEnabled) { var sw2 = Stopwatch.StartNew(); - var mbResult = await MusicBrainzArtistSearchEngine.PerformArtistSearch(result.Name, 1); + var mbResult = await MusicBrainzArtistSearchEngine.PerformArtistSearch(result.Name, 1).ConfigureAwait(false); if (mbResult.IsSuccess) { var mb = mbResult.Data.First(); @@ -447,6 +445,10 @@ namespace Roadie.Library.Engines BioContext = mb.Bio, Profile = mb.Profile, MusicBrainzId = mb.MusicBrainzId, + DiscogsId = mb.DiscogsId, + SpotifyId = mb.SpotifyId, + ITunesId = mb.iTunesId, + AmgId = mb.AmgId, BeginDate = mb.BeginDate, Name = result.Name ?? mb.ArtistName, SortName = result.SortName ?? mb.ArtistSortName, @@ -469,7 +471,7 @@ namespace Roadie.Library.Engines if (LastFmArtistSearchEngine.IsEnabled) { var sw2 = Stopwatch.StartNew(); - var lastFmResult = await LastFmArtistSearchEngine.PerformArtistSearch(result.Name, 1); + var lastFmResult = await LastFmArtistSearchEngine.PerformArtistSearch(result.Name, 1).ConfigureAwait(false); if (lastFmResult.IsSuccess) { var l = lastFmResult.Data.First(); @@ -482,7 +484,9 @@ namespace Roadie.Library.Engines if (l.ArtistGenres != null) artistGenres.AddRange(l.ArtistGenres); if (!string.IsNullOrEmpty(l.ArtistName) && !l.ArtistName.Equals(result.Name, StringComparison.OrdinalIgnoreCase)) + { result.AlternateNames.AddToDelimitedList(new[] { l.ArtistName }); + } result.CopyTo(new Artist { EndDate = l.EndDate, @@ -511,7 +515,7 @@ namespace Roadie.Library.Engines if (SpotifyArtistSearchEngine.IsEnabled) { var sw2 = Stopwatch.StartNew(); - var spotifyResult = await SpotifyArtistSearchEngine.PerformArtistSearch(result.Name, 1); + var spotifyResult = await SpotifyArtistSearchEngine.PerformArtistSearch(result.Name, 1).ConfigureAwait(false); if (spotifyResult.IsSuccess) { var s = spotifyResult.Data.First(); @@ -521,13 +525,16 @@ namespace Roadie.Library.Engines if (s.ArtistGenres != null) artistGenres.AddRange(s.ArtistGenres); if (!string.IsNullOrEmpty(s.ArtistName) && !s.ArtistName.Equals(result.Name, StringComparison.OrdinalIgnoreCase)) + { result.AlternateNames.AddToDelimitedList(new[] { s.ArtistName }); + } result.CopyTo(new Artist { EndDate = s.EndDate, BioContext = s.Bio, Profile = HttpEncoder.HtmlEncode(s.Profile), MusicBrainzId = s.MusicBrainzId, + SpotifyId = s.SpotifyId, BeginDate = s.BeginDate, Name = result.Name ?? s.ArtistName, SortName = result.SortName ?? s.ArtistSortName, @@ -550,7 +557,7 @@ namespace Roadie.Library.Engines if (DiscogsArtistSearchEngine.IsEnabled) { var sw2 = Stopwatch.StartNew(); - var discogsResult = await DiscogsArtistSearchEngine.PerformArtistSearch(result.Name, 1); + var discogsResult = await DiscogsArtistSearchEngine.PerformArtistSearch(result.Name, 1).ConfigureAwait(false); if (discogsResult.IsSuccess) { var d = discogsResult?.Data?.FirstOrDefault(); @@ -607,7 +614,7 @@ namespace Roadie.Library.Engines { wikiName += " band"; } - var wikipediaResult = await WikipediaArtistSearchEngine.PerformArtistSearch(wikiName, 1); + var wikipediaResult = await WikipediaArtistSearchEngine.PerformArtistSearch(wikiName, 1).ConfigureAwait(false); if (wikipediaResult?.Data != null) { if (wikipediaResult.IsSuccess) @@ -647,7 +654,7 @@ namespace Roadie.Library.Engines { result.Tags = string.Join("|", result.Tags.ToListFromDelimited().Distinct().OrderBy(x => x)); } - if (artistGenres.Any()) + if (artistGenres.Count > 0) { var sw2 = Stopwatch.StartNew(); var genreInfos = from ag in artistGenres @@ -663,7 +670,7 @@ namespace Roadie.Library.Engines { var ag = new ArtistGenre { - Genre = genreInfo.existingGenre != null ? genreInfo.existingGenre : new Genre + Genre = genreInfo.existingGenre ?? new Genre { Name = genreInfo.newGenre, NormalizedName = genreInfo.newGenre.ToAlphanumericName() @@ -678,16 +685,13 @@ namespace Roadie.Library.Engines Logger.LogTrace($"PerformMetaDataProvidersArtistSearch: Artist Genre Processing Complete [{ sw2.ElapsedMilliseconds }]"); } - if (artistImageUrls.Any()) + if (artistImageUrls.Count > 0) { var sw2 = Stopwatch.StartNew(); var imageBag = new ConcurrentBag(); - var i = artistImageUrls.Select(async url => - { - imageBag.Add(await WebHelper.GetImageFromUrlAsync(url)); - }); - await Task.WhenAll(i); - result.Images = imageBag.Where(x => x != null && x.Bytes != null) + var i = artistImageUrls.Select(async url => imageBag.Add(await WebHelper.GetImageFromUrlAsync(url).ConfigureAwait(false))); + await Task.WhenAll(i).ConfigureAwait(false); + result.Images = imageBag.Where(x => x?.Bytes != null) .GroupBy(x => x.Signature) .Select(x => x.First()) .Take(Configuration.Processing.MaximumArtistImagesToAdd) @@ -703,6 +707,7 @@ namespace Roadie.Library.Engines result.SortName = result.SortName.ToTitleCase(); if (!string.IsNullOrEmpty(result.ArtistType)) + { switch (result.ArtistType.ToLower().Replace('-', ' ')) { case "artist": @@ -747,6 +752,7 @@ namespace Roadie.Library.Engines result.ArtistType = "Other"; break; } + } sw.Stop(); return new OperationResult diff --git a/Roadie.Api.Library/Engines/IArtistLookupEngine.cs b/Roadie.Api.Library/Engines/IArtistLookupEngine.cs index 0cdbb05..0cbaae6 100644 --- a/Roadie.Api.Library/Engines/IArtistLookupEngine.cs +++ b/Roadie.Api.Library/Engines/IArtistLookupEngine.cs @@ -17,6 +17,7 @@ namespace Roadie.Library.Engines IArtistSearchEngine WikipediaArtistSearchEngine { get; } Task> Add(Artist artist); + /// /// There can be more than one Artist matching the given name with Alternate and Normalized Name matching /// diff --git a/Roadie.Api.Library/Engines/LabelLookupEngine.cs b/Roadie.Api.Library/Engines/LabelLookupEngine.cs index 6108b91..b77dde0 100644 --- a/Roadie.Api.Library/Engines/LabelLookupEngine.cs +++ b/Roadie.Api.Library/Engines/LabelLookupEngine.cs @@ -46,7 +46,7 @@ namespace Roadie.Library.Engines var inserted = 0; try { - inserted = await DbContext.SaveChangesAsync(); + inserted = await DbContext.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { @@ -95,7 +95,7 @@ namespace Roadie.Library.Engines select l ).FirstOrDefault(); sw.Stop(); - if (label == null || !label.IsValid) + if (label?.IsValid != true) { Logger.LogTrace("LabelFactory: Label Not Found By Name [{0}]", labelName); if (doFindIfNotInDatabase) @@ -103,7 +103,7 @@ namespace Roadie.Library.Engines OperationResult