Merge pull request #52 from jellyfin/base-item-kind

This commit is contained in:
Cody Robibero 2022-01-04 21:36:37 -07:00 committed by GitHub
commit 6f0aed3621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,8 @@
using System.Collections.Generic;
using System;
using System;
using System.ComponentModel;
using System.Linq;
using Jellyfin.Data.Enums;
using Jellyfin.Plugin.Reports.Api.Common;
using Jellyfin.Plugin.Reports.Api.Model;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
@ -420,20 +419,14 @@ namespace Jellyfin.Plugin.Reports.Api
return (MediaTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
public string[] GetIncludeItemTypes()
{
return (IncludeItemTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
public BaseItemKind[] GetIncludeItemTypes() => GetBaseItemKinds(IncludeItemTypes);
public string[] GetExcludeItemIds()
{
return (ExcludeItemIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
public string[] GetExcludeItemTypes()
{
return (ExcludeItemTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
public BaseItemKind[] GetExcludeItemTypes() => GetBaseItemKinds(ExcludeItemTypes);
public int[] GetYears()
{
@ -594,7 +587,43 @@ namespace Jellyfin.Plugin.Reports.Api
// [ApiMember(Name = "ReportColumns", Description = "Optional. The columns to show.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportColumns { get; set; }
private BaseItemKind[] GetBaseItemKinds(string input)
{
if (string.IsNullOrEmpty(input))
{
return Array.Empty<BaseItemKind>();
}
var splitString = input.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
var converter = TypeDescriptor.GetConverter(typeof(BaseItemKind));
var parsedValues = new object[splitString.Length];
var convertedCount = 0;
for (var i = 0; i < splitString.Length; i++)
{
try
{
parsedValues[i] = converter.ConvertFromString(splitString[i]);
convertedCount++;
}
catch (FormatException)
{
// suppress.
}
}
var typedValues = new BaseItemKind[convertedCount];
var typedValueIndex = 0;
for (var i = 0; i < parsedValues.Length; i++)
{
if (parsedValues[i] != null)
{
typedValues.SetValue(parsedValues[i], typedValueIndex);
typedValueIndex++;
}
}
return typedValues;
}
}
public class GetItemReport : BaseReportRequest