Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import folder filters #1184

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Shoko.Server/Filters/FilterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down Expand Up @@ -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(),
};
Expand Down
16 changes: 16 additions & 0 deletions Shoko.Server/Filters/Filterable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class Filterable : IFilterable
private readonly Lazy<IReadOnlySet<string>> _names;
private readonly Lazy<IReadOnlySet<string>> _aniDbIds;
private readonly Lazy<IReadOnlySet<string>> _resolutions;
private readonly Lazy<IReadOnlySet<string>> _importFolderIDs;
private readonly Lazy<IReadOnlySet<string>> _importFolderNames;
private readonly Lazy<IReadOnlySet<string>> _filePaths;
private readonly Lazy<IReadOnlySet<(int year, AnimeSeason season)>> _seasons;
private readonly Lazy<int> _seriesCount;
Expand Down Expand Up @@ -307,6 +309,20 @@ public Func<IReadOnlySet<string>> ResolutionsDelegate
}
}

public IReadOnlySet<string> ImportFolderIDs => _importFolderIDs.Value;

public Func<IReadOnlySet<string>> ImportFolderIDsDelegate
{
init => _importFolderIDs = new Lazy<IReadOnlySet<string>>(value);
}

public IReadOnlySet<string> ImportFolderNames => _importFolderNames.Value;

public Func<IReadOnlySet<string>> ImportFolderNamesDelegate
{
init => _importFolderNames = new Lazy<IReadOnlySet<string>>(value);
}

public IReadOnlySet<string> FilePaths => _filePaths.Value;

public Func<IReadOnlySet<string>> FilePathsDelegate
Expand Down
10 changes: 10 additions & 0 deletions Shoko.Server/Filters/Interfaces/IFilterable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ public interface IFilterable
/// </summary>
IReadOnlySet<string> Resolutions { get; }

/// <summary>
/// Import Folder IDs
/// </summary>
IReadOnlySet<string> ImportFolderIDs { get; }

/// <summary>
/// Import Folder Names
/// </summary>
IReadOnlySet<string> ImportFolderNames { get; }

/// <summary>
/// Relative File Paths
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using Shoko.Server.Filters.Interfaces;

namespace Shoko.Server.Filters.Selectors.StringSetSelectors;

public class ImportFolderIDsSelector : FilterExpression<IReadOnlySet<string>>
{
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<string> 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using Shoko.Server.Filters.Interfaces;

namespace Shoko.Server.Filters.Selectors.StringSetSelectors;

public class ImportFolderNamesSelector : FilterExpression<IReadOnlySet<string>>
{
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<string> 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);
}
}
2 changes: 2 additions & 0 deletions Shoko.Tests/Shoko.Tests/TestFilterable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ public class TestFilterable : IFilterable
public IReadOnlySet<string> SubtitleLanguages { get; init; }
public IReadOnlySet<string> SharedSubtitleLanguages { get; init; }
public IReadOnlySet<string> Resolutions { get; init; }
public IReadOnlySet<string> ImportFolderIDs { get; init; }
public IReadOnlySet<string> ImportFolderNames { get; init; }
public IReadOnlySet<string> FilePaths { get; init; }
}