99using MediaBrowser . Controller . Entities . Audio ;
1010using MediaBrowser . Controller . Library ;
1111using MediaBrowser . Controller . Lyrics ;
12+ using MediaBrowser . Controller . MediaEncoding ;
1213using MediaBrowser . Model . Entities ;
1314using MediaBrowser . Model . Globalization ;
1415using MediaBrowser . Model . Tasks ;
@@ -32,6 +33,7 @@ public class LyricDownloadTask : IScheduledTask
3233 private readonly ILyricManager _lyricManager ;
3334 private readonly ILogger < LyricDownloadTask > _logger ;
3435 private readonly ILocalizationManager _localizationManager ;
36+ private readonly IMediaSourceManager _mediaSourceManager ;
3537
3638 /// <summary>
3739 /// Initializes a new instance of the <see cref="LyricDownloadTask"/> class.
@@ -40,16 +42,19 @@ public class LyricDownloadTask : IScheduledTask
4042 /// <param name="lyricManager">Instance of the <see cref="ILyricManager"/> interface.</param>
4143 /// <param name="logger">Instance of the <see cref="ILogger{DownloaderScheduledTask}"/> interface.</param>
4244 /// <param name="localizationManager">Instance of the <see cref="ILocalizationManager"/> interface.</param>
45+ /// <param name="mediaSourceManager">Instance of the <see cref="IMediaSourceManager"/> interface.</param>
4346 public LyricDownloadTask (
4447 ILibraryManager libraryManager ,
4548 ILyricManager lyricManager ,
4649 ILogger < LyricDownloadTask > logger ,
47- ILocalizationManager localizationManager )
50+ ILocalizationManager localizationManager ,
51+ IMediaSourceManager mediaSourceManager )
4852 {
4953 _libraryManager = libraryManager ;
5054 _lyricManager = lyricManager ;
5155 _logger = logger ;
5256 _localizationManager = localizationManager ;
57+ _mediaSourceManager = mediaSourceManager ;
5358 }
5459
5560 /// <inheritdoc />
@@ -94,7 +99,10 @@ public async Task ExecuteAsync(IProgress<double> progress, CancellationToken can
9499
95100 try
96101 {
97- if ( audioItem . MediaStreams . All ( s => s . Type != MediaStreamType . Lyric ) )
102+ var mediaSources = await _mediaSourceManager . GetPlaybackMediaSources ( audioItem , null , false , false , cancellationToken ) . ConfigureAwait ( false ) ;
103+ var hasLyrics = mediaSources . Any ( ms => ms . MediaStreams . Any ( s => s . Type == MediaStreamType . Lyric ) ) ;
104+
105+ if ( ! hasLyrics )
98106 {
99107 _logger . LogDebug ( "Searching for lyrics for {Path}" , audioItem . Path ) ;
100108 var lyricResults = await _lyricManager . SearchLyricsAsync ( audioItem , true , cancellationToken ) . ConfigureAwait ( false ) ;
0 commit comments