diff --git a/Inspector/Inspector.csproj b/Inspector/Inspector.csproj
index 6706d76..e9beb22 100644
--- a/Inspector/Inspector.csproj
+++ b/Inspector/Inspector.csproj
@@ -22,7 +22,7 @@
-
+
diff --git a/Roadie.Api.Library.Tests/ArtistLookupEngineTests.cs b/Roadie.Api.Library.Tests/ArtistLookupEngineTests.cs
index fe72721..3d58659 100644
--- a/Roadie.Api.Library.Tests/ArtistLookupEngineTests.cs
+++ b/Roadie.Api.Library.Tests/ArtistLookupEngineTests.cs
@@ -47,7 +47,7 @@ namespace Roadie.Library.Tests
IConfiguration configuration = configurationBuilder.Build();
configuration.GetSection("RoadieSettings").Bind(settings);
Configuration = settings;
- CacheManager = new DictionaryCacheManager(Logger, new CachePolicy(TimeSpan.FromHours(4)));
+ CacheManager = new DictionaryCacheManager(Logger, new NewtonsoftCacheSerializer(Logger), new CachePolicy(TimeSpan.FromHours(4)));
HttpEncoder = new Encoding.DummyHttpEncoder();
}
diff --git a/Roadie.Api.Library.Tests/ExtensionTests.cs b/Roadie.Api.Library.Tests/ExtensionTests.cs
index 15ac01e..723fe93 100644
--- a/Roadie.Api.Library.Tests/ExtensionTests.cs
+++ b/Roadie.Api.Library.Tests/ExtensionTests.cs
@@ -290,5 +290,22 @@ namespace Roadie.Library.Tests
var d = input.ToSecondsFromMilliseconds();
Assert.Equal(shouldBe, d);
}
+
+ [Theory]
+ [InlineData("Song (ft. Joe)")]
+ [InlineData("Song (featuring Joe)")]
+ [InlineData("Song (feat. Joe)")]
+ public void StringHaveFeatureFragments(string input)
+ {
+ Assert.True(input.HasFeaturingFragments());
+ }
+
+ [Theory]
+ [InlineData("Future Feature")]
+ [InlineData("Feature Song")]
+ public void StringShouldNotHaveFeatureFragments(string input)
+ {
+ Assert.False(input.HasFeaturingFragments());
+ }
}
}
diff --git a/Roadie.Api.Library.Tests/ID3TagsHelperTests.cs b/Roadie.Api.Library.Tests/ID3TagsHelperTests.cs
index 6ea698c..012a75b 100644
--- a/Roadie.Api.Library.Tests/ID3TagsHelperTests.cs
+++ b/Roadie.Api.Library.Tests/ID3TagsHelperTests.cs
@@ -42,7 +42,7 @@ namespace Roadie.Library.Tests
configuration.GetSection("RoadieSettings").Bind(settings);
settings.ConnectionString = configuration.GetConnectionString("RoadieDatabaseConnection");
Configuration = settings;
- CacheManager = new DictionaryCacheManager(Logger, new CachePolicy(TimeSpan.FromHours(4)));
+ CacheManager = new DictionaryCacheManager(Logger, new NewtonsoftCacheSerializer(Logger), new CachePolicy(TimeSpan.FromHours(4)));
var tagHelperLooper = new EventMessageLogger();
tagHelperLooper.Messages += MessageLoggerMessages;
TagsHelper = new ID3TagsHelper(Configuration, CacheManager, tagHelperLooper);
diff --git a/Roadie.Api.Library.Tests/InspectorTests.cs b/Roadie.Api.Library.Tests/InspectorTests.cs
index ecf91f6..a3308dd 100644
--- a/Roadie.Api.Library.Tests/InspectorTests.cs
+++ b/Roadie.Api.Library.Tests/InspectorTests.cs
@@ -45,7 +45,7 @@ namespace Roadie.Library.Tests
configuration.GetSection("RoadieSettings").Bind(settings);
settings.ConnectionString = configuration.GetConnectionString("RoadieDatabaseConnection");
Configuration = settings;
- CacheManager = new DictionaryCacheManager(Logger, new CachePolicy(TimeSpan.FromHours(4)));
+ CacheManager = new DictionaryCacheManager(Logger, new NewtonsoftCacheSerializer(Logger), new CachePolicy(TimeSpan.FromHours(4)));
var tagHelperLooper = new EventMessageLogger();
tagHelperLooper.Messages += MessageLoggerMessages;
TagsHelper = new ID3TagsHelper(Configuration, CacheManager, tagHelperLooper);
diff --git a/Roadie.Api.Library.Tests/Roadie.Library.Tests.csproj b/Roadie.Api.Library.Tests/Roadie.Library.Tests.csproj
index f891d84..1a5df5e 100644
--- a/Roadie.Api.Library.Tests/Roadie.Library.Tests.csproj
+++ b/Roadie.Api.Library.Tests/Roadie.Library.Tests.csproj
@@ -23,7 +23,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/Roadie.Api.Library.Tests/SearchEngineTests.cs b/Roadie.Api.Library.Tests/SearchEngineTests.cs
index 0a17146..47f18f3 100644
--- a/Roadie.Api.Library.Tests/SearchEngineTests.cs
+++ b/Roadie.Api.Library.Tests/SearchEngineTests.cs
@@ -35,7 +35,7 @@ namespace Roadie.Library.Tests
IConfiguration configuration = configurationBuilder.Build();
configuration.GetSection("RoadieSettings").Bind(settings);
Configuration = settings;
- CacheManager = new DictionaryCacheManager(Logger, new CachePolicy(TimeSpan.FromHours(4)));
+ CacheManager = new DictionaryCacheManager(Logger, new NewtonsoftCacheSerializer(Logger), new CachePolicy(TimeSpan.FromHours(4)));
HttpEncoder = new Encoding.DummyHttpEncoder();
}
diff --git a/Roadie.Api.Library/Caching/CacheManagerBase.cs b/Roadie.Api.Library/Caching/CacheManagerBase.cs
index 495cb4e..be231c2 100644
--- a/Roadie.Api.Library/Caching/CacheManagerBase.cs
+++ b/Roadie.Api.Library/Caching/CacheManagerBase.cs
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
-using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
@@ -10,19 +9,15 @@ namespace Roadie.Library.Caching
public const string SystemCacheRegionUrn = "urn:system";
protected readonly CachePolicy _defaultPolicy;
- protected readonly JsonSerializerSettings _serializerSettings;
protected ILogger Logger { get; }
+ protected ICacheSerializer CacheSerializer { get; }
- public CacheManagerBase(ILogger logger, CachePolicy defaultPolicy)
+ public CacheManagerBase(ILogger logger, ICacheSerializer cacheSerializer, CachePolicy defaultPolicy)
{
Logger = logger;
+ CacheSerializer = cacheSerializer;
_defaultPolicy = defaultPolicy;
- _serializerSettings = new JsonSerializerSettings
- {
- ContractResolver = new IgnoreJsonAttributesResolver(),
- Formatting = Formatting.Indented
- };
}
public abstract bool Add(string key, TCacheValue value);
@@ -55,24 +50,5 @@ namespace Roadie.Library.Caching
public abstract bool Remove(string key, string region);
- protected TOut Deserialize(string s)
- {
- if (string.IsNullOrEmpty(s)) return default(TOut);
- try
- {
- return JsonConvert.DeserializeObject(s, _serializerSettings);
- }
- catch (Exception ex)
- {
- Logger.LogError(ex);
- }
-
- return default(TOut);
- }
-
- protected string Serialize(object o)
- {
- return JsonConvert.SerializeObject(o, _serializerSettings);
- }
}
}
\ No newline at end of file
diff --git a/Roadie.Api.Library/Caching/DictionaryCacheManager.cs b/Roadie.Api.Library/Caching/DictionaryCacheManager.cs
index 88a0cbf..3fe99ec 100644
--- a/Roadie.Api.Library/Caching/DictionaryCacheManager.cs
+++ b/Roadie.Api.Library/Caching/DictionaryCacheManager.cs
@@ -11,8 +11,8 @@ namespace Roadie.Library.Caching
private Dictionary Cache { get; }
- public DictionaryCacheManager(ILogger logger, CachePolicy defaultPolicy)
- : base(logger, defaultPolicy)
+ public DictionaryCacheManager(ILogger logger, ICacheSerializer cacheSerializer, CachePolicy defaultPolicy)
+ : base(logger, cacheSerializer, defaultPolicy)
{
Cache = new Dictionary();
}
diff --git a/Roadie.Api.Library/Caching/ICacheSerializer.cs b/Roadie.Api.Library/Caching/ICacheSerializer.cs
new file mode 100644
index 0000000..26ad043
--- /dev/null
+++ b/Roadie.Api.Library/Caching/ICacheSerializer.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Roadie.Library.Caching
+{
+ public interface ICacheSerializer
+ {
+ string Serialize(object o);
+ TOut Deserialize(string s);
+ }
+}
diff --git a/Roadie.Api.Library/Caching/MemoryCacheManager.cs b/Roadie.Api.Library/Caching/MemoryCacheManager.cs
index 78570ce..34c218d 100644
--- a/Roadie.Api.Library/Caching/MemoryCacheManager.cs
+++ b/Roadie.Api.Library/Caching/MemoryCacheManager.cs
@@ -9,8 +9,8 @@ namespace Roadie.Library.Caching
{
private MemoryCache _cache;
- public MemoryCacheManager(ILogger logger, CachePolicy defaultPolicy)
- : base(logger, defaultPolicy)
+ public MemoryCacheManager(ILogger logger, ICacheSerializer cacheSerializer, CachePolicy defaultPolicy)
+ : base(logger, cacheSerializer, defaultPolicy)
{
_cache = new MemoryCache(new MemoryCacheOptions());
}
diff --git a/Roadie.Api.Library/Caching/NewtonsoftCacheSerializer.cs b/Roadie.Api.Library/Caching/NewtonsoftCacheSerializer.cs
new file mode 100644
index 0000000..9831cb7
--- /dev/null
+++ b/Roadie.Api.Library/Caching/NewtonsoftCacheSerializer.cs
@@ -0,0 +1,43 @@
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using System;
+
+namespace Roadie.Library.Caching
+{
+ public class NewtonsoftCacheSerializer : ICacheSerializer
+ {
+ protected ILogger Logger { get; }
+
+ protected readonly JsonSerializerSettings _serializerSettings;
+
+ public NewtonsoftCacheSerializer(ILogger logger)
+ {
+ Logger = logger;
+ _serializerSettings = new JsonSerializerSettings
+ {
+ ContractResolver = new IgnoreJsonAttributesResolver(),
+ ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
+ Formatting = Formatting.Indented
+ };
+ }
+
+ public TOut Deserialize(string s)
+ {
+ if (string.IsNullOrEmpty(s))
+ {
+ return default(TOut);
+ }
+ try
+ {
+ return JsonConvert.DeserializeObject(s, _serializerSettings);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex);
+ }
+ return default(TOut);
+ }
+
+ public string Serialize(object o) => JsonConvert.SerializeObject(o, _serializerSettings);
+ }
+}
\ No newline at end of file
diff --git a/Roadie.Api.Library/Caching/RedisCacheManager.cs b/Roadie.Api.Library/Caching/RedisCacheManager.cs
index ec4b43f..da31fc5 100644
--- a/Roadie.Api.Library/Caching/RedisCacheManager.cs
+++ b/Roadie.Api.Library/Caching/RedisCacheManager.cs
@@ -26,8 +26,8 @@ namespace Roadie.Library.Caching
private IDatabase Redis => _redis ?? (_redis = Connection.GetDatabase());
- public RedisCacheManager(ILogger logger, CachePolicy defaultPolicy)
- : base(logger, defaultPolicy)
+ public RedisCacheManager(ILogger logger, ICacheSerializer cacheSerializer, CachePolicy defaultPolicy)
+ : base(logger, cacheSerializer, defaultPolicy)
{
}
@@ -49,7 +49,7 @@ namespace Roadie.Library.Caching
public override bool Add(string key, TCacheValue value, string region, CachePolicy policy)
{
if (_doTraceLogging) Logger.LogTrace("Added [{0}], Region [{1}]", key, region);
- return Redis.StringSet(key, Serialize(value));
+ return Redis.StringSet(key, CacheSerializer.Serialize(value));
}
public override void Clear()
@@ -135,7 +135,7 @@ namespace Roadie.Library.Caching
private TOut Get(string key, string region, CachePolicy policy)
{
- var result = Deserialize(Redis.StringGet(key));
+ var result = CacheSerializer.Deserialize(Redis.StringGet(key));
if (result == null)
{
if (_doTraceLogging) Logger.LogTrace("Get Cache Miss Key [{0}], Region [{1}]", key, region);
diff --git a/Roadie.Api.Library/Caching/Utf8JsonCacheSerializer.cs b/Roadie.Api.Library/Caching/Utf8JsonCacheSerializer.cs
new file mode 100644
index 0000000..1083bfe
--- /dev/null
+++ b/Roadie.Api.Library/Caching/Utf8JsonCacheSerializer.cs
@@ -0,0 +1,52 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Utf8Json;
+
+namespace Roadie.Library.Caching
+{
+ public class Utf8JsonCacheSerializer : ICacheSerializer
+ {
+ protected ILogger Logger { get; }
+
+ public Utf8JsonCacheSerializer(ILogger logger)
+ {
+ Logger = logger;
+ }
+
+ public string Serialize(object o)
+ {
+ if(o == null)
+ {
+ return null;
+ }
+ try
+ {
+ return System.Text.Encoding.UTF8.GetString(JsonSerializer.Serialize(o));
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex);
+ }
+ return null;
+ }
+
+ public TOut Deserialize(string s)
+ {
+ if (string.IsNullOrEmpty(s))
+ {
+ return default(TOut);
+ }
+ try
+ {
+ return JsonSerializer.Deserialize(s);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex);
+ }
+ return default(TOut);
+ }
+ }
+}
diff --git a/Roadie.Api.Library/Configuration/Processing.cs b/Roadie.Api.Library/Configuration/Processing.cs
index ad12ff4..e704253 100644
--- a/Roadie.Api.Library/Configuration/Processing.cs
+++ b/Roadie.Api.Library/Configuration/Processing.cs
@@ -46,6 +46,8 @@ namespace Roadie.Library.Configuration
public string UnknownFolder { get; set; }
+ public bool DoDetectFeatureFragments { get; set; }
+
public Processing()
{
DoAudioCleanup = true;
@@ -55,6 +57,7 @@ namespace Roadie.Library.Configuration
DoParseFromLastFM = true;
DoParseFromMusicBrainz = true;
DoSaveEditsToTags = true;
+ DoDetectFeatureFragments = true;
MaximumArtistImagesToAdd = 12;
MaximumReleaseImagesToAdd = 12;
diff --git a/Roadie.Api.Library/Data/CollectionPartial.cs b/Roadie.Api.Library/Data/CollectionPartial.cs
index 84e2ab0..6eef9dd 100644
--- a/Roadie.Api.Library/Data/CollectionPartial.cs
+++ b/Roadie.Api.Library/Data/CollectionPartial.cs
@@ -1,7 +1,5 @@
using CsvHelper;
-using Newtonsoft.Json;
using Roadie.Library.Configuration;
-using Roadie.Library.Enums;
using Roadie.Library.Extensions;
using Roadie.Library.Utility;
using System;
@@ -14,6 +12,10 @@ namespace Roadie.Library.Data
{
public partial class Collection
{
+ public const string ArtistPosition = "artist";
+ public const string PositionPosition = "position";
+ public const string ReleasePosition = "release";
+
///
/// If the given value in either Artist or Release starts with this then the next value is the database Id, example "1,~4,~19"
///
@@ -35,7 +37,10 @@ namespace Roadie.Library.Data
foreach (var pos in ListInCSVFormat.Split(','))
{
looper++;
- if (pos.ToLower().Equals("artist")) _artistColumn = looper;
+ if (String.Equals(pos, ArtistPosition, StringComparison.OrdinalIgnoreCase))
+ {
+ _artistColumn = looper;
+ }
}
}
@@ -70,7 +75,10 @@ namespace Roadie.Library.Data
foreach (var pos in ListInCSVFormat.Split(','))
{
looper++;
- if (pos.ToLower().Equals("position")) _positionColumn = looper;
+ if (String.Equals(pos, PositionPosition, StringComparison.OrdinalIgnoreCase))
+ {
+ _positionColumn = looper;
+ }
}
}
@@ -88,7 +96,10 @@ namespace Roadie.Library.Data
foreach (var pos in ListInCSVFormat.Split(','))
{
looper++;
- if (pos.ToLower().Equals("release")) _releaseColumn = looper;
+ if (String.Equals(pos, ReleasePosition, StringComparison.OrdinalIgnoreCase))
+ {
+ _releaseColumn = looper;
+ }
}
}
@@ -129,10 +140,7 @@ namespace Roadie.Library.Data
MissingFieldFound = null,
HasHeaderRecord = false
};
- configuration.BadDataFound = context =>
- {
- Trace.WriteLine($"PositionArtistReleases: Bad data found on row '{context.RawRow}'", "Warning");
- };
+ configuration.BadDataFound = context => Trace.WriteLine($"PositionArtistReleases: Bad data found on row '{context.RawRow}'", "Warning");
using (var csv = new CsvReader(sr, configuration))
{
while (csv.Read())
@@ -160,6 +168,4 @@ namespace Roadie.Library.Data
return $"Id [{Id}], Name [{Name}], RoadieId [{RoadieId}]";
}
}
-
-
}
\ No newline at end of file
diff --git a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs
index 4d9df46..965eb99 100644
--- a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs
+++ b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs
@@ -1,6 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
-using Newtonsoft.Json;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data;
@@ -19,6 +18,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Text.Json;
using System.Threading.Tasks;
using discogs = Roadie.Library.SearchEngines.MetaData.Discogs;
using lastfm = Roadie.Library.MetaData.LastFm;
@@ -251,7 +251,7 @@ namespace Roadie.Library.Engines
}
if (!string.IsNullOrEmpty(releaseRoadieDataFilename) && File.Exists(releaseRoadieDataFilename))
{
- artist = JsonConvert.DeserializeObject(File.ReadAllText(releaseRoadieDataFilename));
+ artist = JsonSerializer.Deserialize(File.ReadAllText(releaseRoadieDataFilename));
var addResult = await Add(artist).ConfigureAwait(false);
if (!addResult.IsSuccess)
{
diff --git a/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs b/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs
index 1d1e1d5..6ac56f1 100644
--- a/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs
+++ b/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs
@@ -30,7 +30,11 @@ namespace Roadie.Library.Engines
{
public class ReleaseLookupEngine : LookupEngineBase, IReleaseLookupEngine
{
+ private IArtistLookupEngine ArtistLookupEngine { get; }
+ private ILabelLookupEngine LabelLookupEngine { get; }
+
public List _addedReleaseIds = new List();
+
public List _addedTrackIds = new List();
public IEnumerable AddedReleaseIds => _addedReleaseIds;
@@ -49,10 +53,6 @@ namespace Roadie.Library.Engines
public IReleaseSearchEngine WikipediaReleaseSearchEngine { get; }
- private IArtistLookupEngine ArtistLookupEngine { get; }
-
- private ILabelLookupEngine LabelLookupEngine { get; }
-
public ReleaseLookupEngine(IRoadieSettings configuration, IHttpEncoder httpEncoder, IRoadieDbContext context,
ICacheManager cacheManager, ILogger logger, IArtistLookupEngine artistLookupEngine,
ILabelLookupEngine labelLookupEngine, musicbrainz.IMusicBrainzProvider musicBrainzProvider, lastfm.ILastFmHelper lastFmHelper,
@@ -117,7 +117,11 @@ namespace Roadie.Library.Engines
{
var genreName = releaseGenreTable.ToAlphanumericName().ToTitleCase();
var normalizedName = genreName.ToUpper();
- if (string.IsNullOrEmpty(genreName)) continue;
+ if (string.IsNullOrEmpty(genreName))
+ {
+ continue;
+ }
+
if (genreName.Length > 100)
{
var originalName = genreName;
@@ -204,76 +208,73 @@ namespace Roadie.Library.Engines
}
}
- if (doAddTracksInDatabase)
+ if (doAddTracksInDatabase && releaseMedias?.Any(x => x.Status == Statuses.New) == true)
{
- if (releaseMedias?.Any(x => x.Status == Statuses.New) == true)
+ foreach (var newReleaseMedia in releaseMedias.Where(x => x.Status == Statuses.New))
{
- foreach (var newReleaseMedia in releaseMedias.Where(x => x.Status == Statuses.New))
+ var releasemedia = new ReleaseMedia
{
- var releasemedia = new ReleaseMedia
+ Status = Statuses.Incomplete,
+ MediaNumber = newReleaseMedia.MediaNumber,
+ SubTitle = newReleaseMedia.SubTitle,
+ TrackCount = newReleaseMedia.TrackCount,
+ ReleaseId = release.Id
+ };
+ var releasemediatracks = new List
diff --git a/Roadie.Api.Library/RoadieProcessingException.cs b/Roadie.Api.Library/RoadieProcessingException.cs
new file mode 100644
index 0000000..bba5af1
--- /dev/null
+++ b/Roadie.Api.Library/RoadieProcessingException.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Roadie.Library
+{
+ public sealed class RoadieProcessingException : Exception
+ {
+ public RoadieProcessingException() : base()
+ {
+ }
+
+ public RoadieProcessingException(string message)
+ : base(message)
+ {
+ }
+
+ public RoadieProcessingException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}
diff --git a/Roadie.Api.Library/SearchEngines/MetaData/Audio/AudioMetaData.cs b/Roadie.Api.Library/SearchEngines/MetaData/Audio/AudioMetaData.cs
index f2ec034..e7d84b7 100644
--- a/Roadie.Api.Library/SearchEngines/MetaData/Audio/AudioMetaData.cs
+++ b/Roadie.Api.Library/SearchEngines/MetaData/Audio/AudioMetaData.cs
@@ -1,10 +1,10 @@
-using Newtonsoft.Json;
-using Roadie.Library.Extensions;
+using Roadie.Library.Extensions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Text.Json.Serialization;
namespace Roadie.Library.MetaData.Audio
{
@@ -14,10 +14,11 @@ namespace Roadie.Library.MetaData.Audio
public sealed class AudioMetaData : IAudioMetaData
{
public const char ArtistSplitCharacter = '/';
-
public const int MinimumYearValue = 1900;
public const string SoundTrackArtist = "Sound Tracks";
+
private string _artist;
+
private bool _doModifyArtistNameOnGet = true;
private FileInfo _fileInfo;
@@ -43,15 +44,20 @@ namespace Roadie.Library.MetaData.Audio
{
get
{
- if (_doModifyArtistNameOnGet)
- if (!string.IsNullOrEmpty(_artist) && _artist.Contains(ArtistSplitCharacter.ToString()))
- return _artist.Split(ArtistSplitCharacter).First();
+ if (_doModifyArtistNameOnGet && !string.IsNullOrEmpty(_artist) && _artist.Contains(ArtistSplitCharacter.ToString()))
+ {
+ return _artist.Split(ArtistSplitCharacter)[0];
+ }
+
return _artist;
}
set
{
_artist = value;
- if (!string.IsNullOrEmpty(_artist)) _artist = _artist.Replace(';', ArtistSplitCharacter);
+ if (!string.IsNullOrEmpty(_artist))
+ {
+ _artist = _artist.Replace(';', ArtistSplitCharacter);
+ }
}
}
@@ -66,12 +72,36 @@ namespace Roadie.Library.MetaData.Audio
get
{
var result = AudioMetaDataWeights.None;
- if (!string.IsNullOrEmpty(Artist)) result |= AudioMetaDataWeights.Artist;
- if (!string.IsNullOrEmpty(Title)) result |= AudioMetaDataWeights.Time;
- if ((Year ?? 0) > 1) result |= AudioMetaDataWeights.Year;
- if ((TrackNumber ?? 0) > 1) result |= AudioMetaDataWeights.TrackNumber;
- if ((TotalTrackNumbers ?? 0) > 1) result |= AudioMetaDataWeights.TrackTotalNumber;
- if (TotalSeconds > 1) result |= AudioMetaDataWeights.Time;
+ if (!string.IsNullOrEmpty(Artist))
+ {
+ result |= AudioMetaDataWeights.Artist;
+ }
+
+ if (!string.IsNullOrEmpty(Title))
+ {
+ result |= AudioMetaDataWeights.Time;
+ }
+
+ if ((Year ?? 0) > 1)
+ {
+ result |= AudioMetaDataWeights.Year;
+ }
+
+ if ((TrackNumber ?? 0) > 1)
+ {
+ result |= AudioMetaDataWeights.TrackNumber;
+ }
+
+ if ((TotalTrackNumbers ?? 0) > 1)
+ {
+ result |= AudioMetaDataWeights.TrackTotalNumber;
+ }
+
+ if (TotalSeconds > 1)
+ {
+ result |= AudioMetaDataWeights.Time;
+ }
+
return result;
}
}
@@ -90,7 +120,11 @@ namespace Roadie.Library.MetaData.Audio
{
get
{
- if (string.IsNullOrEmpty(Filename)) return null;
+ if (string.IsNullOrEmpty(Filename))
+ {
+ return null;
+ }
+
return Path.GetDirectoryName(Filename);
}
}
@@ -105,7 +139,8 @@ namespace Roadie.Library.MetaData.Audio
///
public string DiscSubTitle { get; set; }
- [JsonIgnore] public FileInfo FileInfo => _fileInfo ?? (_fileInfo = new FileInfo(Filename));
+ [JsonIgnore]
+ public FileInfo FileInfo => _fileInfo ?? (_fileInfo = new FileInfo(Filename));
///
/// Full filename to the file used to get this AudioMetaData
@@ -114,7 +149,8 @@ namespace Roadie.Library.MetaData.Audio
public ICollection Genres { get; set; }
- [JsonIgnore] public IEnumerable Images { get; set; }
+ [JsonIgnore]
+ public IEnumerable Images { get; set; }
public string ISRC { get; internal set; }
@@ -122,10 +158,13 @@ namespace Roadie.Library.MetaData.Audio
{
get
{
- if (Genres != null && Genres.Any())
+ if (Genres?.Any() == true)
{
var soundtrackGenres = new List { "24", "soundtrack" };
- if (Genres.Intersect(soundtrackGenres, StringComparer.OrdinalIgnoreCase).Any()) return true;
+ if (Genres.Intersect(soundtrackGenres, StringComparer.OrdinalIgnoreCase).Any())
+ {
+ return true;
+ }
}
return false;
@@ -142,7 +181,7 @@ namespace Roadie.Library.MetaData.Audio
Release = Release == null ? null : Release.Equals("Unknown Release") ? null : Release;
if (!string.IsNullOrEmpty(Title))
{
- var trackNumberTitle = string.Format("Track {0}", TrackNumber);
+ var trackNumberTitle = $"Track {TrackNumber}";
Title = Title == trackNumberTitle ? null : Title;
}
@@ -193,7 +232,10 @@ namespace Roadie.Library.MetaData.Audio
set
{
_title = value;
- if (IsSoundTrack) Artist = SoundTrackArtist;
+ if (IsSoundTrack)
+ {
+ Artist = SoundTrackArtist;
+ }
}
}
@@ -206,7 +248,11 @@ namespace Roadie.Library.MetaData.Audio
{
get
{
- if (Time == null) return 0;
+ if (Time == null)
+ {
+ return 0;
+ }
+
return Time.Value.TotalSeconds;
}
}
@@ -225,9 +271,11 @@ namespace Roadie.Library.MetaData.Audio
{
string result = null;
if (!string.IsNullOrEmpty(_trackArtist))
- result = _trackArtist.Split(ArtistSplitCharacter).First().ToTitleCase();
- result = !_artist?.Equals(result, StringComparison.OrdinalIgnoreCase) ?? false ? result : null;
- return result;
+ {
+ result = _trackArtist.Split(ArtistSplitCharacter)[0].ToTitleCase();
+ }
+
+ return !String.Equals(_artist, result, StringComparison.OrdinalIgnoreCase) ? result : null;
}
set => _trackArtist = value;
}
@@ -242,17 +290,33 @@ namespace Roadie.Library.MetaData.Audio
{
get
{
- if (string.IsNullOrEmpty(_trackArtist)) return new string[0];
+ if (string.IsNullOrEmpty(_trackArtist))
+ {
+ return new string[0];
+ }
+
if (!_trackArtist.Contains(ArtistSplitCharacter.ToString()))
{
- if (string.IsNullOrEmpty(TrackArtist)) return new string[0];
+ if (string.IsNullOrEmpty(TrackArtist))
+ {
+ return new string[0];
+ }
+
return new string[1] { TrackArtist };
}
if (!string.IsNullOrEmpty(_artist) || !string.IsNullOrEmpty(_trackArtist))
- if (!_artist.Equals(_trackArtist, StringComparison.OrdinalIgnoreCase))
- return _trackArtist.Split(ArtistSplitCharacter).Where(x => !string.IsNullOrEmpty(x))
- .Select(x => x.ToTitleCase()).OrderBy(x => x).ToArray();
+ {
+ if (!String.Equals(_artist, _trackArtist, StringComparison.OrdinalIgnoreCase))
+ {
+ return _trackArtist.Split(ArtistSplitCharacter)
+ .Where(x => !string.IsNullOrEmpty(x))
+ .Select(x => x.ToTitleCase())
+ .OrderBy(x => x)
+ .ToArray();
+ }
+ }
+
return new string[0];
}
}
@@ -280,8 +344,11 @@ namespace Roadie.Library.MetaData.Audio
public override bool Equals(object obj)
{
- var item = obj as AudioMetaData;
- if (item == null) return false;
+ if (!(obj is AudioMetaData item))
+ {
+ return false;
+ }
+
return item.GetHashCode() == GetHashCode();
}
@@ -290,12 +357,12 @@ namespace Roadie.Library.MetaData.Audio
unchecked
{
var hash = 17;
- hash = hash * 23 + Artist.GetHashCode();
- hash = hash * 23 + Release.GetHashCode();
- hash = hash * 23 + Title.GetHashCode();
- hash = hash * 23 + TrackNumber.GetHashCode();
- hash = hash * 23 + AudioBitrate.GetHashCode();
- hash = hash * 23 + AudioSampleRate.GetHashCode();
+ hash = (hash * 23) + Artist.GetHashCode();
+ hash = (hash * 23) + Release.GetHashCode();
+ hash = (hash * 23) + Title.GetHashCode();
+ hash = (hash * 23) + TrackNumber.GetHashCode();
+ hash = (hash * 23) + AudioBitrate.GetHashCode();
+ hash = (hash * 23) + AudioSampleRate.GetHashCode();
return hash;
}
}
@@ -314,9 +381,17 @@ namespace Roadie.Library.MetaData.Audio
{
var result =
$"IsValid: {IsValid}{(IsSoundTrack ? " [SoundTrack ]" : string.Empty)}, ValidWeight {ValidWeight}, Artist: {Artist}";
- if (!string.IsNullOrEmpty(TrackArtist)) result += $", TrackArtist: {TrackArtist}";
+ if (!string.IsNullOrEmpty(TrackArtist))
+ {
+ result += $", TrackArtist: {TrackArtist}";
+ }
+
result += $", Release: {Release}, TrackNumber: {TrackNumber}, TrackTotal: {TotalTrackNumbers}";
- if (TotalDiscCount > 1) result += $", Disc: {Disc}/{TotalDiscCount}";
+ if (TotalDiscCount > 1)
+ {
+ result += $", Disc: {Disc}/{TotalDiscCount}";
+ }
+
result += $", Title: {Title}, Year: {Year}, Duration: {(Time == null ? "-" : Time.Value.ToString())}";
return result;
}
diff --git a/Roadie.Api.Library/SearchEngines/MetaData/MusicBrainz/CoverArtEntities.cs b/Roadie.Api.Library/SearchEngines/MetaData/MusicBrainz/CoverArtEntities.cs
index c702ca1..3cf0b4a 100644
--- a/Roadie.Api.Library/SearchEngines/MetaData/MusicBrainz/CoverArtEntities.cs
+++ b/Roadie.Api.Library/SearchEngines/MetaData/MusicBrainz/CoverArtEntities.cs
@@ -13,7 +13,6 @@
public string comment { get; set; }
public int edit { get; set; }
public bool front { get; set; }
- public string id { get; set; }
public string image { get; set; }
public Thumbnails thumbnails { get; set; }
public string[] types { get; set; }
diff --git a/Roadie.Api.Library/SearchEngines/MetaData/MusicBrainz/Entities.cs b/Roadie.Api.Library/SearchEngines/MetaData/MusicBrainz/Entities.cs
index 58fe118..e1fc59b 100644
--- a/Roadie.Api.Library/SearchEngines/MetaData/MusicBrainz/Entities.cs
+++ b/Roadie.Api.Library/SearchEngines/MetaData/MusicBrainz/Entities.cs
@@ -1,7 +1,7 @@
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Text.Json.Serialization;
namespace Roadie.Library.MetaData.MusicBrainz
{
@@ -13,51 +13,59 @@ namespace Roadie.Library.MetaData.MusicBrainz
public class CoverArtArchive
{
public bool artwork { get; set; }
+
public bool back { get; set; }
+
public int? count { get; set; }
public bool darkened { get; set; }
+
public bool front { get; set; }
}
public class Label
{
public List aliases { get; set; }
+
public string disambiguation { get; set; }
+
+ public NameAndCount[] genres { get; set; }
+
public string id { get; set; }
- [JsonProperty(PropertyName = "label-code")]
+ [JsonPropertyName("label-code")]
public int? labelcode { get; set; }
public string name { get; set; }
- [JsonProperty(PropertyName = "sort-name")]
+ [JsonPropertyName("sort-name")]
public string sortname { get; set; }
public NameAndCount[] tags { get; set; }
- public NameAndCount[] genres { get; set; }
}
[Serializable]
public class LabelInfo
{
- [JsonProperty(PropertyName = "catalog-number")]
+ [JsonPropertyName("catalog-number")]
public string catalognumber { get; set; }
public Label label { get; set; }
}
-
[Serializable]
public class Medium
{
public object format { get; set; }
+
public int? position { get; set; }
+
public string title { get; set; }
- [JsonProperty(PropertyName = "track-count")]
+ [JsonPropertyName("track-count")]
public short? trackcount { get; set; }
- [JsonProperty(PropertyName = "track-offset")]
+
+ [JsonPropertyName("track-offset")]
public int? trackoffset { get; set; }
public List tracks { get; set; }
@@ -67,37 +75,57 @@ namespace Roadie.Library.MetaData.MusicBrainz
public class Recording
{
public List aliases { get; set; }
+
public string disambiguation { get; set; }
- public string id { get; set; }
- public int? length { get; set; }
- public string title { get; set; }
- public bool video { get; set; }
- public NameAndCount[] tags { get; set; }
+
public NameAndCount[] genres { get; set; }
+
+ public string id { get; set; }
+
+ public int? length { get; set; }
+
+ public NameAndCount[] tags { get; set; }
+
+ public string title { get; set; }
+
+ public bool video { get; set; }
}
[Serializable]
public class Relation
{
public List