diff --git a/LyricsScraperNET/Providers/AZLyrics/AZLyricsProvider.cs b/LyricsScraperNET/Providers/AZLyrics/AZLyricsProvider.cs index f47f518..1e4e850 100644 --- a/LyricsScraperNET/Providers/AZLyrics/AZLyricsProvider.cs +++ b/LyricsScraperNET/Providers/AZLyrics/AZLyricsProvider.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -17,7 +18,7 @@ public sealed class AZLyricsProvider : ExternalProviderBase private readonly IExternalUriConverter _uriConverter; private const string _lyricStart = ""; - private const string _lyricEnd = ""; + private readonly string[] _lyricEnds = new[] { "", "/* JamX - AZLyrics.com - Podcasts */" }; #region Constructors @@ -114,13 +115,18 @@ private SearchResult PostProcessLyric(Uri uri, string text) } var startIndex = text.IndexOf(_lyricStart); - var endIndex = text.IndexOf(_lyricEnd); - if (startIndex <= 0 || endIndex <= 0) + if (startIndex <= 0) { _logger?.LogWarning($"AZLyrics. Can't find lyrics for Uri: [{uri}]"); return new SearchResult(Models.ExternalProviderType.AZLyrics); } - string result = Parser.Parse(text.Substring(startIndex, endIndex - startIndex)); + var endIndices = _lyricEnds.Select(i => text.IndexOf(i, startIndex)).Where(i => i > 0); + if (endIndices == null || !endIndices.Any()) + { + _logger?.LogWarning($"AZLyrics. Can't find lyrics for Uri: [{uri}]"); + return new SearchResult(Models.ExternalProviderType.AZLyrics); + } + string result = Parser.Parse(text.Substring(startIndex, endIndices.Min() - startIndex)); return new SearchResult(result, Models.ExternalProviderType.AZLyrics); } diff --git a/Tests/LyricsScraperNET.UnitTest/Providers/AZLyrics/Resources/Lyrics_HtmlPage_01.txt b/Tests/LyricsScraperNET.UnitTest/Providers/AZLyrics/Resources/Lyrics_HtmlPage_01.txt index cae4820..be88cce 100644 --- a/Tests/LyricsScraperNET.UnitTest/Providers/AZLyrics/Resources/Lyrics_HtmlPage_01.txt +++ b/Tests/LyricsScraperNET.UnitTest/Providers/AZLyrics/Resources/Lyrics_HtmlPage_01.txt @@ -10,6 +10,7 @@ Parkway Drive - Wishing Wells Lyrics | AZLyrics.com + @@ -18,17 +19,40 @@ + + + - - + + + + + + + + + + + + + + + - -
-
-
-
-
-
-
-
-
-