Fix external LRC files being incorrectly overwritten during the initial scan (#11480)

pull/11495/head
gnattu 8 months ago committed by GitHub
parent 4aad655fa8
commit cf483203f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -122,14 +122,16 @@ namespace MediaBrowser.Providers.MediaInfo
audio.Size = mediaInfo.Size; audio.Size = mediaInfo.Size;
audio.PremiereDate = mediaInfo.PremiereDate; 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);
var tryExtractEmbeddedLyrics = mediaStreams.All(s => s.Type != MediaStreamType.Lyric);
if (!audio.IsLocked) if (!audio.IsLocked)
{ {
await FetchDataFromTags(audio, mediaInfo, options).ConfigureAwait(false); await FetchDataFromTags(audio, mediaInfo, options, tryExtractEmbeddedLyrics).ConfigureAwait(false);
} }
var mediaStreams = new List<MediaStream>(mediaInfo.MediaStreams);
AddExternalLyrics(audio, mediaStreams, options);
audio.HasLyrics = mediaStreams.Any(s => s.Type == MediaStreamType.Lyric); audio.HasLyrics = mediaStreams.Any(s => s.Type == MediaStreamType.Lyric);
_itemRepo.SaveMediaStreams(audio.Id, mediaStreams, cancellationToken); _itemRepo.SaveMediaStreams(audio.Id, mediaStreams, cancellationToken);
@ -141,7 +143,8 @@ namespace MediaBrowser.Providers.MediaInfo
/// <param name="audio">The <see cref="Audio"/>.</param> /// <param name="audio">The <see cref="Audio"/>.</param>
/// <param name="mediaInfo">The <see cref="Model.MediaInfo.MediaInfo"/>.</param> /// <param name="mediaInfo">The <see cref="Model.MediaInfo.MediaInfo"/>.</param>
/// <param name="options">The <see cref="MetadataRefreshOptions"/>.</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); using var file = TagLib.File.Create(audio.Path);
var tagTypes = file.TagTypesOnDisk; var tagTypes = file.TagTypesOnDisk;
@ -321,9 +324,9 @@ namespace MediaBrowser.Providers.MediaInfo
} }
// Save extracted lyrics if they exist, // 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) 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); await _lyricManager.SaveLyricAsync(audio, "lrc", tags.Lyrics).ConfigureAwait(false);
} }

Loading…
Cancel
Save