New: Reject files during import that have no audio tracks

(cherry picked from commit 978349e24135572889095c743d0e7fac734ba7e0)

Closes #10643
pull/10622/head
Mark McDowall 1 week ago committed by Bogdan
parent b4eff4d4f9
commit 5976d66511

@ -0,0 +1,61 @@
using System.IO;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.MediaFiles.MovieImport.Specifications;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
{
[TestFixture]
public class HasAudioTrackSpecificationFixture : CoreTest<HasAudioTrackSpecification>
{
private Movie _movie;
private LocalMovie _localMovie;
private string _rootFolder;
[SetUp]
public void Setup()
{
_rootFolder = @"C:\Test\Movies".AsOsAgnostic();
_movie = Builder<Movie>.CreateNew()
.With(s => s.Path = Path.Combine(_rootFolder, "Movie Title"))
.Build();
_localMovie = new LocalMovie
{
Path = @"C:\Test\Unsorted\Movie Title\movie.title.2000.avi".AsOsAgnostic(),
Movie = _movie
};
}
[Test]
public void should_accept_if_media_info_is_null()
{
_localMovie.MediaInfo = null;
Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_reject_if_audio_stream_count_is_0()
{
_localMovie.MediaInfo = Builder<MediaInfoModel>.CreateNew().With(m => m.AudioStreamCount = 0).Build();
Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeFalse();
}
[Test]
public void should_accept_if_audio_stream_count_is_0()
{
_localMovie.MediaInfo = Builder<MediaInfoModel>.CreateNew().With(m => m.AudioStreamCount = 1).Build();
Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeTrue();
}
}
}

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