Skip to content

Commit

Permalink
Added WithAllProviders method to configure LyricsScraperClient with a…
Browse files Browse the repository at this point in the history
…ll available providers
  • Loading branch information
skuill committed Jan 27, 2024
1 parent 9dbf3b7 commit 5e18c3d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
26 changes: 19 additions & 7 deletions LyricsScraperNET.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,32 @@ private static SearchResult ExampleWithHostConfiguration(string artistToSearch,
/// <returns>lyrics text</returns>
private static SearchResult ExampleWithCertainProvider(string artistToSearch, string songToSearch)
{
//// Create instance of LyricScraperClient with different lyrics providers
//// Create instance of LyricScraperClient with all available lyrics providers
ILyricsScraperClient lyricsScraperClient
= new LyricsScraperClient()
.WithGenius()
.WithAZLyrics()
.WithMusixmatch()
.WithSongLyrics()
.WithLyricFind();
.WithAllProviders();

//// To configure a specific provider, use a method like With[ProviderName]()
// ILyricsScraperClient lyricsScraperClient
// = new LyricsScraperClient()
// .WithGenius()
// .WithAZLyrics()
// .WithMusixmatch()
// .WithSongLyrics()
// .WithLyricFind();

//// Another way to configure:
//// 1. First create instance of LyricScraperClient.
// ILyricsScraperClient lyricsScraperClient = new LyricsScraperClient();
//// 2. Create some external provider instanse. For example Genius:
//// 2. Create some external provider instanse with default settings. For example Genius:
// IExternalProvider externalProvider = new GeniusProvider();
//// 2. Or create provider with custom settings like:
// GeniusOptions geniusOptions = new GeniusOptions()
// {
// Enabled = true,
// SearchPriority = 1
// };
// IExternalProvider externalProvider = new GeniusProvider(geniusOptions);
//// 3. Add external provider to client:
// lyricsScraperClient.AddProvider(externalProvider);

Expand Down
15 changes: 15 additions & 0 deletions LyricsScraperNET/Extensions/LyricsScraperClientExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using LyricsScraperNET.Providers.AZLyrics;
using LyricsScraperNET.Providers.Genius;
using LyricsScraperNET.Providers.LyricFind;
using LyricsScraperNET.Providers.Models;
using LyricsScraperNET.Providers.Musixmatch;
using LyricsScraperNET.Providers.SongLyrics;

Expand Down Expand Up @@ -37,5 +38,19 @@ public static ILyricsScraperClient WithLyricFind(this ILyricsScraperClient lyric
lyricsScraperClient.AddProvider(new LyricFindProvider());
return lyricsScraperClient;
}

/// <summary>
/// Configure LyricsScraperClient with all available providers in <seealso cref="ExternalProviderType"/>.
/// Search lyrics enabled by default for all providers.
/// </summary>
public static ILyricsScraperClient WithAllProviders(this ILyricsScraperClient lyricsScraperClient)
{
return lyricsScraperClient
.WithGenius()
.WithAZLyrics()
.WithMusixmatch()
.WithSongLyrics()
.WithLyricFind();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using LyricsScraperNET.Providers.Models;
using System;
using System.Linq;
using Xunit;

namespace LyricsScraperNET.UnitTest.Extensions
Expand Down Expand Up @@ -81,5 +83,26 @@ public void LyricsScraperClient_WithLyricFind_ReturnsIsEnabled()
Assert.True(externalTypeProvider.IsEnabled);
Assert.Equal(3, externalTypeProvider.SearchPriority);
}

[Fact]
public void LyricsScraperClient_WithAllProviders_ReturnsIsEnabled()
{
// Act
var lyricsScraperClient = _lyricsScraperClient.WithAllProviders();

Assert.NotNull(lyricsScraperClient);
Assert.True(lyricsScraperClient.IsEnabled);

foreach (var providerType in Enum.GetValues(typeof(ExternalProviderType)).Cast<ExternalProviderType>())
{
if (providerType == ExternalProviderType.None)
continue;
var externalTypeProvider = lyricsScraperClient[providerType];

// Assert
Assert.NotNull(externalTypeProvider);
Assert.True(externalTypeProvider.IsEnabled);
}
}
}
}

0 comments on commit 5e18c3d

Please sign in to comment.