@@ -68,10 +68,11 @@ public async Task<IEnumerable<RemoteLyricInfo>> SearchAsync(
6868 }
6969 catch ( HttpRequestException ex )
7070 {
71+ var artist = request . ArtistNames is { Count : > 0 } ? request . ArtistNames [ 0 ] : null ;
7172 _logger . LogDebug (
7273 ex ,
7374 "Unable to get results for {Artist} - {Album} - {Song}" ,
74- request . ArtistNames ? [ 0 ] ,
75+ artist ,
7576 request . AlbumName ,
7677 request . SongName ) ;
7778 return Enumerable . Empty < RemoteLyricInfo > ( ) ;
@@ -82,6 +83,13 @@ public async Task<IEnumerable<RemoteLyricInfo>> SearchAsync(
8283 public async Task < LyricResponse ? > GetLyricsAsync ( string id , CancellationToken cancellationToken )
8384 {
8485 var splitId = id . Split ( '_' , 2 ) ;
86+ if ( splitId . Length != 2
87+ || string . IsNullOrWhiteSpace ( splitId [ 0 ] )
88+ || ! IsSupportedLyricSuffix ( splitId [ 1 ] ) )
89+ {
90+ _logger . LogDebug ( "Invalid lyric id format: {Id}" , id ) ;
91+ throw new ResourceNotFoundException ( $ "Unable to get results for id { id } ") ;
92+ }
8593
8694 try
8795 {
@@ -95,7 +103,7 @@ public async Task<IEnumerable<RemoteLyricInfo>> SearchAsync(
95103 . ConfigureAwait ( false ) ;
96104 if ( response is null )
97105 {
98- throw new ResourceNotFoundException ( "Unable to get results for id {Id }" ) ;
106+ throw new ResourceNotFoundException ( $ "Unable to get results for id { id } ") ;
99107 }
100108
101109 if ( string . Equals ( splitId [ 1 ] , SyncedSuffix , StringComparison . OrdinalIgnoreCase )
@@ -120,18 +128,24 @@ public async Task<IEnumerable<RemoteLyricInfo>> SearchAsync(
120128 } ;
121129 }
122130
123- throw new ResourceNotFoundException ( "Unable to get results for id {Id }" ) ;
131+ throw new ResourceNotFoundException ( $ "Unable to get results for id { id } ") ;
124132 }
125133 catch ( HttpRequestException ex )
126134 {
127135 _logger . LogDebug (
128136 ex ,
129137 "Unable to get results for id {Id}" ,
130138 id ) ;
131- throw new ResourceNotFoundException ( "Unable to get results for id {Id }" ) ;
139+ throw new ResourceNotFoundException ( $ "Unable to get results for id { id } ") ;
132140 }
133141 }
134142
143+ private static bool IsSupportedLyricSuffix ( string suffix )
144+ {
145+ return string . Equals ( suffix , SyncedSuffix , StringComparison . OrdinalIgnoreCase )
146+ || string . Equals ( suffix , PlainSuffix , StringComparison . OrdinalIgnoreCase ) ;
147+ }
148+
135149 private async Task < IEnumerable < RemoteLyricInfo > > GetExactMatch (
136150 LyricSearchRequest request ,
137151 CancellationToken cancellationToken )
@@ -319,4 +333,4 @@ private List<RemoteLyricInfo> GetRemoteLyrics(LyricsSearchResponse response)
319333
320334 return results ;
321335 }
322- }
336+ }
0 commit comments