This commit is contained in:
gnattu 2024-05-04 11:06:54 -06:00 committed by GitHub
commit 092e269f97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 8 deletions

View File

@ -122,13 +122,15 @@ namespace MediaBrowser.Providers.MediaInfo
audio.Size = mediaInfo.Size;
audio.PremiereDate = mediaInfo.PremiereDate;
if (!audio.IsLocked)
{
await FetchDataFromTags(audio, mediaInfo, options).ConfigureAwait(false);
}
// Add external lyrics first to prevent the lrc file get overwritten on first scan
var mediaStreams = new List<MediaStream>(mediaInfo.MediaStreams);
AddExternalLyrics(audio, mediaStreams, options);
var tryExtractEmbeddedLyrics = mediaStreams.All(s => s.Type != MediaStreamType.Lyric);
if (!audio.IsLocked)
{
await FetchDataFromTags(audio, mediaInfo, options, tryExtractEmbeddedLyrics).ConfigureAwait(false);
}
audio.HasLyrics = mediaStreams.Any(s => s.Type == MediaStreamType.Lyric);
@ -141,7 +143,8 @@ namespace MediaBrowser.Providers.MediaInfo
/// <param name="audio">The <see cref="Audio"/>.</param>
/// <param name="mediaInfo">The <see cref="Model.MediaInfo.MediaInfo"/>.</param>
/// <param name="options">The <see cref="MetadataRefreshOptions"/>.</param>
private async Task FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo mediaInfo, MetadataRefreshOptions options)
/// <param name="tryExtractEmbeddedLyrics">Whether to extract embedded lyrics to lrc file. </param>
private async Task FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo mediaInfo, MetadataRefreshOptions options, bool tryExtractEmbeddedLyrics)
{
using var file = TagLib.File.Create(audio.Path);
var tagTypes = file.TagTypesOnDisk;
@ -321,9 +324,9 @@ namespace MediaBrowser.Providers.MediaInfo
}
// Save extracted lyrics if they exist,
// and if we are replacing all metadata or the audio doesn't yet have lyrics.
// and if the audio doesn't yet have lyrics.
if (!string.IsNullOrWhiteSpace(tags.Lyrics)
&& (options.ReplaceAllMetadata || audio.GetMediaStreams().All(s => s.Type != MediaStreamType.Lyric)))
&& tryExtractEmbeddedLyrics)
{
await _lyricManager.SaveLyricAsync(audio, "lrc", tags.Lyrics).ConfigureAwait(false);
}