Added additional filtering capability by Media airing status.
Note: Anilist currently does not support this type of filtering at the query level, so this is done as a post-processing step.
This commit is contained in:
parent
ddf3a208b4
commit
d4c063df56
|
@ -47,11 +47,6 @@ namespace NzbDrone.Core.ImportLists.AniList
|
||||||
|
|
||||||
public Dictionary<int, MediaMapping> Mappings => _cache.Get(_cacheKey, GetMappingData, _cacheInterval);
|
public Dictionary<int, MediaMapping> Mappings => _cache.Get(_cacheKey, GetMappingData, _cacheInterval);
|
||||||
|
|
||||||
public override AniListParser GetParser()
|
|
||||||
{
|
|
||||||
return new AniListParser(_logger, Mappings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object RequestAction(string action, IDictionary<string, string> query)
|
public override object RequestAction(string action, IDictionary<string, string> query)
|
||||||
{
|
{
|
||||||
if (action == "startOAuth")
|
if (action == "startOAuth")
|
||||||
|
|
|
@ -39,6 +39,34 @@ namespace NzbDrone.Core.ImportLists.AniList
|
||||||
public const string Repeating = "REPEATING";
|
public const string Repeating = "REPEATING";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class MediaStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Anime series has finished airing
|
||||||
|
/// </summary>
|
||||||
|
public const string Finished = "FINISHED";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Anime series is currently airing
|
||||||
|
/// </summary>
|
||||||
|
public const string Releasing = "RELEASING";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Anime series had not yet begun airing
|
||||||
|
/// </summary>
|
||||||
|
public const string Unreleased = "NOT_YET_RELEASED";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Anime series was cancelled
|
||||||
|
/// </summary>
|
||||||
|
public const string Cancelled = "CANCELLED";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Anime series is currently on hiatus
|
||||||
|
/// </summary>
|
||||||
|
public const string Hiatus = "HIATUS";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Data during token refresh cycles
|
/// Data during token refresh cycles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -39,6 +39,11 @@ namespace NzbDrone.Core.ImportLists.AniList.List
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override AniListParser GetParser()
|
||||||
|
{
|
||||||
|
return new AniListParser(_logger, Settings, Mappings);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Anilist caps the result list to 50 items at maximum per query, so the data must be pulled in batches.
|
/// Anilist caps the result list to 50 items at maximum per query, so the data must be pulled in batches.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
@ -6,17 +7,19 @@ using NzbDrone.Common.Serializer;
|
||||||
using NzbDrone.Core.ImportLists.Exceptions;
|
using NzbDrone.Core.ImportLists.Exceptions;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
namespace NzbDrone.Core.ImportLists.AniList
|
namespace NzbDrone.Core.ImportLists.AniList.List
|
||||||
{
|
{
|
||||||
public class AniListParser : IParseImportListResponse
|
public class AniListParser : IParseImportListResponse
|
||||||
{
|
{
|
||||||
private readonly Dictionary<int, MediaMapping> _mappings;
|
private readonly Dictionary<int, MediaMapping> _mappings;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
private readonly AniListSettings _settings;
|
||||||
|
|
||||||
public AniListParser(Logger logger, Dictionary<int, MediaMapping> mappings)
|
public AniListParser(Logger logger, AniListSettings settings, Dictionary<int, MediaMapping> mappings)
|
||||||
{
|
{
|
||||||
_mappings = mappings;
|
_mappings = mappings;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IList<ImportListItemInfo> ParseResponse(ImportListResponse importListResponse)
|
public virtual IList<ImportListItemInfo> ParseResponse(ImportListResponse importListResponse)
|
||||||
|
@ -42,7 +45,11 @@ namespace NzbDrone.Core.ImportLists.AniList
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var item in jsonResponse.Data.Page.MediaList)
|
// Filter out unwanted series status types
|
||||||
|
var filtered = jsonResponse.Data.Page.MediaList
|
||||||
|
.Where(x => ValidateMediaStatus(x.Media));
|
||||||
|
|
||||||
|
foreach (var item in filtered)
|
||||||
{
|
{
|
||||||
var media = item.Media;
|
var media = item.Media;
|
||||||
|
|
||||||
|
@ -85,6 +92,41 @@ namespace NzbDrone.Core.ImportLists.AniList
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Filter by media status, based on user settings.
|
||||||
|
///
|
||||||
|
/// Anilist currently does not support filtering this at the query level, so it must be done in post.
|
||||||
|
/// </summary>
|
||||||
|
private bool ValidateMediaStatus(MediaInfo media)
|
||||||
|
{
|
||||||
|
if (media.Status == MediaStatus.Finished && _settings.ImportFinished)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (media.Status == MediaStatus.Releasing && _settings.ImportReleasing)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (media.Status == MediaStatus.Unreleased && _settings.ImportUnreleased)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (media.Status == MediaStatus.Cancelled && _settings.ImportCancelled)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (media.Status == MediaStatus.Hiatus && _settings.ImportHiatus)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual bool PreProcess(ImportListResponse netImportResponse)
|
protected virtual bool PreProcess(ImportListResponse netImportResponse)
|
||||||
{
|
{
|
||||||
if (netImportResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
|
if (netImportResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
|
|
@ -19,13 +19,16 @@ namespace NzbDrone.Core.ImportLists.AniList.List
|
||||||
public class AniListSettings : AniListSettingsBase<AniListSettings>
|
public class AniListSettings : AniListSettingsBase<AniListSettings>
|
||||||
{
|
{
|
||||||
public const string sectionImport = "Import List Status";
|
public const string sectionImport = "Import List Status";
|
||||||
public const string unitStatusType = "Status Type";
|
public const string unitListStatus = "List Status";
|
||||||
|
public const string unitMediaStatus = "Media Status";
|
||||||
|
|
||||||
public AniListSettings()
|
public AniListSettings()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
ImportCurrent = true;
|
ImportCurrent = true;
|
||||||
ImportPlanning = true;
|
ImportPlanning = true;
|
||||||
|
ImportReleasing = true;
|
||||||
|
ImportFinished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override AbstractValidator<AniListSettings> Validator => new AniListSettingsValidator();
|
protected override AbstractValidator<AniListSettings> Validator => new AniListSettingsValidator();
|
||||||
|
@ -33,22 +36,37 @@ namespace NzbDrone.Core.ImportLists.AniList.List
|
||||||
[FieldDefinition(1, Label = "Username", HelpText = "Username for the List to import from")]
|
[FieldDefinition(1, Label = "Username", HelpText = "Username for the List to import from")]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(0, Label = "Import Watching", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitStatusType)]
|
[FieldDefinition(0, Label = "Import Watching", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)]
|
||||||
public bool ImportCurrent { get; set; }
|
public bool ImportCurrent { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(0, Label = "Import Planning", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitStatusType)]
|
[FieldDefinition(0, Label = "Import Planning", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)]
|
||||||
public bool ImportPlanning { get; set; }
|
public bool ImportPlanning { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(0, Label = "Import Completed", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitStatusType)]
|
[FieldDefinition(0, Label = "Import Completed", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)]
|
||||||
public bool ImportCompleted { get; set; }
|
public bool ImportCompleted { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(0, Label = "Import Dropped", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitStatusType)]
|
[FieldDefinition(0, Label = "Import Dropped", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)]
|
||||||
public bool ImportDropped { get; set; }
|
public bool ImportDropped { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(0, Label = "Import Paused", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitStatusType)]
|
[FieldDefinition(0, Label = "Import Paused", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)]
|
||||||
public bool ImportPaused { get; set; }
|
public bool ImportPaused { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(0, Label = "Import Repeating", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitStatusType)]
|
[FieldDefinition(0, Label = "Import Repeating", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)]
|
||||||
public bool ImportRepeating { get; set; }
|
public bool ImportRepeating { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(0, Label = "Import Finished Airing Series", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)]
|
||||||
|
public bool ImportFinished { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(0, Label = "Import Currently Airing Series", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)]
|
||||||
|
public bool ImportReleasing { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(0, Label = "Import Not Yet Airing Series", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)]
|
||||||
|
public bool ImportUnreleased { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(0, Label = "Import Cancelled Series", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)]
|
||||||
|
public bool ImportCancelled { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(0, Label = "Import Series on Hiatus", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)]
|
||||||
|
public bool ImportHiatus { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue