1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-29 23:12:39 +01:00

Fixed: Calculating Custom Formats with languages in queue

This commit is contained in:
kephasdev 2024-08-18 22:00:55 -04:00 committed by GitHub
parent aa488019cf
commit 8af12cc4e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 240 additions and 10 deletions

View File

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Download.Aggregation.Aggregators;
using NzbDrone.Core.Indexers;
@ -65,11 +66,12 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators
}
[Test]
public void should_return_multi_languages_when_indexer_has_multi_languages_configuration()
public void should_return_multi_languages_when_indexer_id_has_multi_languages_configuration()
{
var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup";
var indexerDefinition = new IndexerDefinition
{
Id = 1,
Settings = new TorrentRssIndexerSettings { MultiLanguages = new List<int> { Language.Original.Id, Language.French.Id } }
};
Mocker.GetMock<IIndexerFactory>()
@ -81,6 +83,67 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators
_remoteEpisode.Release.Title = releaseTitle;
Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List<Language> { _series.OriginalLanguage, Language.French });
Mocker.GetMock<IIndexerFactory>().Verify(c => c.Get(1), Times.Once());
Mocker.GetMock<IIndexerFactory>().VerifyNoOtherCalls();
}
[Test]
public void should_return_multi_languages_from_indexer_with_id_when_indexer_id_and_name_are_set()
{
var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup";
var indexerDefinition1 = new IndexerDefinition
{
Id = 1,
Name = "MyIndexer1",
Settings = new TorrentRssIndexerSettings { MultiLanguages = new List<int> { Language.Original.Id, Language.French.Id } }
};
var indexerDefinition2 = new IndexerDefinition
{
Id = 2,
Name = "MyIndexer2",
Settings = new TorrentRssIndexerSettings { MultiLanguages = new List<int> { Language.Original.Id, Language.German.Id } }
};
Mocker.GetMock<IIndexerFactory>()
.Setup(v => v.Get(1))
.Returns(indexerDefinition1);
Mocker.GetMock<IIndexerFactory>()
.Setup(v => v.All())
.Returns(new List<IndexerDefinition>() { indexerDefinition1, indexerDefinition2 });
_remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List<Language> { }, releaseTitle);
_remoteEpisode.Release.IndexerId = 1;
_remoteEpisode.Release.Indexer = "MyIndexer2";
_remoteEpisode.Release.Title = releaseTitle;
Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List<Language> { _series.OriginalLanguage, Language.French });
Mocker.GetMock<IIndexerFactory>().Verify(c => c.Get(1), Times.Once());
Mocker.GetMock<IIndexerFactory>().VerifyNoOtherCalls();
}
[Test]
public void should_return_multi_languages_when_indexer_name_has_multi_languages_configuration()
{
var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup";
var indexerDefinition = new IndexerDefinition
{
Id = 1,
Name = "MyIndexer (Prowlarr)",
Settings = new TorrentRssIndexerSettings { MultiLanguages = new List<int> { Language.Original.Id, Language.French.Id } }
};
Mocker.GetMock<IIndexerFactory>()
.Setup(v => v.FindByName("MyIndexer (Prowlarr)"))
.Returns(indexerDefinition);
_remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List<Language> { }, releaseTitle);
_remoteEpisode.Release.Indexer = "MyIndexer (Prowlarr)";
_remoteEpisode.Release.Title = releaseTitle;
Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List<Language> { _series.OriginalLanguage, Language.French });
Mocker.GetMock<IIndexerFactory>().Verify(c => c.FindByName("MyIndexer (Prowlarr)"), Times.Once());
Mocker.GetMock<IIndexerFactory>().VerifyNoOtherCalls();
}
[Test]
@ -89,6 +152,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators
var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup";
var indexerDefinition = new IndexerDefinition
{
Id = 1,
Settings = new TorrentRssIndexerSettings { MultiLanguages = new List<int> { Language.Original.Id, Language.French.Id } }
};
Mocker.GetMock<IIndexerFactory>()
@ -100,6 +164,8 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators
_remoteEpisode.Release.Title = releaseTitle;
Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List<Language> { _series.OriginalLanguage, Language.French });
Mocker.GetMock<IIndexerFactory>().Verify(c => c.Get(1), Times.Once());
Mocker.GetMock<IIndexerFactory>().VerifyNoOtherCalls();
}
[Test]
@ -108,6 +174,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators
var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup";
var indexerDefinition = new IndexerDefinition
{
Id = 1,
Settings = new TorrentRssIndexerSettings { }
};
Mocker.GetMock<IIndexerFactory>()
@ -119,6 +186,20 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators
_remoteEpisode.Release.Title = releaseTitle;
Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List<Language> { _series.OriginalLanguage });
Mocker.GetMock<IIndexerFactory>().Verify(c => c.Get(1), Times.Once());
Mocker.GetMock<IIndexerFactory>().VerifyNoOtherCalls();
}
[Test]
public void should_return_original_when_no_indexer_value()
{
var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup";
_remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List<Language> { }, releaseTitle);
_remoteEpisode.Release.Title = releaseTitle;
Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List<Language> { _series.OriginalLanguage });
Mocker.GetMock<IIndexerFactory>().VerifyNoOtherCalls();
}
[Test]

View File

@ -7,6 +7,8 @@ using NzbDrone.Core.Download;
using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.History;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.TorrentRss;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
@ -84,6 +86,80 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads
trackedDownload.RemoteEpisode.MappedSeasonNumber.Should().Be(1);
}
[Test]
public void should_set_indexer()
{
var episodeHistory = new EpisodeHistory()
{
DownloadId = "35238",
SourceTitle = "TV Series S01",
SeriesId = 5,
EpisodeId = 4,
EventType = EpisodeHistoryEventType.Grabbed,
};
episodeHistory.Data.Add("indexer", "MyIndexer (Prowlarr)");
Mocker.GetMock<IHistoryService>()
.Setup(s => s.FindByDownloadId(It.Is<string>(sr => sr == "35238")))
.Returns(new List<EpisodeHistory>()
{
episodeHistory
});
var indexerDefinition = new IndexerDefinition
{
Id = 1,
Name = "MyIndexer (Prowlarr)",
Settings = new TorrentRssIndexerSettings { MultiLanguages = new List<int> { Language.Original.Id, Language.French.Id } }
};
Mocker.GetMock<IIndexerFactory>()
.Setup(v => v.Get(indexerDefinition.Id))
.Returns(indexerDefinition);
Mocker.GetMock<IIndexerFactory>()
.Setup(v => v.All())
.Returns(new List<IndexerDefinition>() { indexerDefinition });
var remoteEpisode = new RemoteEpisode
{
Series = new Series() { Id = 5 },
Episodes = new List<Episode> { new Episode { Id = 4 } },
ParsedEpisodeInfo = new ParsedEpisodeInfo()
{
SeriesTitle = "TV Series",
SeasonNumber = 1
},
MappedSeasonNumber = 1
};
Mocker.GetMock<IParsingService>()
.Setup(s => s.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), null))
.Returns(remoteEpisode);
var client = new DownloadClientDefinition()
{
Id = 1,
Protocol = DownloadProtocol.Torrent
};
var item = new DownloadClientItem()
{
Title = "TV.Series.S01.MULTi.1080p.WEB.H265-RlsGroup",
DownloadId = "35238",
DownloadClientInfo = new DownloadClientItemClientInfo
{
Protocol = client.Protocol,
Id = client.Id,
Name = client.Name
}
};
var trackedDownload = Subject.TrackDownload(client, item);
trackedDownload.Should().NotBeNull();
trackedDownload.RemoteEpisode.Should().NotBeNull();
trackedDownload.RemoteEpisode.Release.Should().NotBeNull();
trackedDownload.RemoteEpisode.Release.Indexer.Should().Be("MyIndexer (Prowlarr)");
}
[Test]
public void should_parse_as_special_when_source_title_parsing_fails()
{

View File

@ -0,0 +1,44 @@
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Indexers
{
[TestFixture]
public class IndexerRepositoryFixture : DbTest<IndexerRepository, IndexerDefinition>
{
private void GivenIndexers()
{
var indexers = Builder<IndexerDefinition>.CreateListOfSize(2)
.All()
.With(c => c.Id = 0)
.TheFirst(1)
.With(x => x.Name = "MyIndexer (Prowlarr)")
.TheNext(1)
.With(x => x.Name = "My Second Indexer (Prowlarr)")
.BuildList();
Subject.InsertMany(indexers);
}
[Test]
public void should_finds_with_name()
{
GivenIndexers();
var found = Subject.FindByName("MyIndexer (Prowlarr)");
found.Should().NotBeNull();
found.Name.Should().Be("MyIndexer (Prowlarr)");
found.Id.Should().Be(1);
}
[Test]
public void should_not_find_with_incorrect_case_name()
{
GivenIndexers();
var found = Subject.FindByName("myindexer (prowlarr)");
found.Should().BeNull();
}
}
}

View File

@ -76,9 +76,18 @@ namespace NzbDrone.Core.Download.Aggregation.Aggregators
languages = languages.Except(languagesToRemove).ToList();
}
if ((languages.Count == 0 || (languages.Count == 1 && languages.First() == Language.Unknown)) && releaseInfo is { IndexerId: > 0 } && releaseInfo.Title.IsNotNullOrWhiteSpace())
if ((languages.Count == 0 || (languages.Count == 1 && languages.First() == Language.Unknown)) && releaseInfo?.Title?.IsNotNullOrWhiteSpace() == true)
{
var indexer = _indexerFactory.Get(releaseInfo.IndexerId);
IndexerDefinition indexer = null;
if (releaseInfo is { IndexerId: > 0 })
{
indexer = _indexerFactory.Get(releaseInfo.IndexerId);
}
else if (releaseInfo.Indexer?.IsNotNullOrWhiteSpace() == true)
{
indexer = _indexerFactory.FindByName(releaseInfo.Indexer);
}
if (indexer?.Settings is IIndexerSettings settings && settings.MultiLanguages.Any() && Parser.Parser.HasMultipleLanguages(releaseInfo.Title))
{

View File

@ -120,8 +120,6 @@ namespace NzbDrone.Core.Download.TrackedDownloads
if (parsedEpisodeInfo != null)
{
trackedDownload.RemoteEpisode = _parsingService.Map(parsedEpisodeInfo, 0, 0, null);
_aggregationService.Augment(trackedDownload.RemoteEpisode);
}
var downloadHistory = _downloadHistoryService.GetLatestDownloadHistoryItem(downloadItem.DownloadId);
@ -158,17 +156,24 @@ namespace NzbDrone.Core.Download.TrackedDownloads
}
}
if (trackedDownload.RemoteEpisode != null &&
Enum.TryParse(grabbedEvent?.Data?.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags))
if (trackedDownload.RemoteEpisode != null)
{
trackedDownload.RemoteEpisode.Release ??= new ReleaseInfo();
trackedDownload.RemoteEpisode.Release.IndexerFlags = flags;
trackedDownload.RemoteEpisode.Release.Indexer = trackedDownload.Indexer;
trackedDownload.RemoteEpisode.Release.Title = trackedDownload.RemoteEpisode.ParsedEpisodeInfo?.ReleaseTitle;
if (Enum.TryParse(grabbedEvent?.Data?.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags))
{
trackedDownload.RemoteEpisode.Release.IndexerFlags = flags;
}
}
}
// Calculate custom formats
if (trackedDownload.RemoteEpisode != null)
{
_aggregationService.Augment(trackedDownload.RemoteEpisode);
// Calculate custom formats
trackedDownload.RemoteEpisode.CustomFormats = _formatCalculator.ParseCustomFormat(trackedDownload.RemoteEpisode, downloadItem.TotalSize);
}

View File

@ -13,10 +13,12 @@ namespace NzbDrone.Core.Indexers
List<IIndexer> RssEnabled(bool filterBlockedIndexers = true);
List<IIndexer> AutomaticSearchEnabled(bool filterBlockedIndexers = true);
List<IIndexer> InteractiveSearchEnabled(bool filterBlockedIndexers = true);
IndexerDefinition FindByName(string name);
}
public class IndexerFactory : ProviderFactory<IIndexer, IndexerDefinition>, IIndexerFactory
{
private readonly IIndexerRepository _indexerRepository;
private readonly IIndexerStatusService _indexerStatusService;
private readonly Logger _logger;
@ -28,6 +30,7 @@ namespace NzbDrone.Core.Indexers
Logger logger)
: base(providerRepository, providers, container, eventAggregator, logger)
{
_indexerRepository = providerRepository;
_indexerStatusService = indexerStatusService;
_logger = logger;
}
@ -82,6 +85,11 @@ namespace NzbDrone.Core.Indexers
return enabledIndexers.ToList();
}
public IndexerDefinition FindByName(string name)
{
return _indexerRepository.FindByName(name);
}
private IEnumerable<IIndexer> FilterBlockedIndexers(IEnumerable<IIndexer> indexers)
{
var blockedIndexers = _indexerStatusService.GetBlockedProviders().ToDictionary(v => v.ProviderId, v => v);

View File

@ -1,4 +1,5 @@
using NzbDrone.Core.Datastore;
using System.Linq;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.ThingiProvider;
@ -6,6 +7,7 @@ namespace NzbDrone.Core.Indexers
{
public interface IIndexerRepository : IProviderRepository<IndexerDefinition>
{
IndexerDefinition FindByName(string name);
}
public class IndexerRepository : ProviderRepository<IndexerDefinition>, IIndexerRepository
@ -14,5 +16,10 @@ namespace NzbDrone.Core.Indexers
: base(database, eventAggregator)
{
}
public IndexerDefinition FindByName(string name)
{
return Query(i => i.Name == name).SingleOrDefault();
}
}
}