New: Index priority

#320
This commit is contained in:
Dtaggart 2020-09-10 18:04:53 -04:00 committed by GitHub
parent 9ed2b4e10b
commit b2737a3d35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 96 additions and 4 deletions

View File

@ -42,7 +42,8 @@ function EditIndexerModalContent(props) {
enableInteractiveSearch,
supportsRss,
supportsSearch,
fields
fields,
priority
} = item;
return (
@ -131,7 +132,21 @@ function EditIndexerModalContent(props) {
);
})
}
<FormGroup
advancedSettings={advancedSettings}
isAdvanced={true}>
<FormLabel>Indexer Priority</FormLabel>
<FormInputGroup
type={inputTypes.NUMBER}
name="priority"
helpText="Indexer Priority from 1 (Highest) to 50 (Lowest). Default: 25."
min={1}
max={50}
{...priority}
onChange={onInputChange}
/>
</FormGroup>
</Form>
}
</ModalBody>

View File

@ -68,7 +68,9 @@ class Indexer extends Component {
enableAutomaticSearch,
enableInteractiveSearch,
supportsRss,
supportsSearch
supportsSearch,
priority,
showPriority
} = this.props;
return (
@ -112,7 +114,13 @@ class Indexer extends Component {
Interactive Search
</Label>
}
{
showPriority &&
<Label kind={kinds.DEFAULT}>
Priority: {priority}
</Label>
}
{
!enableRss && !enableAutomaticSearch && !enableInteractiveSearch &&
<Label

View File

@ -62,6 +62,8 @@ class Indexers extends Component {
isAddIndexerModalOpen,
isEditIndexerModalOpen
} = this.state;
const showPriority = items.some((index) => index.priority != 25);
return (
<FieldSet legend="Indexers">
@ -76,6 +78,7 @@ class Indexers extends Component {
<Indexer
key={item.id}
{...item}
showPriority={showPriority}
onCloneIndexerPress={this.onCloneIndexerPress}
onConfirmDeleteIndexer={onConfirmDeleteIndexer}
/>

View File

@ -18,6 +18,7 @@ namespace NzbDrone.Api.Indexers
resource.SupportsRss = definition.SupportsRss;
resource.SupportsSearch = definition.SupportsSearch;
resource.Protocol = definition.Protocol;
resource.Priority = definition.Priority;
}
protected override void MapToModel(IndexerDefinition definition, IndexerResource resource)
@ -27,6 +28,7 @@ namespace NzbDrone.Api.Indexers
definition.EnableRss = resource.EnableRss;
definition.EnableAutomaticSearch = resource.EnableSearch;
definition.EnableInteractiveSearch = resource.EnableSearch;
definition.Priority = resource.Priority;
}
protected override void Validate(IndexerDefinition definition, bool includeWarnings)

View File

@ -9,5 +9,6 @@ namespace NzbDrone.Api.Indexers
public bool SupportsRss { get; set; }
public bool SupportsSearch { get; set; }
public DownloadProtocol Protocol { get; set; }
public int Priority { get; set; }
}
}

View File

@ -38,7 +38,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
.Build();
}
private RemoteEpisode GivenRemoteEpisode(List<Episode> episodes, QualityModel quality, Language language, int age = 0, long size = 0, DownloadProtocol downloadProtocol = DownloadProtocol.Usenet)
private RemoteEpisode GivenRemoteEpisode(List<Episode> episodes, QualityModel quality, Language language, int age = 0, long size = 0, DownloadProtocol downloadProtocol = DownloadProtocol.Usenet, int indexerPriority = 25)
{
var remoteEpisode = new RemoteEpisode();
remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo();
@ -52,6 +52,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
remoteEpisode.Release.PublishDate = DateTime.Now.AddDays(-age);
remoteEpisode.Release.Size = size;
remoteEpisode.Release.DownloadProtocol = downloadProtocol;
remoteEpisode.Release.IndexerPriority = indexerPriority;
remoteEpisode.Series = Builder<Series>.CreateNew()
.With(e => e.QualityProfile = new QualityProfile
@ -573,5 +574,39 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
qualifiedReports.First().RemoteEpisode.ParsedEpisodeInfo.Quality.Revision.Real.Should().Be(0);
qualifiedReports.First().RemoteEpisode.PreferredWordScore.Should().Be(10);
}
[Test]
public void sort_download_decisions_based_on_indexer_priority()
{
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.WEBDL1080p, new Revision(1)), Language.English, indexerPriority: 25);
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.WEBDL1080p, new Revision(1)), Language.English, indexerPriority: 50);
var remoteEpisode3 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.WEBDL1080p, new Revision(1)), Language.English, indexerPriority: 1);
var decisions = new List<DownloadDecision>();
decisions.AddRange(new [] { new DownloadDecision(remoteEpisode1), new DownloadDecision(remoteEpisode2), new DownloadDecision(remoteEpisode3) });
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
qualifiedReports.First().RemoteEpisode.Should().Be(remoteEpisode3);
qualifiedReports.Skip(1).First().RemoteEpisode.Should().Be(remoteEpisode1);
qualifiedReports.Last().RemoteEpisode.Should().Be(remoteEpisode2);
}
[Test]
public void ensure_download_decisions_indexer_priority_is_not_perfered_over_quality()
{
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p, new Revision(1)), Language.English, indexerPriority: 25);
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.WEBDL1080p, new Revision(1)), Language.English, indexerPriority: 50);
var remoteEpisode3 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.SDTV, new Revision(1)), Language.English, indexerPriority: 1);
var remoteEpisode4 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.WEBDL1080p, new Revision(1)), Language.English, indexerPriority: 25);
var decisions = new List<DownloadDecision>();
decisions.AddRange(new[] { new DownloadDecision(remoteEpisode1), new DownloadDecision(remoteEpisode2), new DownloadDecision(remoteEpisode3), new DownloadDecision(remoteEpisode4) });
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
qualifiedReports.First().RemoteEpisode.Should().Be(remoteEpisode4);
qualifiedReports.Skip(1).First().RemoteEpisode.Should().Be(remoteEpisode2);
qualifiedReports.Skip(2).First().RemoteEpisode.Should().Be(remoteEpisode1);
qualifiedReports.Last().RemoteEpisode.Should().Be(remoteEpisode3);
}
}
}

View File

@ -0,0 +1,14 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(143)]
public class add_priority_to_indexers : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Indexers").AddColumn("Priority").AsInt32().NotNullable().WithDefaultValue(25);
}
}
}

View File

@ -34,6 +34,7 @@ namespace NzbDrone.Core.DecisionEngine
CompareProtocol,
CompareEpisodeCount,
CompareEpisodeNumber,
CompareIndexerPriority,
ComparePeersIfTorrent,
CompareAgeIfUsenet,
CompareSize
@ -62,6 +63,11 @@ namespace NzbDrone.Core.DecisionEngine
return comparers.Select(comparer => comparer).FirstOrDefault(result => result != 0);
}
private int CompareIndexerPriority(DownloadDecision x, DownloadDecision y)
{
return CompareByReverse(x.RemoteEpisode.Release, y.RemoteEpisode.Release, release => release.IndexerPriority);
}
private int CompareQuality(DownloadDecision x, DownloadDecision y)
{
if (_configService.DownloadPropersAndRepacks == ProperDownloadTypes.DoNotPrefer)

View File

@ -73,6 +73,7 @@ namespace NzbDrone.Core.Download
try
{
_logger.Trace("Grabbing from Indexer {0} at priority {1}.", remoteEpisode.Release.Indexer, remoteEpisode.Release.IndexerPriority);
_downloadService.DownloadReport(remoteEpisode);
grabbed.Add(report);
}

View File

@ -22,6 +22,7 @@ namespace NzbDrone.Core.Indexers
public abstract string Name { get; }
public abstract DownloadProtocol Protocol { get; }
public int Priority { get; set; }
public abstract bool SupportsRss { get; }
public abstract bool SupportsSearch { get; }
@ -79,6 +80,7 @@ namespace NzbDrone.Core.Indexers
c.IndexerId = Definition.Id;
c.Indexer = Definition.Name;
c.DownloadProtocol = Protocol;
c.IndexerPriority = ((IndexerDefinition)Definition).Priority;
});
return result;

View File

@ -10,6 +10,7 @@ namespace NzbDrone.Core.Indexers
public DownloadProtocol Protocol { get; set; }
public bool SupportsRss { get; set; }
public bool SupportsSearch { get; set; }
public int Priority { get; set; } = 25;
public override bool Enable => EnableRss || EnableAutomaticSearch || EnableInteractiveSearch;

View File

@ -14,6 +14,7 @@ namespace NzbDrone.Core.Parser.Model
public string CommentUrl { get; set; }
public int IndexerId { get; set; }
public string Indexer { get; set; }
public int IndexerPriority { get; set; }
public DownloadProtocol DownloadProtocol { get; set; }
public int TvdbId { get; set; }
public int TvRageId { get; set; }

View File

@ -10,6 +10,7 @@ namespace Sonarr.Api.V3.Indexers
public bool SupportsRss { get; set; }
public bool SupportsSearch { get; set; }
public DownloadProtocol Protocol { get; set; }
public int Priority { get; set; }
}
public class IndexerResourceMapper : ProviderResourceMapper<IndexerResource, IndexerDefinition>
@ -26,6 +27,7 @@ namespace Sonarr.Api.V3.Indexers
resource.SupportsRss = definition.SupportsRss;
resource.SupportsSearch = definition.SupportsSearch;
resource.Protocol = definition.Protocol;
resource.Priority = definition.Priority;
return resource;
}
@ -39,6 +41,7 @@ namespace Sonarr.Api.V3.Indexers
definition.EnableRss = resource.EnableRss;
definition.EnableAutomaticSearch = resource.EnableAutomaticSearch;
definition.EnableInteractiveSearch = resource.EnableInteractiveSearch;
definition.Priority = resource.Priority;
return definition;
}