From d5dc4435d9d0e2a1bbbb64a9133134afa9655da6 Mon Sep 17 00:00:00 2001 From: Nathan McCrina Date: Tue, 14 May 2024 22:28:29 -0500 Subject: [PATCH] Handle exception for unexpected audio file YEAR tag values (#11621) --- CONTRIBUTORS.md | 1 + .../MediaInfo/AudioFileProber.cs | 14 +++++++++++++- MediaBrowser.Providers/MediaInfo/ProbeProvider.cs | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8550222a16..47c06998c0 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -255,3 +255,4 @@ - [JPUC1143](https://github.com/Jpuc1143/) - [0x25CBFC4F](https://github.com/0x25CBFC4F) - [Robert Lützner](https://github.com/rluetzner) + - [Nathan McCrina](https://github.com/nfmccrina) diff --git a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs index 9f37d8b549..34681fac86 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs @@ -15,6 +15,7 @@ using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.MediaInfo; +using Microsoft.Extensions.Logging; using TagLib; namespace MediaBrowser.Providers.MediaInfo @@ -27,6 +28,7 @@ namespace MediaBrowser.Providers.MediaInfo private readonly IMediaEncoder _mediaEncoder; private readonly IItemRepository _itemRepo; private readonly ILibraryManager _libraryManager; + private readonly ILogger _logger; private readonly IMediaSourceManager _mediaSourceManager; private readonly LyricResolver _lyricResolver; private readonly ILyricManager _lyricManager; @@ -34,6 +36,7 @@ namespace MediaBrowser.Providers.MediaInfo /// /// Initializes a new instance of the class. /// + /// Instance of the interface. /// Instance of the interface. /// Instance of the interface. /// Instance of the interface. @@ -41,6 +44,7 @@ namespace MediaBrowser.Providers.MediaInfo /// Instance of the interface. /// Instance of the interface. public AudioFileProber( + ILogger logger, IMediaSourceManager mediaSourceManager, IMediaEncoder mediaEncoder, IItemRepository itemRepo, @@ -51,6 +55,7 @@ namespace MediaBrowser.Providers.MediaInfo _mediaEncoder = mediaEncoder; _itemRepo = itemRepo; _libraryManager = libraryManager; + _logger = logger; _mediaSourceManager = mediaSourceManager; _lyricResolver = lyricResolver; _lyricManager = lyricManager; @@ -276,7 +281,14 @@ namespace MediaBrowser.Providers.MediaInfo if (!audio.PremiereDate.HasValue) { - audio.PremiereDate = new DateTime(year, 01, 01); + try + { + audio.PremiereDate = new DateTime(year, 01, 01); + } + catch (ArgumentOutOfRangeException ex) + { + _logger.LogError(ex, "Error parsing YEAR tag in {File}. '{TagValue}' is an invalid year.", audio.Path, tags.Year); + } } } diff --git a/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs index b330b419bd..8bb8d5bb4c 100644 --- a/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs @@ -103,6 +103,7 @@ namespace MediaBrowser.Providers.MediaInfo _subtitleResolver); _audioProber = new AudioFileProber( + loggerFactory.CreateLogger(), mediaSourceManager, mediaEncoder, itemRepo,