feat: add Trailer Pre-Roll and Feature Pre-Roll bumpers
All checks were successful
Publish Release / release (push) Successful in 14s
All checks were successful
Publish Release / release (push) Successful in 14s
Adds two optional IIntroProvider bumper slots, mirroring CherryFloors' cinema mode plugin: a "Trailer Pre-Roll" played before the trailer block and a "Feature Pre-Roll" played right before the movie/episode. Each is configured by picking an existing Jellyfin Movie library, from which a random Movie is injected as the bumper. Bump version to 1.0.0.5. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -68,5 +68,15 @@ namespace Jellyfin.Plugin.CinemaTrailers4Jellyfins.Configuration
|
||||
|
||||
/// <summary>Also inject trailers before TV episodes, but only before the first episode a user watches each day.</summary>
|
||||
public bool TrailersForEpisodes { get; set; } = false;
|
||||
|
||||
// ── Pre-Roll Bumpers ─────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Jellyfin movie library (VirtualFolder ItemId) to pick a random "Trailer Pre-Roll"
|
||||
/// bumper from, played before the trailer block. Empty = disabled.</summary>
|
||||
public string TrailerPreRollLibraryId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Jellyfin movie library (VirtualFolder ItemId) to pick a random "Feature Pre-Roll"
|
||||
/// bumper from, played after the trailer block, right before the feature. Empty = disabled.</summary>
|
||||
public string FeaturePreRollLibraryId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,6 +341,38 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<!-- Pre-Roll Bumpers -->
|
||||
<fieldset class="verticalSection verticalSection-extrabottompadding">
|
||||
<legend><h3 class="sectionTitle">Pre-Roll Bumpers</h3></legend>
|
||||
<p class="fieldDescription">
|
||||
Optional: pick existing Jellyfin Movie libraries to pull random bumper
|
||||
videos from, bookending the trailer block above. Each is independent —
|
||||
leave either set to "None" to disable it.
|
||||
</p>
|
||||
|
||||
<div class="selectContainer">
|
||||
<label class="selectLabel" for="trailer-preroll-library">Trailer Pre-Roll library</label>
|
||||
<select is="emby-select" id="trailer-preroll-library" class="emby-select-withcolor emby-select">
|
||||
<option value="">— None (disabled) —</option>
|
||||
</select>
|
||||
<div class="fieldDescription">
|
||||
A Movie library to pick a random "Now Playing" style bumper from,
|
||||
played before the trailer block.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="selectContainer">
|
||||
<label class="selectLabel" for="feature-preroll-library">Feature Pre-Roll library</label>
|
||||
<select is="emby-select" id="feature-preroll-library" class="emby-select-withcolor emby-select">
|
||||
<option value="">— None (disabled) —</option>
|
||||
</select>
|
||||
<div class="fieldDescription">
|
||||
A Movie library to pick a random "Feature Presentation" style bumper
|
||||
from, played right before the movie/episode (after trailers).
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<!-- Advanced -->
|
||||
<fieldset class="verticalSection verticalSection-extrabottompadding">
|
||||
<legend><h3 class="sectionTitle">Advanced</h3></legend>
|
||||
@@ -375,7 +407,24 @@
|
||||
|
||||
$('.cinemaTrailers4JellyfinsConfigPage').on('pageshow', function () {
|
||||
Dashboard.showLoadingMsg();
|
||||
ApiClient.getPluginConfiguration(pluginId).then(function (config) {
|
||||
Promise.all([
|
||||
ApiClient.getPluginConfiguration(pluginId),
|
||||
ApiClient.getJSON(ApiClient.getUrl('Library/VirtualFolders'))
|
||||
]).then(function (results) {
|
||||
var config = results[0];
|
||||
var movieFolders = results[1].filter(function (f) { return f.CollectionType === 'movies'; });
|
||||
[['trailer-preroll-library', config.TrailerPreRollLibraryId],
|
||||
['feature-preroll-library', config.FeaturePreRollLibraryId]]
|
||||
.forEach(function (entry) {
|
||||
var select = document.getElementById(entry[0]);
|
||||
movieFolders.forEach(function (f) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = f.ItemId;
|
||||
opt.text = f.Name;
|
||||
select.appendChild(opt);
|
||||
});
|
||||
select.value = entry[1] || '';
|
||||
});
|
||||
document.getElementById('tmdb-api-key').value = config.TmdbApiKey || '';
|
||||
document.getElementById('source-now-playing').checked = config.SourceNowPlaying !== false;
|
||||
document.getElementById('source-upcoming').checked = config.SourceUpcoming !== false;
|
||||
@@ -442,6 +491,8 @@
|
||||
config.FilterByRating = document.getElementById('filter-rating').checked;
|
||||
config.AvoidRepeats = document.getElementById('avoid-repeats').checked;
|
||||
config.TrailersForEpisodes = document.getElementById('trailers-for-episodes').checked;
|
||||
config.TrailerPreRollLibraryId = document.getElementById('trailer-preroll-library').value;
|
||||
config.FeaturePreRollLibraryId = document.getElementById('feature-preroll-library').value;
|
||||
ApiClient.updatePluginConfiguration(pluginId, config)
|
||||
.then(Dashboard.processPluginConfigurationUpdateResult);
|
||||
});
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<RootNamespace>Jellyfin.Plugin.CinemaTrailers4Jellyfins</RootNamespace>
|
||||
<AssemblyVersion>1.0.0.4</AssemblyVersion>
|
||||
<FileVersion>1.0.0.4</FileVersion>
|
||||
<AssemblyVersion>1.0.0.5</AssemblyVersion>
|
||||
<FileVersion>1.0.0.5</FileVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateDocumentationFile>false</GenerateDocumentationFile>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
|
||||
@@ -41,7 +41,14 @@ namespace Jellyfin.Plugin.CinemaTrailers4Jellyfins.Services
|
||||
public Task<IEnumerable<IntroInfo>> GetIntros(BaseItem item, User user)
|
||||
{
|
||||
var config = Plugin.Instance?.Configuration;
|
||||
if (config == null || config.TrailersPerMovie <= 0)
|
||||
if (config == null)
|
||||
return Task.FromResult(Enumerable.Empty<IntroInfo>());
|
||||
|
||||
var trailersEnabled = config.TrailersPerMovie > 0;
|
||||
var preRollEnabled = !string.IsNullOrEmpty(config.TrailerPreRollLibraryId);
|
||||
var featurePreRollEnabled = !string.IsNullOrEmpty(config.FeaturePreRollLibraryId);
|
||||
|
||||
if (!trailersEnabled && !preRollEnabled && !featurePreRollEnabled)
|
||||
return Task.FromResult(Enumerable.Empty<IntroInfo>());
|
||||
|
||||
// The item used for genre/rating filtering. For episodes this is the
|
||||
@@ -73,57 +80,104 @@ namespace Jellyfin.Plugin.CinemaTrailers4Jellyfins.Services
|
||||
|
||||
var outputFolder = config.DownloadFolder?.TrimEnd(
|
||||
Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
|
||||
if (string.IsNullOrEmpty(outputFolder))
|
||||
return Task.FromResult(Enumerable.Empty<IntroInfo>());
|
||||
|
||||
// Break recursion: don't inject intros before items from our own output folder
|
||||
// (covers both the fake-movie files and their trailer extras).
|
||||
if (item.Path?.StartsWith(outputFolder, StringComparison.OrdinalIgnoreCase) == true)
|
||||
if (!string.IsNullOrEmpty(outputFolder)
|
||||
&& item.Path?.StartsWith(outputFolder, StringComparison.OrdinalIgnoreCase) == true)
|
||||
return Task.FromResult(Enumerable.Empty<IntroInfo>());
|
||||
|
||||
// Server-scoped query so hidden libraries don't block trailer discovery.
|
||||
var pairs = _libraryManager
|
||||
var intros = new List<IntroInfo>();
|
||||
|
||||
if (preRollEnabled)
|
||||
{
|
||||
var preRoll = GetRandomLibraryMovieIntro(config.TrailerPreRollLibraryId, item.Id);
|
||||
if (preRoll != null)
|
||||
intros.Add(preRoll);
|
||||
}
|
||||
|
||||
if (trailersEnabled && !string.IsNullOrEmpty(outputFolder))
|
||||
{
|
||||
// Server-scoped query so hidden libraries don't block trailer discovery.
|
||||
var pairs = _libraryManager
|
||||
.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
IncludeItemTypes = new[] { BaseItemKind.Movie },
|
||||
Recursive = true,
|
||||
})
|
||||
.OfType<Movie>()
|
||||
.Where(m =>
|
||||
m.Path?.StartsWith(outputFolder, StringComparison.OrdinalIgnoreCase) == true
|
||||
&& m.LocalTrailers.Count > 0
|
||||
// Keep TV show trailers for episodes and movie trailers for movies separate.
|
||||
&& m.Tags.Contains(TrailerTags.TvShow, StringComparer.OrdinalIgnoreCase) == isEpisode)
|
||||
.SelectMany(m => m.LocalTrailers.Select(t => (Movie: m, Trailer: t)))
|
||||
.ToList();
|
||||
|
||||
if (pairs.Count == 0)
|
||||
{
|
||||
_logger.LogDebug(
|
||||
"|CinemaTrailers4Jellyfins| No indexed {Kind} trailers in {Folder}. "
|
||||
+ "Ensure the output folder is added as a Jellyfin Movies library and scanned.",
|
||||
isEpisode ? "TV show" : "movie",
|
||||
outputFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Apply enabled filters. If nothing survives, fall back to the full pool.
|
||||
var filtered = ApplyFilters(pairs, feature, config);
|
||||
var pool = filtered.Count > 0 ? filtered : pairs;
|
||||
|
||||
// Prefer unseen trailers within the pool; reset the cycle when all have been shown.
|
||||
pool = ApplyAvoidRepeats(pool, user.Id, config.AvoidRepeats);
|
||||
|
||||
var selected = pool
|
||||
.OrderBy(_ => _rng.Next())
|
||||
.Take(config.TrailersPerMovie)
|
||||
.ToList();
|
||||
|
||||
if (config.AvoidRepeats)
|
||||
MarkSeen(user.Id, selected.Select(p => p.Trailer.Id));
|
||||
|
||||
intros.AddRange(selected.Select(p => new IntroInfo { ItemId = p.Trailer.Id, Path = p.Trailer.Path }));
|
||||
}
|
||||
}
|
||||
|
||||
if (featurePreRollEnabled)
|
||||
{
|
||||
var featureRoll = GetRandomLibraryMovieIntro(config.FeaturePreRollLibraryId, item.Id);
|
||||
if (featureRoll != null)
|
||||
intros.Add(featureRoll);
|
||||
}
|
||||
|
||||
return Task.FromResult<IEnumerable<IntroInfo>>(intros);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Picks a random Movie from the given Jellyfin library (VirtualFolder ItemId) to use as a
|
||||
/// pre-roll/post-roll bumper, excluding the item currently being played.
|
||||
/// </summary>
|
||||
private IntroInfo? GetRandomLibraryMovieIntro(string libraryId, Guid excludeId)
|
||||
{
|
||||
if (!Guid.TryParse(libraryId, out var parsedId))
|
||||
return null;
|
||||
|
||||
var movies = _libraryManager
|
||||
.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
IncludeItemTypes = new[] { BaseItemKind.Movie },
|
||||
TopParentIds = new[] { parsedId },
|
||||
Recursive = true,
|
||||
})
|
||||
.OfType<Movie>()
|
||||
.Where(m =>
|
||||
m.Path?.StartsWith(outputFolder, StringComparison.OrdinalIgnoreCase) == true
|
||||
&& m.LocalTrailers.Count > 0
|
||||
// Keep TV show trailers for episodes and movie trailers for movies separate.
|
||||
&& m.Tags.Contains(TrailerTags.TvShow, StringComparer.OrdinalIgnoreCase) == isEpisode)
|
||||
.SelectMany(m => m.LocalTrailers.Select(t => (Movie: m, Trailer: t)))
|
||||
.Where(m => m.Id != excludeId)
|
||||
.ToList();
|
||||
|
||||
if (pairs.Count == 0)
|
||||
{
|
||||
_logger.LogDebug(
|
||||
"|CinemaTrailers4Jellyfins| No indexed {Kind} trailers in {Folder}. "
|
||||
+ "Ensure the output folder is added as a Jellyfin Movies library and scanned.",
|
||||
isEpisode ? "TV show" : "movie",
|
||||
outputFolder);
|
||||
return Task.FromResult(Enumerable.Empty<IntroInfo>());
|
||||
}
|
||||
if (movies.Count == 0)
|
||||
return null;
|
||||
|
||||
// Apply enabled filters. If nothing survives, fall back to the full pool.
|
||||
var filtered = ApplyFilters(pairs, feature, config);
|
||||
var pool = filtered.Count > 0 ? filtered : pairs;
|
||||
|
||||
// Prefer unseen trailers within the pool; reset the cycle when all have been shown.
|
||||
pool = ApplyAvoidRepeats(pool, user.Id, config.AvoidRepeats);
|
||||
|
||||
var selected = pool
|
||||
.OrderBy(_ => _rng.Next())
|
||||
.Take(config.TrailersPerMovie)
|
||||
.ToList();
|
||||
|
||||
if (config.AvoidRepeats)
|
||||
MarkSeen(user.Id, selected.Select(p => p.Trailer.Id));
|
||||
|
||||
var intros = selected.Select(p => new IntroInfo { ItemId = p.Trailer.Id, Path = p.Trailer.Path });
|
||||
return Task.FromResult<IEnumerable<IntroInfo>>(intros.ToList());
|
||||
var movie = movies[_rng.Next(movies.Count)];
|
||||
return new IntroInfo { ItemId = movie.Id, Path = movie.Path };
|
||||
}
|
||||
|
||||
private static List<(Movie Movie, BaseItem Trailer)> ApplyFilters(
|
||||
|
||||
Reference in New Issue
Block a user