fix: move FilterCollectionItems from Common.cs to GenerateCollection.cs.
It had no place being in common.
This commit is contained in:
parent
4db98eb1c8
commit
b0593585df
2 changed files with 38 additions and 34 deletions
|
@ -77,39 +77,5 @@ namespace Jellyfin.Plugin.SmartPlaylist.ScheduledTasks {
|
|||
}
|
||||
return executor;
|
||||
}
|
||||
public IEnumerable<Guid> FilterCollectionItems(IEnumerable<BaseItem> items, User? user, string name, string program, string sortProgram) {
|
||||
List<BaseItem> results = new List<BaseItem>();
|
||||
Expression expression = new Parser(StringTokenStream.generate(program)).parse(); // parse here, so that we don't repeat the work for each item
|
||||
Executor executor = SetupExecutor();
|
||||
|
||||
executor.environment.Set("*user*", Lisp.Object.FromBase(user));
|
||||
foreach (var i in items) {
|
||||
executor.environment.Set("*item*", Lisp.Object.FromBase(i));
|
||||
var r = executor.eval(expression);
|
||||
_logger.LogTrace("Item {0} evaluated to {1}", i, r.ToString());
|
||||
if ((r is not Lisp.Boolean r_bool) || (r_bool.Value())) {
|
||||
_logger.LogDebug("Added '{0}' to Smart Collection {1}", i, name);
|
||||
results.Add(i);
|
||||
}
|
||||
}
|
||||
executor = SetupExecutor();
|
||||
executor.environment.Set("*user*", Lisp.Object.FromBase(user));
|
||||
executor.environment.Set("*items*", Lisp.Object.FromBase(results));
|
||||
results = new List<BaseItem>();
|
||||
var sort_result = executor.eval(sortProgram);
|
||||
if (sort_result is Cons sorted_items) {
|
||||
foreach (var i in sorted_items.ToList()) {
|
||||
if (i is Lisp.Object iObject && iObject.Value() is BaseItem iBaseItem) {
|
||||
results.Add(iBaseItem);
|
||||
continue;
|
||||
}
|
||||
throw new ApplicationException($"Returned sorted list does contain unexpected items, got {i}");
|
||||
}
|
||||
} else if (sort_result == Lisp.Boolean.FALSE) {
|
||||
} else {
|
||||
throw new ApplicationException($"Did not return a list of items, returned {sort_result}");
|
||||
}
|
||||
return results.Select(x => x.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,10 @@ using MediaBrowser.Controller.Providers;
|
|||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using Jellyfin.Data.Entities;
|
||||
|
||||
using Jellyfin.Plugin.SmartPlaylist.Lisp;
|
||||
using Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler;
|
||||
|
||||
namespace Jellyfin.Plugin.SmartPlaylist.ScheduledTasks {
|
||||
public class GenerateCollection: Common, IScheduledTask {
|
||||
|
@ -61,6 +64,41 @@ namespace Jellyfin.Plugin.SmartPlaylist.ScheduledTasks {
|
|||
)).Id;
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> FilterCollectionItems(IEnumerable<BaseItem> items, User? user, string name, string program, string sortProgram) {
|
||||
List<BaseItem> results = new List<BaseItem>();
|
||||
Expression expression = new Parser(StringTokenStream.generate(program)).parse(); // parse here, so that we don't repeat the work for each item
|
||||
Executor executor = SetupExecutor();
|
||||
|
||||
executor.environment.Set("*user*", Lisp.Object.FromBase(user));
|
||||
foreach (var i in items) {
|
||||
executor.environment.Set("*item*", Lisp.Object.FromBase(i));
|
||||
var r = executor.eval(expression);
|
||||
_logger.LogTrace("Item {0} evaluated to {1}", i, r.ToString());
|
||||
if ((r is not Lisp.Boolean r_bool) || (r_bool.Value())) {
|
||||
_logger.LogDebug("Added '{0}' to Smart Collection {1}", i, name);
|
||||
results.Add(i);
|
||||
}
|
||||
}
|
||||
executor = SetupExecutor();
|
||||
executor.environment.Set("*user*", Lisp.Object.FromBase(user));
|
||||
executor.environment.Set("*items*", Lisp.Object.FromBase(results));
|
||||
results = new List<BaseItem>();
|
||||
var sort_result = executor.eval(sortProgram);
|
||||
if (sort_result is Cons sorted_items) {
|
||||
foreach (var i in sorted_items.ToList()) {
|
||||
if (i is Lisp.Object iObject && iObject.Value() is BaseItem iBaseItem) {
|
||||
results.Add(iBaseItem);
|
||||
continue;
|
||||
}
|
||||
throw new ApplicationException($"Returned sorted list does contain unexpected items, got {i}");
|
||||
}
|
||||
} else if (sort_result == Lisp.Boolean.FALSE) {
|
||||
} else {
|
||||
throw new ApplicationException($"Did not return a list of items, returned {sort_result}");
|
||||
}
|
||||
return results.Select(x => x.Id);
|
||||
}
|
||||
|
||||
private IEnumerable<BaseItem> GetAllMedia() {
|
||||
var req = new InternalItemsQuery() {
|
||||
IncludeItemTypes = AvailableFilterItems,
|
||||
|
|
Loading…
Add table
Reference in a new issue