Skip to content

Commit 11c1de9

Browse files
authored
Merge pull request #49 from skuill/bugfix/47_azlyrics_malformed
#47 Fix AZLyrics provider search to support new script tag
2 parents 14a5702 + ec1b4c1 commit 11c1de9

File tree

2 files changed

+139
-68
lines changed

2 files changed

+139
-68
lines changed

LyricsScraperNET/Providers/AZLyrics/AZLyricsProvider.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.Extensions.Logging.Abstractions;
77
using Microsoft.Extensions.Options;
88
using System;
9+
using System.Linq;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112

@@ -17,7 +18,7 @@ public sealed class AZLyricsProvider : ExternalProviderBase
1718
private readonly IExternalUriConverter _uriConverter;
1819

1920
private const string _lyricStart = "<!-- Usage of azlyrics.com content by any third-party lyrics provider is prohibited by our licensing agreement. Sorry about that. -->";
20-
private const string _lyricEnd = "<!-- MxM banner -->";
21+
private readonly string[] _lyricEnds = new[] { "<!-- MxM banner -->", "/* JamX - AZLyrics.com - Podcasts */" };
2122

2223
#region Constructors
2324

@@ -114,13 +115,18 @@ private SearchResult PostProcessLyric(Uri uri, string text)
114115
}
115116

116117
var startIndex = text.IndexOf(_lyricStart);
117-
var endIndex = text.IndexOf(_lyricEnd);
118-
if (startIndex <= 0 || endIndex <= 0)
118+
if (startIndex <= 0)
119119
{
120120
_logger?.LogWarning($"AZLyrics. Can't find lyrics for Uri: [{uri}]");
121121
return new SearchResult(Models.ExternalProviderType.AZLyrics);
122122
}
123-
string result = Parser.Parse(text.Substring(startIndex, endIndex - startIndex));
123+
var endIndices = _lyricEnds.Select(i => text.IndexOf(i, startIndex)).Where(i => i > 0);
124+
if (endIndices == null || !endIndices.Any())
125+
{
126+
_logger?.LogWarning($"AZLyrics. Can't find lyrics for Uri: [{uri}]");
127+
return new SearchResult(Models.ExternalProviderType.AZLyrics);
128+
}
129+
string result = Parser.Parse(text.Substring(startIndex, endIndices.Min() - startIndex));
124130

125131
return new SearchResult(result, Models.ExternalProviderType.AZLyrics);
126132
}

0 commit comments

Comments
 (0)