1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-23 02:05:27 +02:00

New: Reject files during import that have no audio tracks

Closes #7298
This commit is contained in:
Mark McDowall 2024-11-03 14:43:50 -08:00 committed by Mark McDowall
parent a77bf64352
commit 978349e241
2 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,70 @@
using System.IO;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
{
[TestFixture]
public class HasAudioTrackSpecificationFixture : CoreTest<HasAudioTrackSpecification>
{
private Series _series;
private LocalEpisode _localEpisode;
private string _rootFolder;
[SetUp]
public void Setup()
{
_rootFolder = @"C:\Test\TV".AsOsAgnostic();
_series = Builder<Series>.CreateNew()
.With(s => s.SeriesType = SeriesTypes.Standard)
.With(s => s.Path = Path.Combine(_rootFolder, "30 Rock"))
.Build();
var episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.SeasonNumber = 1)
.Build()
.ToList();
_localEpisode = new LocalEpisode
{
Path = @"C:\Test\Unsorted\30 Rock\30.rock.s01e01.avi".AsOsAgnostic(),
Episodes = episodes,
Series = _series
};
}
[Test]
public void should_accept_if_media_info_is_null()
{
_localEpisode.MediaInfo = null;
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
}
[Test]
public void should_reject_if_audio_stream_count_is_0()
{
_localEpisode.MediaInfo = Builder<MediaInfoModel>.CreateNew().With(m => m.AudioStreamCount = 0).Build();
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
}
[Test]
public void should_accept_if_audio_stream_count_is_0()
{
_localEpisode.MediaInfo = Builder<MediaInfoModel>.CreateNew().With(m => m.AudioStreamCount = 1).Build();
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
}
}
}

View File

@ -0,0 +1,35 @@
using NLog;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
{
public class HasAudioTrackSpecification : IImportDecisionEngineSpecification
{
private readonly Logger _logger;
public HasAudioTrackSpecification(Logger logger)
{
_logger = logger;
}
public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem downloadClientItem)
{
if (localEpisode.MediaInfo == null)
{
_logger.Debug("Failed to get media info from the file, make sure ffprobe is available, skipping check");
return Decision.Accept();
}
if (localEpisode.MediaInfo.AudioStreamCount == 0)
{
_logger.Debug("No audio tracks found in file");
return Decision.Reject("No audio tracks detected");
}
return Decision.Accept();
}
}
}