From b4405b06009ed07926f83df52425384a28a2146f Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Mon, 27 Apr 2020 19:08:14 +0200 Subject: [PATCH] Fixed: Parsing release group from file rather than folder in case of season packs --- .../AggregateReleaseGroupFixture.cs | 122 ++++++++++++++++++ .../Aggregators/AggregateReleaseGroup.cs | 27 +++- 2 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseGroupFixture.cs diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseGroupFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseGroupFixture.cs new file mode 100644 index 000000000..b3f774e96 --- /dev/null +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseGroupFixture.cs @@ -0,0 +1,122 @@ + +using System.Collections.Generic; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators; +using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators +{ + [TestFixture] + public class AggregateReleaseGroupFixture : CoreTest + { + private Series _series; + + [SetUp] + public void Setup() + { + _series = Builder.CreateNew().Build(); + } + + [Test] + public void should_not_use_downloadclient_for_full_season() + { + var fileEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL-Wizzy"); + var downloadClientEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01.WEB-DL-Viva"); + var localEpisode = new LocalEpisode + { + FileEpisodeInfo = fileEpisodeInfo, + DownloadClientEpisodeInfo = downloadClientEpisodeInfo, + Path = @"C:\Test\Unsorted TV\Series.Title.S01\Series.Title.S01E01.WEB-DL.mkv".AsOsAgnostic(), + Series = _series + }; + + Subject.Aggregate(localEpisode, false); + + localEpisode.ReleaseGroup.Should().Be("Wizzy"); + } + + [Test] + public void should_not_use_folder_for_full_season() + { + var fileEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL-Wizzy"); + var folderEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01.WEB-DL-Drone"); + var localEpisode = new LocalEpisode + { + FileEpisodeInfo = fileEpisodeInfo, + FolderEpisodeInfo = folderEpisodeInfo, + Path = @"C:\Test\Unsorted TV\Series.Title.S01\Series.Title.S01E01.WEB-DL.mkv".AsOsAgnostic(), + Series = _series + }; + + Subject.Aggregate(localEpisode, false); + + localEpisode.ReleaseGroup.Should().Be("Wizzy"); + } + + [Test] + public void should_prefer_downloadclient() + { + var fileEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL-Wizzy"); + var folderEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL-Drone"); + var downloadClientEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL-Viva"); + var localEpisode = new LocalEpisode + { + FileEpisodeInfo = fileEpisodeInfo, + FolderEpisodeInfo = folderEpisodeInfo, + DownloadClientEpisodeInfo = downloadClientEpisodeInfo, + Path = @"C:\Test\Unsorted TV\Series.Title.S01\Series.Title.S01E01.WEB-DL.mkv".AsOsAgnostic(), + Series = _series + }; + + Subject.Aggregate(localEpisode, false); + + localEpisode.ReleaseGroup.Should().Be("Viva"); + } + + [Test] + public void should_prefer_folder() + { + var fileEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL-Wizzy"); + var folderEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL-Drone"); + var downloadClientEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL"); + var localEpisode = new LocalEpisode + { + FileEpisodeInfo = fileEpisodeInfo, + FolderEpisodeInfo = folderEpisodeInfo, + DownloadClientEpisodeInfo = downloadClientEpisodeInfo, + Path = @"C:\Test\Unsorted TV\Series.Title.S01\Series.Title.S01E01.WEB-DL.mkv".AsOsAgnostic(), + Series = _series + }; + + Subject.Aggregate(localEpisode, false); + + localEpisode.ReleaseGroup.Should().Be("Drone"); + } + + [Test] + public void should_fallback_to_file() + { + var fileEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL-Wizzy"); + var folderEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL"); + var downloadClientEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.WEB-DL"); + var localEpisode = new LocalEpisode + { + FileEpisodeInfo = fileEpisodeInfo, + FolderEpisodeInfo = folderEpisodeInfo, + DownloadClientEpisodeInfo = downloadClientEpisodeInfo, + Path = @"C:\Test\Unsorted TV\Series.Title.S01\Series.Title.S01E01.mkv".AsOsAgnostic(), + Series = _series + }; + + Subject.Aggregate(localEpisode, false); + + localEpisode.ReleaseGroup.Should().Be("Wizzy"); + } + } +} diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseGroup.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseGroup.cs index a919320b8..470269487 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseGroup.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseGroup.cs @@ -7,21 +7,42 @@ public class AggregateReleaseGroup : IAggregateLocalEpisode { public LocalEpisode Aggregate(LocalEpisode localEpisode, bool otherFiles) { - var releaseGroup = localEpisode.DownloadClientEpisodeInfo?.ReleaseGroup; + // Prefer ReleaseGroup from DownloadClient/Folder if they're not a season pack + var releaseGroup = GetReleaseGroup(localEpisode.DownloadClientEpisodeInfo, true); if (releaseGroup.IsNullOrWhiteSpace()) { - releaseGroup = localEpisode.FolderEpisodeInfo?.ReleaseGroup; + releaseGroup = GetReleaseGroup(localEpisode.FolderEpisodeInfo, true); } if (releaseGroup.IsNullOrWhiteSpace()) { - releaseGroup = localEpisode.FileEpisodeInfo?.ReleaseGroup; + releaseGroup = GetReleaseGroup(localEpisode.FileEpisodeInfo, false); } + if (releaseGroup.IsNullOrWhiteSpace()) + { + releaseGroup = GetReleaseGroup(localEpisode.DownloadClientEpisodeInfo, false); + } + + if (releaseGroup.IsNullOrWhiteSpace()) + { + releaseGroup = GetReleaseGroup(localEpisode.FolderEpisodeInfo, false); + } + localEpisode.ReleaseGroup = releaseGroup; return localEpisode; } + + private string GetReleaseGroup(ParsedEpisodeInfo episodeInfo, bool skipFullSeason) + { + if (episodeInfo == null || episodeInfo.FullSeason && skipFullSeason) + { + return null; + } + + return episodeInfo.ReleaseGroup; + } } }