Add AutoCollection option

it can determine whether auto create/add movies to collection

Signed-off-by: Petrus.Z <silencly07@gmail.com>
This commit is contained in:
Petrus.Z 2021-11-17 14:02:07 +08:00
parent 1924d0740d
commit 0a0ddb0eaf
No known key found for this signature in database
GPG Key ID: 71B321E14F898C3D
2 changed files with 28 additions and 8 deletions

View File

@ -10,6 +10,7 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using Jellyfin.Data.Enums; using Jellyfin.Data.Enums;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Diagnostics;
namespace Emby.Server.Implementations.Library.Validators namespace Emby.Server.Implementations.Library.Validators
{ {
@ -101,18 +102,23 @@ namespace Emby.Server.Implementations.Library.Validators
// won't automatically create collection if only one movie in it // won't automatically create collection if only one movie in it
if (movieList.Count >= 2) if (movieList.Count >= 2)
{ {
boxSet = await _collectionManager.CreateCollectionAsync(new CollectionCreationOptions var movieIds = FliterMoviesByOption(movieList);
{ if (movieIds.Count >= 2) {
Name = collectionName, // at least 2 movies have AutoCollection option enable
IsLocked = true boxSet = await _collectionManager.CreateCollectionAsync(new CollectionCreationOptions
}); {
Name = collectionName,
IsLocked = true
});
await _collectionManager.AddToCollectionAsync(boxSet.Id, movieList.Select(m => m.Id)); await _collectionManager.AddToCollectionAsync(boxSet.Id, movieIds);
}
} }
} }
else else
{ {
await _collectionManager.AddToCollectionAsync(boxSet.Id, movieList.Select(m => m.Id)); var movieIds = FliterMoviesByOption(movieList);
await _collectionManager.AddToCollectionAsync(boxSet.Id, movieIds);
} }
numComplete++; numComplete++;
@ -130,5 +136,17 @@ namespace Emby.Server.Implementations.Library.Validators
progress.Report(100); progress.Report(100);
} }
private List<Guid> FliterMoviesByOption(List<Movie> movieList) {
List<Guid> movieIds = new List<Guid>();
foreach (var movie in movieList)
{
if (_libraryManager.GetLibraryOptions(movie).AutoCollection)
{
movieIds.Add(movie.Id);
}
}
return movieIds;
}
} }
} }

View File

@ -16,6 +16,7 @@ namespace MediaBrowser.Model.Configuration
SkipSubtitlesIfAudioTrackMatches = true; SkipSubtitlesIfAudioTrackMatches = true;
RequirePerfectSubtitleMatch = true; RequirePerfectSubtitleMatch = true;
AutoCollection = true;
EnablePhotos = true; EnablePhotos = true;
SaveSubtitlesWithMedia = true; SaveSubtitlesWithMedia = true;
EnableRealtimeMonitor = true; EnableRealtimeMonitor = true;
@ -80,6 +81,7 @@ namespace MediaBrowser.Model.Configuration
public bool RequirePerfectSubtitleMatch { get; set; } public bool RequirePerfectSubtitleMatch { get; set; }
public bool SaveSubtitlesWithMedia { get; set; } public bool SaveSubtitlesWithMedia { get; set; }
public bool AutoCollection { get; set; }
public TypeOptions[] TypeOptions { get; set; } public TypeOptions[] TypeOptions { get; set; }