Skip to content

Commit

Permalink
feat: add video files to filtering system
Browse files Browse the repository at this point in the history
…because I need it.
  • Loading branch information
revam committed Dec 15, 2024
1 parent e7b5cc2 commit d1d3379
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Shoko.Server/Filters/FilterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static Filterable ToFilterable(this SVR_AnimeSeries series)
series.MissingEpisodeCount,
MissingEpisodesCollectingDelegate = () =>
series.MissingEpisodeCountGroups,
VideoFilesDelegate = () =>
series.VideoLocals.Count,
TagsDelegate = () =>
series.AniDB_Anime?.Tags.Select(a => a.TagName).ToHashSet() ?? [],
CustomTagsDelegate = () =>
Expand Down Expand Up @@ -199,6 +201,8 @@ public static Filterable ToFilterable(this SVR_AnimeGroup group)
group.MissingEpisodeCount,
MissingEpisodesCollectingDelegate = () =>
group.MissingEpisodeCountGroups,
VideoFilesDelegate = () =>
series.SelectMany(s => s.VideoLocals).DistinctBy(a => a.VideoLocalID).Count(),
TagsDelegate = () =>
group.Tags.Select(a => a.TagName).ToHashSet(),
CustomTagsDelegate = () =>
Expand Down
8 changes: 8 additions & 0 deletions Shoko.Server/Filters/Filterable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Filterable : IFilterable
private readonly Lazy<decimal> _lowestAniDBRating;
private readonly Lazy<int> _missingEpisodes;
private readonly Lazy<int> _missingEpisodesCollecting;
private readonly Lazy<int> _videoFiles;
private readonly Lazy<string> _name;
private readonly Lazy<IReadOnlySet<string>> _names;
private readonly Lazy<IReadOnlySet<string>> _aniDbIds;
Expand Down Expand Up @@ -98,6 +99,13 @@ public Func<int> MissingEpisodesCollectingDelegate
init => _missingEpisodesCollecting = new Lazy<int>(value);
}

public int VideoFiles => _videoFiles.Value;

public Func<int> VideoFilesDelegate
{
init => _videoFiles = new Lazy<int>(value);
}

public IReadOnlySet<string> Tags => _tags.Value;

public Func<IReadOnlySet<string>> TagsDelegate
Expand Down
55 changes: 55 additions & 0 deletions Shoko.Server/Filters/Info/HasVideoFilesExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Shoko.Server.Filters.Interfaces;

namespace Shoko.Server.Filters.Info;

public class HasVideoFilesExpression : FilterExpression<bool>
{
public override bool TimeDependent => false;
public override bool UserDependent => false;
public override string HelpDescription => "This condition passes if any of the anime have any video files locally.";

public override bool Evaluate(IFilterable filterable, IFilterableUserInfo userInfo)
{
return filterable.VideoFiles > 0;
}

protected bool Equals(HasVideoFilesExpression 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((HasVideoFilesExpression)obj);
}

public override int GetHashCode()
{
return GetType().FullName!.GetHashCode();
}

public static bool operator ==(HasVideoFilesExpression left, HasVideoFilesExpression right)
{
return Equals(left, right);
}

public static bool operator !=(HasVideoFilesExpression left, HasVideoFilesExpression right)
{
return !Equals(left, right);
}
}
5 changes: 5 additions & 0 deletions Shoko.Server/Filters/Interfaces/IFilterable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public interface IFilterable
/// </summary>
int MissingEpisodesCollecting { get; }

/// <summary>
/// Number of video files for the filterable.
/// </summary>
int VideoFiles { get; }

/// <summary>
/// All of the tags
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Shoko.Server.Filters.Interfaces;

namespace Shoko.Server.Filters.Selectors.NumberSelectors;

public class VideoFilesSelector : FilterExpression<double>
{
public override bool TimeDependent => false;
public override bool UserDependent => false;
public override string HelpDescription => "This returns the number of video files for the filterable.";
public override FilterExpressionGroup Group => FilterExpressionGroup.Selector;

public override double Evaluate(IFilterable filterable, IFilterableUserInfo userInfo)
{
return filterable.VideoFiles;
}

protected bool Equals(VideoFilesSelector 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((VideoFilesSelector)obj);
}

public override int GetHashCode()
{
return GetType().FullName!.GetHashCode();
}

public static bool operator ==(VideoFilesSelector left, VideoFilesSelector right)
{
return Equals(left, right);
}

public static bool operator !=(VideoFilesSelector left, VideoFilesSelector right)
{
return !Equals(left, right);
}
}
1 change: 1 addition & 0 deletions Shoko.Tests/Shoko.Tests/TestFilterable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class TestFilterable : IFilterable
public int SeriesCount { get; init; }
public int MissingEpisodes { get; init; }
public int MissingEpisodesCollecting { get; init; }
public int VideoFiles { get; init; }
public IReadOnlySet<string> Tags { get; init; }
public IReadOnlySet<string> CustomTags { get; init; }
public IReadOnlySet<int> Years { get; init; }
Expand Down

0 comments on commit d1d3379

Please sign in to comment.