Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 31 additions & 36 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -1,86 +1,81 @@
name: CI/CD LyricsScraperNET

on:
push:
pull_request:

jobs:
lyrics_scraper_net-cicd:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "3.1.x"
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "5.0.x"
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "6.0.x"
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
- uses: actions/setup-dotnet@v3
uses: actions/checkout@v7

- name: Setup .NET SDKs
uses: actions/setup-dotnet@v6
with:
dotnet-version: "8.0.x"
dotnet-version: |
8.0.x
9.0.x
10.0.x

- name: Set RELEASE_VERSION
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Restore Packages
run: dotnet restore

- name: Lint
run: dotnet format --verify-no-changes --exclude *\xunit*\*

- name: Build
run: dotnet build --configuration Release --verbosity minimal

- name: Test (Unit) with Coverage
run: |
dotnet test Tests/LyricsScraperNET.UnitTest \
--configuration Release \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults \
--settings coverlet.runsettings
-- \
--coverage --coverage-output-format cobertura

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@v7
with:
files: ./TestResults/**/*.cobertura.xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

# Temporarily switched off. There are errors during CI.
# - name: Test (Integration)
# run: dotnet test Tests/LyricsScraperNET.IntegrationTest

- name: Publish to NuGET
run: ./publish.sh
if: startsWith( github.ref, 'refs/tags/')
env:
NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }}

- name: Publish to GH Release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v3
if: startsWith( github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: LyricsScraperNET ${{ github.ref }}
name: LyricsScraperNET ${{ github.ref_name }}
body: |
TODO
draft: true
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload to GH Release
if: startsWith( github.ref, 'refs/tags/')
run: |
zip -j LyricsScraperNET-netstandard2.0.zip LyricsScraperNET/bin/Release/netstandard2.0/*
zip -j LyricsScraperNET-netstandard2.1.zip LyricsScraperNET/bin/Release/netstandard2.1/*
zip -j LyricsScraperNET-net5.0.zip LyricsScraperNET/bin/Release/net5.0/*
zip -j LyricsScraperNET-net6.0.zip LyricsScraperNET/bin/Release/net6.0/*
zip -j LyricsScraperNET-net7.0.zip LyricsScraperNET/bin/Release/net7.0/*
zip -j LyricsScraperNET-net8.0.zip LyricsScraperNET/bin/Release/net8.0/*
zip -j LyricsScraperNET-net9.0.zip LyricsScraperNET/bin/Release/net9.0/*
zip -j LyricsScraperNET-net10.0.zip LyricsScraperNET/bin/Release/net10.0/*
gh release upload "$RELEASE_VERSION" \
"LyricsScraperNET-netstandard2.0.zip" \
"LyricsScraperNET-netstandard2.1.zip" \
"LyricsScraperNET-net5.0.zip" \
"LyricsScraperNET-net6.0.zip" \
"LyricsScraperNET-net7.0.zip" \
"LyricsScraperNET-net8.0.zip" \
"LyricsScraperNET-net9.0.zip" \
"LyricsScraperNET-net10.0.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 8 additions & 8 deletions LyricsScraperNET.Client/LyricsScraperNET.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.11" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions LyricsScraperNET.Client/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"LyricsFreakOptions": {
"SearchPriority": 3,
"Enabled": true
},
"LrclibOptions": {
"SearchPriority": 7,
"Enabled": true
}
}
}
5 changes: 4 additions & 1 deletion LyricsScraperNET/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ internal static class Constants
{ ExternalProviderType.SongLyrics, 4},
{ ExternalProviderType.LyricFind, 1},
{ ExternalProviderType.KPopLyrics, 2},
{ ExternalProviderType.LyricsFreak, 3}
{ ExternalProviderType.LyricsFreak, 3},
{ ExternalProviderType.Lrclib, 7}
};

internal const string LibraryUserAgent = "LyricsScraperNET/1.0 (https://github.com/skuill/LyricsScraperNET)";

internal static class ResponseMessages
{
internal static readonly string ExternalProvidersListIsEmpty = "Empty external providers list! Please set any external provider first";
Expand Down
2 changes: 2 additions & 0 deletions LyricsScraperNET/Configuration/ILyricScraperClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public interface ILyricScraperClientConfig
IExternalProviderOptions KPopLyricsOptions { get; }

IExternalProviderOptions LyricsFreakOptions { get; }

IExternalProviderOptions LrclibOptions { get; }
}
}
6 changes: 5 additions & 1 deletion LyricsScraperNET/Configuration/LyricScraperClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using LyricsScraperNET.Providers.Genius;
using LyricsScraperNET.Providers.KPopLyrics;
using LyricsScraperNET.Providers.LyricFind;
using LyricsScraperNET.Providers.Lrclib;
using LyricsScraperNET.Providers.LyricsFreak;
using LyricsScraperNET.Providers.Musixmatch;
using LyricsScraperNET.Providers.SongLyrics;
Expand All @@ -29,6 +30,8 @@ public sealed class LyricScraperClientConfig : ILyricScraperClientConfig

public IExternalProviderOptions LyricsFreakOptions { get; set; } = new LyricsFreakOptions();

public IExternalProviderOptions LrclibOptions { get; set; } = new LrclibOptions();

/// <inheritdoc />
public bool UseParallelSearch { get; set; } = false;

Expand All @@ -39,6 +42,7 @@ public sealed class LyricScraperClientConfig : ILyricScraperClientConfig
|| SongLyricsOptions.Enabled
|| LyricFindOptions.Enabled
|| KPopLyricsOptions.Enabled
|| LyricsFreakOptions.Enabled;
|| LyricsFreakOptions.Enabled
|| LrclibOptions.Enabled;
}
}
8 changes: 8 additions & 0 deletions LyricsScraperNET/Configuration/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using LyricsScraperNET.Providers.Genius;
using LyricsScraperNET.Providers.KPopLyrics;
using LyricsScraperNET.Providers.LyricFind;
using LyricsScraperNET.Providers.Lrclib;
using LyricsScraperNET.Providers.LyricsFreak;
using LyricsScraperNET.Providers.Musixmatch;
using LyricsScraperNET.Providers.SongLyrics;
Expand All @@ -13,8 +14,14 @@

namespace LyricsScraperNET.Configuration
{
/// <summary>
/// Extension methods for configuring the LyricsScraperNET services in the DI container.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds the LyricsScraperNET services to the service collection with automatic provider discovery.
/// </summary>
public static IServiceCollection AddLyricScraperClientService(
this IServiceCollection services,
IConfiguration configuration)
Expand All @@ -28,6 +35,7 @@ public static IServiceCollection AddLyricScraperClientService(
services.AddProvider<SongLyricsOptions, SongLyricsProvider>(lyricScraperClientConfig);
services.AddProvider<LyricFindOptions, LyricFindProvider>(lyricScraperClientConfig);
services.AddProvider<KPopLyricsOptions, KPopLyricsProvider>(lyricScraperClientConfig);
services.AddProvider<LrclibOptions, LrclibProvider>(lyricScraperClientConfig);

services.AddMusixmatchService(lyricScraperClientConfig);

Expand Down
10 changes: 9 additions & 1 deletion LyricsScraperNET/Extensions/LyricsScraperClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using LyricsScraperNET.Providers.Genius;
using LyricsScraperNET.Providers.KPopLyrics;
using LyricsScraperNET.Providers.LyricFind;
using LyricsScraperNET.Providers.Lrclib;
using LyricsScraperNET.Providers.LyricsFreak;
using LyricsScraperNET.Providers.Models;
using LyricsScraperNET.Providers.Musixmatch;
Expand Down Expand Up @@ -53,6 +54,12 @@ public static ILyricsScraperClient WithLyricsFreak(this ILyricsScraperClient lyr
return lyricsScraperClient;
}

public static ILyricsScraperClient WithLrclib(this ILyricsScraperClient lyricsScraperClient)
{
lyricsScraperClient.AddProvider(new LrclibProvider());
return lyricsScraperClient;
}

/// <summary>
/// Configure LyricsScraperClient with all available providers in <seealso cref="ExternalProviderType"/>.
/// Search lyrics enabled by default for all providers.
Expand All @@ -66,7 +73,8 @@ public static ILyricsScraperClient WithAllProviders(this ILyricsScraperClient ly
.WithSongLyrics()
.WithLyricFind()
.WithKPopLyrics()
.WithLyricsFreak();
.WithLyricsFreak()
.WithLrclib();
}
}
}
21 changes: 10 additions & 11 deletions LyricsScraperNET/LyricsScraperNET.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<PackageId>LyricsScraperNET</PackageId>
<Title>LyricsScraperNET</Title>
Expand All @@ -28,16 +28,15 @@

<ItemGroup>
<PackageReference Include="Genius.NET" Version="4.0.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="MusixmatchClientLib" Version="1.1.8" />
<PackageReference Include="HtmlAgilityPack" Version="1.13.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.11" />
<PackageReference Include="MusixmatchClientLib" Version="1.1.9" />
<PackageReference Include="Sigil" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.11" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions LyricsScraperNET/Network/HtmlAgilityWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ internal sealed class HtmlAgilityWebClient : IWebClient

public HtmlAgilityWebClient()
{
_htmlWeb = new HtmlWeb();
_htmlWeb.UsingCache = false;
_htmlWeb = new HtmlWeb
{
UsingCache = false
};
}

public HtmlAgilityWebClient(ILogger<HtmlAgilityWebClient> logger) : this()
Expand Down
7 changes: 1 addition & 6 deletions LyricsScraperNET/Providers/AZLyrics/AZLyricsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ public override bool Equals(object? obj)

public override int GetHashCode()
{
unchecked
{
int hash = 17;
hash = (hash * 31) + ExternalProviderType.GetHashCode();
return hash;
}
return System.HashCode.Combine(ExternalProviderType);
}
}
}
36 changes: 16 additions & 20 deletions LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
{
public abstract class ExternalProviderBase : IExternalProvider
{
internal IExternalProviderLyricParser Parser { get; set; }

Check warning on line 13 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'Parser' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'Parser' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'Parser' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'Parser' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'Parser' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'Parser' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'Parser' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'Parser' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
internal IWebClient WebClient { get; set; }

Check warning on line 14 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'WebClient' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'WebClient' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'WebClient' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'WebClient' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'WebClient' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in LyricsScraperNET/Providers/Abstract/ExternalProviderBase.cs

View workflow job for this annotation

GitHub Actions / lyrics_scraper_net-cicd

Non-nullable property 'WebClient' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public virtual IExternalProviderOptions Options => throw new NotImplementedException();

Expand All @@ -27,15 +27,14 @@
if (!IsEnabled)
return new SearchResult();

switch (searchRequest)
return searchRequest switch
{
case ArtistAndSongSearchRequest artistAndSongSearchRequest:
return SearchLyric(artistAndSongSearchRequest.Artist, artistAndSongSearchRequest.Song, cancellationToken);
case UriSearchRequest uriSearchRequest:
return SearchLyric(uriSearchRequest.Uri, cancellationToken);
default:
return new SearchResult();
}
ArtistAndSongSearchRequest artistAndSongSearchRequest
=> SearchLyric(artistAndSongSearchRequest.Artist, artistAndSongSearchRequest.Song, cancellationToken),
UriSearchRequest uriSearchRequest
=> SearchLyric(uriSearchRequest.Uri, cancellationToken),
_ => new SearchResult(),
};
}

protected virtual SearchResult SearchLyric(Uri uri, CancellationToken cancellationToken = default)
Expand All @@ -53,15 +52,14 @@
if (!IsEnabled)
return new SearchResult();

switch (searchRequest)
return searchRequest switch
{
case ArtistAndSongSearchRequest artistAndSongSearchRequest:
return await SearchLyricAsync(artistAndSongSearchRequest.Artist, artistAndSongSearchRequest.Song, cancellationToken);
case UriSearchRequest uriSearchRequest:
return await SearchLyricAsync(uriSearchRequest.Uri, cancellationToken);
default:
return new SearchResult();
}
ArtistAndSongSearchRequest artistAndSongSearchRequest
=> await SearchLyricAsync(artistAndSongSearchRequest.Artist, artistAndSongSearchRequest.Song, cancellationToken),
UriSearchRequest uriSearchRequest
=> await SearchLyricAsync(uriSearchRequest.Uri, cancellationToken),
_ => new SearchResult(),
};
}

protected virtual Task<SearchResult> SearchLyricAsync(Uri uri, CancellationToken cancellationToken = default)
Expand All @@ -86,14 +84,12 @@

public void Enable()
{
if (Options != null)
Options.Enabled = true;
Options?.Enabled = true;
}

public void Disable()
{
if (Options != null)
Options.Enabled = false;
Options?.Enabled = false;
}

public virtual void WithLogger(ILoggerFactory loggerFactory)
Expand Down
Loading
Loading