Fix external LRC files being incorrectly overwritten during the initial scan

The external LRC should be added to the current stream first; otherwise, the initial scan will always overwrite the external LRC if that audio file also has an embedded lyric.

Now, such overwrite will only happen when the user explicitly requires replacing all metadata.

Signed-off-by: gnattu <gnattuoc@me.com>
pull/11480/head
gnattu 4 weeks ago
parent 45d9481f73
commit c3f9345e9f

@ -122,14 +122,15 @@ namespace MediaBrowser.Providers.MediaInfo
audio.Size = mediaInfo.Size;
audio.PremiereDate = mediaInfo.PremiereDate;
// 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);
if (!audio.IsLocked)
{
await FetchDataFromTags(audio, mediaInfo, options).ConfigureAwait(false);
await FetchDataFromTags(audio, mediaInfo, options, mediaStreams).ConfigureAwait(false);
}
var mediaStreams = new List<MediaStream>(mediaInfo.MediaStreams);
AddExternalLyrics(audio, mediaStreams, options);
audio.HasLyrics = mediaStreams.Any(s => s.Type == MediaStreamType.Lyric);
_itemRepo.SaveMediaStreams(audio.Id, mediaStreams, cancellationToken);
@ -141,7 +142,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="currentStreams"> Current audio streams. </param>
private async Task FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo mediaInfo, MetadataRefreshOptions options, IEnumerable<MediaStream> currentStreams)
{
using var file = TagLib.File.Create(audio.Path);
var tagTypes = file.TagTypesOnDisk;
@ -323,7 +325,7 @@ 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.
if (!string.IsNullOrWhiteSpace(tags.Lyrics)
&& (options.ReplaceAllMetadata || audio.GetMediaStreams().All(s => s.Type != MediaStreamType.Lyric)))
&& (options.ReplaceAllMetadata || currentStreams.All(s => s.Type != MediaStreamType.Lyric)))
{
await _lyricManager.SaveLyricAsync(audio, "lrc", tags.Lyrics).ConfigureAwait(false);
}

Loading…
Cancel
Save