Update README.md
This commit is contained in:
27
Api/NewReleasesController.cs
Normal file
27
Api/NewReleasesController.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Jellyfin.Plugin.NewReleases.Models;
|
||||
using Jellyfin.Plugin.NewReleases.Services;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Jellyfin.Plugin.NewReleases.Api;
|
||||
|
||||
[ApiController]
|
||||
[Route("Plugins/NewReleases")]
|
||||
public sealed class NewReleasesController : ControllerBase
|
||||
{
|
||||
private readonly NewReleasesService _newReleasesService;
|
||||
|
||||
public NewReleasesController(ILibraryManager libraryManager)
|
||||
{
|
||||
_newReleasesService = new NewReleasesService(libraryManager);
|
||||
}
|
||||
|
||||
[HttpGet("Movies")]
|
||||
[ProducesResponseType(typeof(NewReleasesResponse), StatusCodes.Status200OK)]
|
||||
public ActionResult<NewReleasesResponse> GetNewlyReleasedMovies()
|
||||
{
|
||||
var response = _newReleasesService.GetNewlyReleasedMovies();
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
17
Jellyfin.Plugin.NewReleases.csproj
Normal file
17
Jellyfin.Plugin.NewReleases.csproj
Normal file
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Jellyfin.Controller" Version="10.10.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
10
Models/NewReleaseMovieDto.cs
Normal file
10
Models/NewReleaseMovieDto.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Jellyfin.Plugin.NewReleases.Models;
|
||||
|
||||
public sealed class NewReleaseMovieDto
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public DateTime PremiereDate { get; set; }
|
||||
}
|
||||
8
Models/NewReleasesResponse.cs
Normal file
8
Models/NewReleasesResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Jellyfin.Plugin.NewReleases.Models;
|
||||
|
||||
public sealed class NewReleasesResponse
|
||||
{
|
||||
public int TotalRecordCount { get; set; }
|
||||
|
||||
public List<NewReleaseMovieDto> Items { get; set; } = [];
|
||||
}
|
||||
22
Plugin.cs
Normal file
22
Plugin.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.NewReleases;
|
||||
|
||||
public sealed class Plugin : BasePlugin<PluginConfiguration>
|
||||
{
|
||||
public static Plugin? Instance { get; private set; }
|
||||
|
||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
|
||||
: base(applicationPaths, xmlSerializer)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override string Name => "Jellyfin New Releases";
|
||||
|
||||
public override Guid Id => new("cc3f7cd7-e910-4f09-bf89-e9c7ba7fca77");
|
||||
|
||||
public override string Description => "Provides newly released movies based on PremiereDate.";
|
||||
}
|
||||
10
PluginConfiguration.cs
Normal file
10
PluginConfiguration.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using MediaBrowser.Model.Plugins;
|
||||
|
||||
namespace Jellyfin.Plugin.NewReleases;
|
||||
|
||||
public sealed class PluginConfiguration : BasePluginConfiguration
|
||||
{
|
||||
public int MaxItems { get; set; } = 20;
|
||||
|
||||
public int ReleaseWindowDays { get; set; } = 365;
|
||||
}
|
||||
52
Services/NewReleasesService.cs
Normal file
52
Services/NewReleasesService.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user