mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
parent
07c95f06d3
commit
519a5ca75c
@ -37,6 +37,7 @@ public FieldOptionAttribute([CallerLineNumber] int order = 0, string label = nul
|
||||
public int Order { get; private set; }
|
||||
public string Label { get; set; }
|
||||
public string Hint { get; set; }
|
||||
public string RequestAction { get; set; }
|
||||
}
|
||||
|
||||
public class FieldSelectOption
|
||||
|
@ -14,6 +14,7 @@ public class SonarrSeries
|
||||
public int Year { get; set; }
|
||||
public string TitleSlug { get; set; }
|
||||
public int QualityProfileId { get; set; }
|
||||
public HashSet<int> Tags { get; set; }
|
||||
}
|
||||
|
||||
public class SonarrProfile
|
||||
@ -21,4 +22,10 @@ public class SonarrProfile
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class SonarrTag
|
||||
{
|
||||
public string Label { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ public override IList<ImportListItemInfo> Fetch()
|
||||
|
||||
foreach (var item in remoteSeries)
|
||||
{
|
||||
if (!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(item.QualityProfileId))
|
||||
if ((!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(item.QualityProfileId)) &&
|
||||
(!Settings.TagIds.Any() || Settings.TagIds.Any(tagId => item.Tags.Any(itemTagId => itemTagId == tagId))))
|
||||
{
|
||||
series.Add(new ImportListItemInfo
|
||||
{
|
||||
@ -60,24 +61,24 @@ public override IList<ImportListItemInfo> Fetch()
|
||||
|
||||
public override object RequestAction(string action, IDictionary<string, string> query)
|
||||
{
|
||||
if (action == "getDevices")
|
||||
// Return early if there is not an API key
|
||||
if (Settings.ApiKey.IsNullOrWhiteSpace())
|
||||
{
|
||||
// Return early if there is not an API key
|
||||
if (Settings.ApiKey.IsNullOrWhiteSpace())
|
||||
return new
|
||||
{
|
||||
return new
|
||||
{
|
||||
devices = new List<object>()
|
||||
};
|
||||
}
|
||||
devices = new List<object>()
|
||||
};
|
||||
}
|
||||
|
||||
if (action == "getProfiles")
|
||||
{
|
||||
Settings.Validate().Filter("ApiKey").ThrowOnError();
|
||||
|
||||
var devices = _sonarrV3Proxy.GetProfiles(Settings);
|
||||
var profiles = _sonarrV3Proxy.GetProfiles(Settings);
|
||||
|
||||
return new
|
||||
{
|
||||
options = devices.OrderBy(d => d.Name, StringComparer.InvariantCultureIgnoreCase)
|
||||
options = profiles.OrderBy(d => d.Name, StringComparer.InvariantCultureIgnoreCase)
|
||||
.Select(d => new
|
||||
{
|
||||
id = d.Id,
|
||||
@ -86,6 +87,21 @@ public override object RequestAction(string action, IDictionary<string, string>
|
||||
};
|
||||
}
|
||||
|
||||
if (action == "getTags")
|
||||
{
|
||||
var tags = _sonarrV3Proxy.GetTags(Settings);
|
||||
|
||||
return new
|
||||
{
|
||||
options = tags.OrderBy(d => d.Label, StringComparer.InvariantCultureIgnoreCase)
|
||||
.Select(d => new
|
||||
{
|
||||
id = d.Id,
|
||||
name = d.Label
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
return new { };
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ public SonarrSettings()
|
||||
BaseUrl = "";
|
||||
ApiKey = "";
|
||||
ProfileIds = new int[] { };
|
||||
TagIds = new int[] { };
|
||||
}
|
||||
|
||||
[FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Sonarr V3 instance to import from")]
|
||||
@ -31,9 +32,12 @@ public SonarrSettings()
|
||||
[FieldDefinition(1, Label = "API Key", HelpText = "Apikey of the Sonarr V3 instance to import from")]
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
[FieldDefinition(2, Type = FieldType.Device, Label = "Profiles", HelpText = "Profiles from the source instance to import from")]
|
||||
[FieldDefinition(2, Type = FieldType.Select, SelectOptionsProviderAction = "getProfiles", Label = "Profiles", HelpText = "Profiles from the source instance to import from")]
|
||||
public IEnumerable<int> ProfileIds { get; set; }
|
||||
|
||||
[FieldDefinition(3, Type = FieldType.Select, SelectOptionsProviderAction = "getTags", Label = "Tags", HelpText = "Tags from the source instance to import from")]
|
||||
public IEnumerable<int> TagIds { get; set; }
|
||||
|
||||
public NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
|
@ -13,6 +13,7 @@ public interface ISonarrV3Proxy
|
||||
{
|
||||
List<SonarrSeries> GetSeries(SonarrSettings settings);
|
||||
List<SonarrProfile> GetProfiles(SonarrSettings settings);
|
||||
List<SonarrTag> GetTags(SonarrSettings settings);
|
||||
ValidationFailure Test(SonarrSettings settings);
|
||||
}
|
||||
|
||||
@ -37,6 +38,11 @@ public List<SonarrProfile> GetProfiles(SonarrSettings settings)
|
||||
return Execute<SonarrProfile>("/api/v3/qualityprofile", settings);
|
||||
}
|
||||
|
||||
public List<SonarrTag> GetTags(SonarrSettings settings)
|
||||
{
|
||||
return Execute<SonarrTag>("/api/v3/tag", settings);
|
||||
}
|
||||
|
||||
public ValidationFailure Test(SonarrSettings settings)
|
||||
{
|
||||
try
|
||||
|
Loading…
Reference in New Issue
Block a user