53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using Jellyfin.Plugin.NewReleases.Models;
|
|
using Jellyfin.Data.Enums;
|
|
using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
namespace Jellyfin.Plugin.NewReleases.Services;
|
|
|
|
public sealed class NewReleasesService
|
|
{
|
|
private const int DefaultMaxItems = 20;
|
|
private const int DefaultReleaseWindowDays = 365;
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
public NewReleasesService(ILibraryManager libraryManager)
|
|
{
|
|
_libraryManager = libraryManager;
|
|
}
|
|
|
|
public NewReleasesResponse GetNewlyReleasedMovies()
|
|
{
|
|
var configuration = Plugin.Instance?.Configuration ?? new PluginConfiguration();
|
|
var maxItems = configuration.MaxItems > 0 ? configuration.MaxItems : DefaultMaxItems;
|
|
var releaseWindowDays = configuration.ReleaseWindowDays > 0 ? configuration.ReleaseWindowDays : DefaultReleaseWindowDays;
|
|
var cutoffUtc = DateTime.UtcNow.AddDays(-releaseWindowDays);
|
|
|
|
var query = new InternalItemsQuery
|
|
{
|
|
IncludeItemTypes = [BaseItemKind.Movie],
|
|
Recursive = true
|
|
};
|
|
|
|
var items = _libraryManager.GetItemList(query)
|
|
.Where(x => x.PremiereDate.HasValue)
|
|
.Where(x => x.PremiereDate!.Value.ToUniversalTime() >= cutoffUtc)
|
|
.OrderByDescending(x => x.PremiereDate!.Value)
|
|
.Take(maxItems)
|
|
.Select(x => new NewReleaseMovieDto
|
|
{
|
|
Id = x.Id.ToString("N"),
|
|
Name = x.Name,
|
|
PremiereDate = x.PremiereDate!.Value.ToUniversalTime()
|
|
})
|
|
.ToList();
|
|
|
|
return new NewReleasesResponse
|
|
{
|
|
TotalRecordCount = items.Count,
|
|
Items = items
|
|
};
|
|
}
|
|
}
|