feat: add genre, rating, and avoid-repeats trailer filters
All checks were successful
Publish Release / release (push) Successful in 23s
All checks were successful
Publish Release / release (push) Successful in 23s
Trailer selection now supports three optional filters:
- Genre match: prefer trailers whose fake-movie genre overlaps with the
feature being played (requires TMDB genres in NFO)
- Age rating ceiling: exclude trailers rated higher than the feature
(requires TMDB certification in NFO)
- Avoid repeats: cycle through all trailers before replaying any;
resets per-user once the pool is exhausted
Genre and certification are fetched from TMDB at download time via a
single /movie/{id}?append_to_response=release_dates call and written
into the fake-movie NFO as <genre> and <mpaa> tags. All filters fall
back to the full unfiltered pool when no match is found.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,8 @@ namespace Jellyfin.Plugin.CinemaTrailers4Jellyfins.Services
|
||||
public int? Year => DateTime.TryParse(ReleaseDate, out var d) ? d.Year : (int?)null;
|
||||
}
|
||||
|
||||
public record TmdbMovieMetadata(IReadOnlyList<string> Genres, string? Certification);
|
||||
|
||||
public class TmdbService : IDisposable
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
@@ -187,6 +189,77 @@ namespace Jellyfin.Plugin.CinemaTrailers4Jellyfins.Services
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the genre names and US theatrical certification (G, PG, PG-13, R, NC-17)
|
||||
/// for a movie. Uses a single /movie/{id}?append_to_response=release_dates call.
|
||||
/// </summary>
|
||||
public async Task<TmdbMovieMetadata> GetMovieMetadataAsync(
|
||||
string tmdbId,
|
||||
string apiKey,
|
||||
CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = $"{BaseUrl}/movie/{tmdbId}?append_to_response=release_dates&language=en-US";
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||
ApplyAuth(request, apiKey);
|
||||
using var response = await _httpClient.SendAsync(request, ct).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var json = await response.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
|
||||
using var doc = JsonDocument.Parse(json);
|
||||
|
||||
var genres = new List<string>();
|
||||
if (doc.RootElement.TryGetProperty("genres", out var genreArr))
|
||||
{
|
||||
foreach (var g in genreArr.EnumerateArray())
|
||||
{
|
||||
if (g.TryGetProperty("name", out var name))
|
||||
{
|
||||
var genreName = name.GetString();
|
||||
if (!string.IsNullOrEmpty(genreName))
|
||||
genres.Add(genreName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string? certification = null;
|
||||
if (doc.RootElement.TryGetProperty("release_dates", out var releaseDates)
|
||||
&& releaseDates.TryGetProperty("results", out var rdResults))
|
||||
{
|
||||
foreach (var country in rdResults.EnumerateArray())
|
||||
{
|
||||
if (!country.TryGetProperty("iso_3166_1", out var iso)
|
||||
|| !string.Equals(iso.GetString(), "US", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
if (!country.TryGetProperty("release_dates", out var dates))
|
||||
break;
|
||||
|
||||
foreach (var date in dates.EnumerateArray())
|
||||
{
|
||||
if (!date.TryGetProperty("certification", out var cert))
|
||||
continue;
|
||||
var certStr = cert.GetString();
|
||||
if (!string.IsNullOrWhiteSpace(certStr))
|
||||
{
|
||||
certification = certStr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new TmdbMovieMetadata(genres.AsReadOnly(), certification);
|
||||
}
|
||||
catch (OperationCanceledException) { throw; }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "|CinemaTrailers4Jellyfins| GetMovieMetadata failed for TMDB ID {Id}", tmdbId);
|
||||
return new TmdbMovieMetadata(Array.Empty<string>(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<TmdbVideo>> GetTrailersAsync(
|
||||
string tmdbId,
|
||||
string apiKey,
|
||||
|
||||
Reference in New Issue
Block a user