-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from Zastai/update-mappings
Update the mappings to match current API results
- Loading branch information
Showing
26 changed files
with
426 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
using JetBrains.Annotations; | ||
|
||
namespace MetaBrainz.ListenBrainz.Interfaces; | ||
|
||
/// <summary>An entry in an artist credit taken from the MusicBrainz database.</summary> | ||
[PublicAPI] | ||
public interface IArtistCredit { | ||
|
||
/// <summary>The name specified for the artist in the credit.</summary> | ||
string CreditedName { get; } | ||
|
||
/// <summary>The MusicBrainz IDs for the artist.</summary> | ||
Guid Id { get; } | ||
|
||
/// <summary> | ||
/// The phrase used to connect this entry to the next one in the credit, or to end the credit if this is the last entry. | ||
/// </summary> | ||
string? JoinPhrase { get; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
MetaBrainz.ListenBrainz/Interfaces/IMusicBrainzIdMappings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
MetaBrainz.ListenBrainz/Json/Readers/ArtistCreditReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
|
||
using MetaBrainz.Common.Json; | ||
using MetaBrainz.Common.Json.Converters; | ||
using MetaBrainz.ListenBrainz.Objects; | ||
|
||
namespace MetaBrainz.ListenBrainz.Json.Readers; | ||
|
||
internal class ArtistCreditReader : ObjectReader<ArtistCredit> { | ||
|
||
public static readonly ArtistCreditReader Instance = new(); | ||
|
||
protected override ArtistCredit ReadObjectContents(ref Utf8JsonReader reader, JsonSerializerOptions options) { | ||
string? creditedName = null; | ||
string? joinPhrase = null; | ||
Guid? id = null; | ||
Dictionary<string, object?>? rest = null; | ||
while (reader.TokenType == JsonTokenType.PropertyName) { | ||
var prop = reader.GetPropertyName(); | ||
try { | ||
reader.Read(); | ||
switch (prop) { | ||
case "artist_credit_name": | ||
creditedName = reader.GetString(); | ||
break; | ||
case "artist_mbid": | ||
id = reader.GetOptionalGuid(); | ||
break; | ||
case "join_phrase": | ||
joinPhrase = reader.GetString(); | ||
break; | ||
default: | ||
rest ??= new Dictionary<string, object?>(); | ||
rest[prop] = reader.GetOptionalObject(options); | ||
break; | ||
} | ||
} | ||
catch (Exception e) { | ||
throw new JsonException($"Failed to deserialize the '{prop}' property.", e); | ||
} | ||
reader.Read(); | ||
} | ||
if (creditedName is null) { | ||
throw new JsonException("Expected artist credit name not found or null."); | ||
} | ||
if (id is null) { | ||
throw new JsonException("Expected artist ID not found or null."); | ||
} | ||
if (joinPhrase is null) { | ||
throw new JsonException("Expected join phrase not found or null."); | ||
} | ||
return new ArtistCredit(creditedName, id.Value, joinPhrase) { | ||
UnhandledProperties = rest, | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.