66using Microsoft . Extensions . Logging . Abstractions ;
77using Microsoft . Extensions . Options ;
88using System ;
9+ using System . Linq ;
910using System . Threading ;
1011using 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