Skip to content

Commit

Permalink
Backport pull request jellyfin#13003 from jellyfin/release-10.10.z
Browse files Browse the repository at this point in the history
Only set first MusicBrainz ID for audio tags

Original-merge: e2434d3

Merged-by: crobibero <[email protected]>

Backported-by: Joshua M. Boniface <[email protected]>
  • Loading branch information
gnattu authored and joshuaboniface committed Nov 19, 2024
1 parent fbdbf77 commit 7f296d0
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ private async Task FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo medi
|| track.AdditionalFields.TryGetValue("MusicBrainz Artist Id", out musicBrainzArtistTag))
&& !string.IsNullOrEmpty(musicBrainzArtistTag))
{
audio.TrySetProviderId(MetadataProvider.MusicBrainzArtist, musicBrainzArtistTag);
var id = GetFirstMusicBrainzId(musicBrainzArtistTag, libraryOptions.UseCustomTagDelimiters, libraryOptions.GetCustomTagDelimiters(), libraryOptions.DelimiterWhitelist);
audio.TrySetProviderId(MetadataProvider.MusicBrainzArtist, id);
}
}

Expand All @@ -357,7 +358,8 @@ private async Task FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo medi
|| track.AdditionalFields.TryGetValue("MusicBrainz Album Artist Id", out musicBrainzReleaseArtistIdTag))
&& !string.IsNullOrEmpty(musicBrainzReleaseArtistIdTag))
{
audio.TrySetProviderId(MetadataProvider.MusicBrainzAlbumArtist, musicBrainzReleaseArtistIdTag);
var id = GetFirstMusicBrainzId(musicBrainzReleaseArtistIdTag, libraryOptions.UseCustomTagDelimiters, libraryOptions.GetCustomTagDelimiters(), libraryOptions.DelimiterWhitelist);
audio.TrySetProviderId(MetadataProvider.MusicBrainzAlbumArtist, id);
}
}

Expand All @@ -367,7 +369,8 @@ private async Task FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo medi
|| track.AdditionalFields.TryGetValue("MusicBrainz Album Id", out musicBrainzReleaseIdTag))
&& !string.IsNullOrEmpty(musicBrainzReleaseIdTag))
{
audio.TrySetProviderId(MetadataProvider.MusicBrainzAlbum, musicBrainzReleaseIdTag);
var id = GetFirstMusicBrainzId(musicBrainzReleaseIdTag, libraryOptions.UseCustomTagDelimiters, libraryOptions.GetCustomTagDelimiters(), libraryOptions.DelimiterWhitelist);
audio.TrySetProviderId(MetadataProvider.MusicBrainzAlbum, id);
}
}

Expand All @@ -377,7 +380,8 @@ private async Task FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo medi
|| track.AdditionalFields.TryGetValue("MusicBrainz Release Group Id", out musicBrainzReleaseGroupIdTag))
&& !string.IsNullOrEmpty(musicBrainzReleaseGroupIdTag))
{
audio.TrySetProviderId(MetadataProvider.MusicBrainzReleaseGroup, musicBrainzReleaseGroupIdTag);
var id = GetFirstMusicBrainzId(musicBrainzReleaseGroupIdTag, libraryOptions.UseCustomTagDelimiters, libraryOptions.GetCustomTagDelimiters(), libraryOptions.DelimiterWhitelist);
audio.TrySetProviderId(MetadataProvider.MusicBrainzReleaseGroup, id);
}
}

Expand All @@ -387,7 +391,8 @@ private async Task FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo medi
|| track.AdditionalFields.TryGetValue("MusicBrainz Release Track Id", out trackMbId))
&& !string.IsNullOrEmpty(trackMbId))
{
audio.TrySetProviderId(MetadataProvider.MusicBrainzTrack, trackMbId);
var id = GetFirstMusicBrainzId(trackMbId, libraryOptions.UseCustomTagDelimiters, libraryOptions.GetCustomTagDelimiters(), libraryOptions.DelimiterWhitelist);
audio.TrySetProviderId(MetadataProvider.MusicBrainzTrack, id);
}
}

Expand Down Expand Up @@ -441,5 +446,18 @@ private List<string> SplitWithCustomDelimiter(string val, char[] tagDelimiters,

return items;
}

// MusicBrainz IDs are multi-value tags, so we need to split them
// However, our current provider can only have one single ID, which means we need to pick the first one
private string? GetFirstMusicBrainzId(string tag, bool useCustomTagDelimiters, char[] tagDelimiters, string[] whitelist)
{
var val = tag.Split(InternalValueSeparator).FirstOrDefault();
if (val is not null && useCustomTagDelimiters)
{
val = SplitWithCustomDelimiter(val, tagDelimiters, whitelist).FirstOrDefault();
}

return val;
}
}
}

0 comments on commit 7f296d0

Please sign in to comment.