aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2026-07-23 21:21:28 +0200
committerShadowghost <Ghost_of_Stone@web.de>2026-07-23 21:21:28 +0200
commit8f57f3537260642315d48192e66abd977017d857 (patch)
tree21cab5be5f6af1c305622ad76aeb69cc984d0e4d
parent88216e0ec4adc388a1db795f18fa8f4591ebc099 (diff)
Implement AudioDb artist search
-rw-r--r--MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistProvider.cs86
1 files changed, 84 insertions, 2 deletions
diff --git a/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistProvider.cs
index d8cb6b4b24..b4aae6ac8b 100644
--- a/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistProvider.cs
+++ b/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistProvider.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
@@ -52,8 +53,89 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
public int Order => 1;
/// <inheritdoc />
- public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
- => Task.FromResult(Enumerable.Empty<RemoteSearchResult>());
+ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
+ {
+ // Prefer a known TheAudioDB artist id.
+ var audioDbId = searchInfo.GetProviderId(MetadataProvider.AudioDbArtist);
+ if (!string.IsNullOrWhiteSpace(audioDbId))
+ {
+ var artists = await FetchArtists(BaseUrl + "/artist.php?i=" + audioDbId, cancellationToken).ConfigureAwait(false);
+ return artists.Select(ToRemoteSearchResult);
+ }
+
+ // Fall back to the MusicBrainz artist id, reusing the on-disk cache also used by GetMetadata.
+ var musicBrainzId = searchInfo.GetMusicBrainzArtistId();
+ if (!string.IsNullOrWhiteSpace(musicBrainzId))
+ {
+ await EnsureArtistInfo(musicBrainzId, cancellationToken).ConfigureAwait(false);
+
+ var path = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId);
+
+ FileStream jsonStream = AsyncFile.OpenRead(path);
+ await using (jsonStream.ConfigureAwait(false))
+ {
+ var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
+
+ if (obj is not null && obj.artists is not null)
+ {
+ return obj.artists.Select(ToRemoteSearchResult);
+ }
+ }
+
+ return Enumerable.Empty<RemoteSearchResult>();
+ }
+
+ // Finally, search by name.
+ if (!string.IsNullOrWhiteSpace(searchInfo.Name))
+ {
+ var artists = await FetchArtists(BaseUrl + "/search.php?s=" + Uri.EscapeDataString(searchInfo.Name), cancellationToken).ConfigureAwait(false);
+ return artists.Select(ToRemoteSearchResult);
+ }
+
+ return Enumerable.Empty<RemoteSearchResult>();
+ }
+
+ private async Task<List<Artist>> FetchArtists(string url, CancellationToken cancellationToken)
+ {
+ using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken).ConfigureAwait(false);
+ response.EnsureSuccessStatusCode();
+
+ var jsonStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
+ await using (jsonStream.ConfigureAwait(false))
+ {
+ var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
+
+ return obj?.artists ?? [];
+ }
+ }
+
+ private RemoteSearchResult ToRemoteSearchResult(Artist artist)
+ {
+ var result = new RemoteSearchResult
+ {
+ Name = artist.strArtist,
+ ImageUrl = artist.strArtistThumb,
+ SearchProviderName = Name,
+ Overview = (artist.strBiographyEN ?? string.Empty).StripHtml()
+ };
+
+ if (!string.IsNullOrEmpty(artist.idArtist))
+ {
+ result.SetProviderId(MetadataProvider.AudioDbArtist, artist.idArtist);
+ }
+
+ if (!string.IsNullOrEmpty(artist.strMusicBrainzID))
+ {
+ result.SetProviderId(MetadataProvider.MusicBrainzArtist, artist.strMusicBrainzID);
+ }
+
+ if (int.TryParse(artist.intFormedYear, NumberStyles.Integer, CultureInfo.InvariantCulture, out var formedYear))
+ {
+ result.ProductionYear = formedYear;
+ }
+
+ return result;
+ }
/// <inheritdoc />
public async Task<MetadataResult<MusicArtist>> GetMetadata(ArtistInfo info, CancellationToken cancellationToken)