diff --git a/Shoko.Server/Filters/FilterExtensions.cs b/Shoko.Server/Filters/FilterExtensions.cs index 19017d20e..d8ded5274 100644 --- a/Shoko.Server/Filters/FilterExtensions.cs +++ b/Shoko.Server/Filters/FilterExtensions.cs @@ -122,6 +122,10 @@ series.AniDB_Anime is { } anime .Where(a => a.MediaInfo?.VideoStream is not null) .Select(a => MediaInfoUtils.GetStandardResolution(Tuple.Create(a.MediaInfo!.VideoStream!.Width, a.MediaInfo!.VideoStream!.Height))) .ToHashSet(), + ImportFolderIDsDelegate = () => + series.VideoLocals.Select(a => a.FirstValidPlace?.ImportFolderID.ToString()).WhereNotNull().ToHashSet(), + ImportFolderNamesDelegate = () => + series.VideoLocals.Select(a => a.FirstValidPlace?.ImportFolder?.ImportFolderName).WhereNotNull().ToHashSet(), FilePathsDelegate = () => series.VideoLocals.Select(a => a.FirstValidPlace?.FilePath).WhereNotNull().ToHashSet(), }; @@ -267,6 +271,10 @@ public static Filterable ToFilterable(this SVR_AnimeGroup group) .Where(a => a.MediaInfo?.VideoStream is not null) .Select(a => MediaInfoUtils.GetStandardResolution(Tuple.Create(a.MediaInfo!.VideoStream!.Width, a.MediaInfo!.VideoStream!.Height))) .ToHashSet(), + ImportFolderIDsDelegate = () => + series.SelectMany(s => s.VideoLocals.Select(a => a.FirstValidPlace?.ImportFolderID.ToString())).WhereNotNull().ToHashSet(), + ImportFolderNamesDelegate = () => + series.SelectMany(s => s.VideoLocals.Select(a => a.FirstValidPlace?.ImportFolder?.ImportFolderName)).WhereNotNull().ToHashSet(), FilePathsDelegate = () => series.SelectMany(s => s.VideoLocals.Select(a => a.FirstValidPlace?.FilePath)).WhereNotNull().ToHashSet(), }; diff --git a/Shoko.Server/Filters/Filterable.cs b/Shoko.Server/Filters/Filterable.cs index 417d8ee4e..802fc2753 100644 --- a/Shoko.Server/Filters/Filterable.cs +++ b/Shoko.Server/Filters/Filterable.cs @@ -33,6 +33,8 @@ public class Filterable : IFilterable private readonly Lazy> _names; private readonly Lazy> _aniDbIds; private readonly Lazy> _resolutions; + private readonly Lazy> _importFolderIDs; + private readonly Lazy> _importFolderNames; private readonly Lazy> _filePaths; private readonly Lazy> _seasons; private readonly Lazy _seriesCount; @@ -307,6 +309,20 @@ public Func> ResolutionsDelegate } } + public IReadOnlySet ImportFolderIDs => _importFolderIDs.Value; + + public Func> ImportFolderIDsDelegate + { + init => _importFolderIDs = new Lazy>(value); + } + + public IReadOnlySet ImportFolderNames => _importFolderNames.Value; + + public Func> ImportFolderNamesDelegate + { + init => _importFolderNames = new Lazy>(value); + } + public IReadOnlySet FilePaths => _filePaths.Value; public Func> FilePathsDelegate diff --git a/Shoko.Server/Filters/Interfaces/IFilterable.cs b/Shoko.Server/Filters/Interfaces/IFilterable.cs index 7edce9afc..4d529703a 100644 --- a/Shoko.Server/Filters/Interfaces/IFilterable.cs +++ b/Shoko.Server/Filters/Interfaces/IFilterable.cs @@ -191,6 +191,16 @@ public interface IFilterable /// IReadOnlySet Resolutions { get; } + /// + /// Import Folder IDs + /// + IReadOnlySet ImportFolderIDs { get; } + + /// + /// Import Folder Names + /// + IReadOnlySet ImportFolderNames { get; } + /// /// Relative File Paths /// diff --git a/Shoko.Server/Filters/Selectors/StringSetSelectors/ImportFolderIDsSelector.cs b/Shoko.Server/Filters/Selectors/StringSetSelectors/ImportFolderIDsSelector.cs new file mode 100644 index 000000000..aac40615d --- /dev/null +++ b/Shoko.Server/Filters/Selectors/StringSetSelectors/ImportFolderIDsSelector.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using Shoko.Server.Filters.Interfaces; + +namespace Shoko.Server.Filters.Selectors.StringSetSelectors; + +public class ImportFolderIDsSelector : FilterExpression> +{ + public override bool TimeDependent => false; + public override bool UserDependent => false; + public override string HelpDescription => "This returns a set of the import folder IDs in a filterable"; + public override FilterExpressionGroup Group => FilterExpressionGroup.Selector; + + public override IReadOnlySet Evaluate(IFilterable filterable, IFilterableUserInfo userInfo) + { + return filterable.ImportFolderIDs; + } + + protected bool Equals(ImportFolderIDsSelector other) + { + return base.Equals(other); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != this.GetType()) + { + return false; + } + + return Equals((ImportFolderIDsSelector)obj); + } + + public override int GetHashCode() + { + return GetType().FullName!.GetHashCode(); + } + + public static bool operator ==(ImportFolderIDsSelector left, ImportFolderIDsSelector right) + { + return Equals(left, right); + } + + public static bool operator !=(ImportFolderIDsSelector left, ImportFolderIDsSelector right) + { + return !Equals(left, right); + } +} diff --git a/Shoko.Server/Filters/Selectors/StringSetSelectors/ImportFolderNamesSelector.cs b/Shoko.Server/Filters/Selectors/StringSetSelectors/ImportFolderNamesSelector.cs new file mode 100644 index 000000000..d4183a5da --- /dev/null +++ b/Shoko.Server/Filters/Selectors/StringSetSelectors/ImportFolderNamesSelector.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using Shoko.Server.Filters.Interfaces; + +namespace Shoko.Server.Filters.Selectors.StringSetSelectors; + +public class ImportFolderNamesSelector : FilterExpression> +{ + public override bool TimeDependent => false; + public override bool UserDependent => false; + public override string HelpDescription => "This returns a set of the import folder names in a filterable"; + public override FilterExpressionGroup Group => FilterExpressionGroup.Selector; + + public override IReadOnlySet Evaluate(IFilterable filterable, IFilterableUserInfo userInfo) + { + return filterable.ImportFolderNames; + } + + protected bool Equals(ImportFolderNamesSelector other) + { + return base.Equals(other); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != this.GetType()) + { + return false; + } + + return Equals((ImportFolderNamesSelector)obj); + } + + public override int GetHashCode() + { + return GetType().FullName!.GetHashCode(); + } + + public static bool operator ==(ImportFolderNamesSelector left, ImportFolderNamesSelector right) + { + return Equals(left, right); + } + + public static bool operator !=(ImportFolderNamesSelector left, ImportFolderNamesSelector right) + { + return !Equals(left, right); + } +} diff --git a/Shoko.Tests/Shoko.Tests/TestFilterable.cs b/Shoko.Tests/Shoko.Tests/TestFilterable.cs index 92d52fba0..687077b58 100644 --- a/Shoko.Tests/Shoko.Tests/TestFilterable.cs +++ b/Shoko.Tests/Shoko.Tests/TestFilterable.cs @@ -44,5 +44,7 @@ public class TestFilterable : IFilterable public IReadOnlySet SubtitleLanguages { get; init; } public IReadOnlySet SharedSubtitleLanguages { get; init; } public IReadOnlySet Resolutions { get; init; } + public IReadOnlySet ImportFolderIDs { get; init; } + public IReadOnlySet ImportFolderNames { get; init; } public IReadOnlySet FilePaths { get; init; } }