Merge pull request 'feat(api): channel templates entity + CRUD (#64)' (#133) from feat/64-channel-templates into main
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 4m23s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (push) Successful in 4m46s
Build ErsatzTV Image / Build & push image (amd64) (push) Successful in 5m0s

This commit was merged in pull request #133.
This commit is contained in:
2026-07-06 17:33:31 +00:00
40 changed files with 17715 additions and 43 deletions
@@ -0,0 +1,24 @@
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
namespace ErsatzTV.Application.ChannelTemplates;
internal static class ChannelTemplateDefault
{
public static async Task<int?> GetDefaultTemplateId(
IConfigElementRepository configElementRepository,
CancellationToken cancellationToken)
{
Option<int> maybeDefault =
await configElementRepository.GetValue<int>(
ConfigElementKey.ChannelTemplatesDefaultTemplateId,
cancellationToken);
int? result = null;
foreach (int id in maybeDefault)
{
result = id;
}
return result;
}
}
@@ -0,0 +1,38 @@
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
namespace ErsatzTV.Application.ChannelTemplates;
public static class ChannelTemplateMapper
{
public static ChannelTemplateResponseModel ProjectToResponseModel(ChannelTemplate template, int? defaultTemplateId) =>
new(
template.Id,
template.Name,
template.Description,
template.IsSystem,
defaultTemplateId == template.Id,
template.FFmpegProfileId,
template.WatermarkId,
template.FallbackFillerId,
template.PreRollFillerId,
template.MidRollFillerId,
template.PostRollFillerId,
template.StreamSelectorMode,
template.StreamSelector,
template.PreferredAudioLanguageCode,
template.PreferredAudioTitle,
template.PlayoutSource,
template.PlayoutMode,
template.StreamingMode,
template.PreferredSubtitleLanguageCode,
template.SubtitleMode,
template.MusicVideoCreditsMode,
template.MusicVideoCreditsTemplate,
template.SongVideoMode,
template.TranscodeMode,
template.IdleBehavior,
template.ShuffleScheduleItems,
template.RandomStartPoint,
template.FixedStartTimeBehavior);
}
@@ -0,0 +1,155 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Domain.Filler;
using ErsatzTV.Core.Errors;
using ErsatzTV.Core.Scheduling;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.ChannelTemplates;
public abstract record ChannelTemplateCommandBase(
string Name,
string Description,
int FFmpegProfileId,
int? WatermarkId,
int? FallbackFillerId,
int? PreRollFillerId,
int? MidRollFillerId,
int? PostRollFillerId,
ChannelStreamSelectorMode StreamSelectorMode,
string StreamSelector,
string PreferredAudioLanguageCode,
string PreferredAudioTitle,
ChannelPlayoutSource PlayoutSource,
ChannelPlayoutMode PlayoutMode,
StreamingMode StreamingMode,
string PreferredSubtitleLanguageCode,
ChannelSubtitleMode SubtitleMode,
ChannelMusicVideoCreditsMode MusicVideoCreditsMode,
string MusicVideoCreditsTemplate,
ChannelSongVideoMode SongVideoMode,
ChannelTranscodeMode TranscodeMode,
ChannelIdleBehavior IdleBehavior,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior)
{
internal static async Task<Option<BaseError>> ValidateCommon(
TvContext dbContext,
ChannelTemplateCommandBase request,
int? existingTemplateId,
CancellationToken cancellationToken)
{
string name = NormalizeName(request.Name);
if (string.IsNullOrWhiteSpace(name))
{
return BaseError.New("Name is required.");
}
if (name.Length > 50)
{
return BaseError.New("Name must be 50 characters or less.");
}
if (request.Description?.Length > 500)
{
return BaseError.New("Description must be 500 characters or less.");
}
bool duplicateName = await dbContext.ChannelTemplates
.AnyAsync(t => t.Id != existingTemplateId && t.Name == name, cancellationToken);
if (duplicateName)
{
return BaseError.New("Channel template name must be unique.");
}
bool ffmpegProfileExists = await dbContext.FFmpegProfiles
.AnyAsync(p => p.Id == request.FFmpegProfileId, cancellationToken);
if (!ffmpegProfileExists)
{
return new NotFoundError($"FFmpegProfile {request.FFmpegProfileId} does not exist.");
}
foreach (int watermarkId in Optional(request.WatermarkId))
{
bool watermarkExists = await dbContext.ChannelWatermarks
.AnyAsync(w => w.Id == watermarkId, cancellationToken);
if (!watermarkExists)
{
return new NotFoundError($"Watermark {watermarkId} does not exist.");
}
}
Option<BaseError> maybeFillerError =
await FillerMustExist(dbContext, request.FallbackFillerId, FillerKind.Fallback, cancellationToken);
if (maybeFillerError.IsSome)
{
return maybeFillerError;
}
maybeFillerError = await FillerMustExist(dbContext, request.PreRollFillerId, FillerKind.PreRoll, cancellationToken);
if (maybeFillerError.IsSome)
{
return maybeFillerError;
}
maybeFillerError = await FillerMustExist(dbContext, request.MidRollFillerId, FillerKind.MidRoll, cancellationToken);
if (maybeFillerError.IsSome)
{
return maybeFillerError;
}
return await FillerMustExist(dbContext, request.PostRollFillerId, FillerKind.PostRoll, cancellationToken);
}
internal void ApplyTo(ChannelTemplate template)
{
template.Name = NormalizeName(Name);
template.Description = Description ?? string.Empty;
template.FFmpegProfileId = FFmpegProfileId;
template.WatermarkId = WatermarkId;
template.FallbackFillerId = FallbackFillerId;
template.PreRollFillerId = PreRollFillerId;
template.MidRollFillerId = MidRollFillerId;
template.PostRollFillerId = PostRollFillerId;
template.StreamSelectorMode = StreamSelectorMode;
template.StreamSelector = StreamSelector ?? string.Empty;
template.PreferredAudioLanguageCode = PreferredAudioLanguageCode ?? string.Empty;
template.PreferredAudioTitle = PreferredAudioTitle ?? string.Empty;
template.PlayoutSource = PlayoutSource;
template.PlayoutMode = PlayoutMode;
template.StreamingMode = StreamingMode;
template.PreferredSubtitleLanguageCode = PreferredSubtitleLanguageCode ?? string.Empty;
template.SubtitleMode = SubtitleMode;
template.MusicVideoCreditsMode = MusicVideoCreditsMode;
template.MusicVideoCreditsTemplate = MusicVideoCreditsTemplate ?? string.Empty;
template.SongVideoMode = SongVideoMode;
template.TranscodeMode = TranscodeMode;
template.IdleBehavior = IdleBehavior;
template.ShuffleScheduleItems = ShuffleScheduleItems;
template.RandomStartPoint = RandomStartPoint;
template.FixedStartTimeBehavior = FixedStartTimeBehavior;
}
internal static string NormalizeName(string name) => (name ?? string.Empty).Trim();
private static async Task<Option<BaseError>> FillerMustExist(
TvContext dbContext,
int? fillerPresetId,
FillerKind fillerKind,
CancellationToken cancellationToken)
{
foreach (int id in Optional(fillerPresetId))
{
bool exists = await dbContext.FillerPresets
.AnyAsync(f => f.Id == id && f.FillerKind == fillerKind, cancellationToken);
if (!exists)
{
return new NotFoundError($"{fillerKind} filler {id} does not exist.");
}
}
return Option<BaseError>.None;
}
}
@@ -0,0 +1,60 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Scheduling;
namespace ErsatzTV.Application.ChannelTemplates;
public record CreateChannelTemplate(
string Name,
string Description,
int FFmpegProfileId,
int? WatermarkId,
int? FallbackFillerId,
int? PreRollFillerId,
int? MidRollFillerId,
int? PostRollFillerId,
ChannelStreamSelectorMode StreamSelectorMode,
string StreamSelector,
string PreferredAudioLanguageCode,
string PreferredAudioTitle,
ChannelPlayoutSource PlayoutSource,
ChannelPlayoutMode PlayoutMode,
StreamingMode StreamingMode,
string PreferredSubtitleLanguageCode,
ChannelSubtitleMode SubtitleMode,
ChannelMusicVideoCreditsMode MusicVideoCreditsMode,
string MusicVideoCreditsTemplate,
ChannelSongVideoMode SongVideoMode,
ChannelTranscodeMode TranscodeMode,
ChannelIdleBehavior IdleBehavior,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior)
: ChannelTemplateCommandBase(
Name,
Description,
FFmpegProfileId,
WatermarkId,
FallbackFillerId,
PreRollFillerId,
MidRollFillerId,
PostRollFillerId,
StreamSelectorMode,
StreamSelector,
PreferredAudioLanguageCode,
PreferredAudioTitle,
PlayoutSource,
PlayoutMode,
StreamingMode,
PreferredSubtitleLanguageCode,
SubtitleMode,
MusicVideoCreditsMode,
MusicVideoCreditsTemplate,
SongVideoMode,
TranscodeMode,
IdleBehavior,
ShuffleScheduleItems,
RandomStartPoint,
FixedStartTimeBehavior),
IRequest<Either<BaseError, ChannelTemplateResponseModel>>;
@@ -0,0 +1,36 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.ChannelTemplates;
public class CreateChannelTemplateHandler(
IDbContextFactory<TvContext> dbContextFactory,
IConfigElementRepository configElementRepository)
: IRequestHandler<CreateChannelTemplate, Either<BaseError, ChannelTemplateResponseModel>>
{
public async Task<Either<BaseError, ChannelTemplateResponseModel>> Handle(
CreateChannelTemplate request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
Option<BaseError> maybeError =
await ChannelTemplateCommandBase.ValidateCommon(dbContext, request, null, cancellationToken);
foreach (BaseError error in maybeError)
{
return error;
}
var template = new ChannelTemplate();
request.ApplyTo(template);
await dbContext.ChannelTemplates.AddAsync(template, cancellationToken);
await dbContext.SaveChangesAsync(cancellationToken);
int? defaultTemplateId =
await ChannelTemplateDefault.GetDefaultTemplateId(configElementRepository, cancellationToken);
return ChannelTemplateMapper.ProjectToResponseModel(template, defaultTemplateId);
}
}
@@ -0,0 +1,5 @@
using ErsatzTV.Core;
namespace ErsatzTV.Application.ChannelTemplates;
public record DeleteChannelTemplate(int ChannelTemplateId) : IRequest<Either<BaseError, Unit>>;
@@ -0,0 +1,42 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Errors;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.ChannelTemplates;
public class DeleteChannelTemplateHandler(
IDbContextFactory<TvContext> dbContextFactory,
IConfigElementRepository configElementRepository)
: IRequestHandler<DeleteChannelTemplate, Either<BaseError, Unit>>
{
public async Task<Either<BaseError, Unit>> Handle(DeleteChannelTemplate request, CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
Option<ChannelTemplate> maybeTemplate = await dbContext.ChannelTemplates
.SelectOneAsync(t => t.Id, t => t.Id == request.ChannelTemplateId, cancellationToken);
foreach (ChannelTemplate template in maybeTemplate)
{
if (template.IsSystem)
{
return BaseError.New("System templates cannot be deleted.");
}
int? defaultTemplateId =
await ChannelTemplateDefault.GetDefaultTemplateId(configElementRepository, cancellationToken);
if (defaultTemplateId == template.Id)
{
return BaseError.New("Default channel template cannot be deleted.");
}
dbContext.ChannelTemplates.Remove(template);
await dbContext.SaveChangesAsync(cancellationToken);
return Unit.Default;
}
return new NotFoundError($"ChannelTemplate {request.ChannelTemplateId} does not exist.");
}
}
@@ -0,0 +1,6 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Api.ChannelTemplates;
namespace ErsatzTV.Application.ChannelTemplates;
public record SetDefaultChannelTemplate(int ChannelTemplateId) : IRequest<Either<BaseError, ChannelTemplateResponseModel>>;
@@ -0,0 +1,36 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Errors;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.ChannelTemplates;
public class SetDefaultChannelTemplateHandler(
IDbContextFactory<TvContext> dbContextFactory,
IConfigElementRepository configElementRepository)
: IRequestHandler<SetDefaultChannelTemplate, Either<BaseError, ChannelTemplateResponseModel>>
{
public async Task<Either<BaseError, ChannelTemplateResponseModel>> Handle(
SetDefaultChannelTemplate request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
Option<ChannelTemplate> maybeTemplate = await dbContext.ChannelTemplates
.AsNoTracking()
.SelectOneAsync(t => t.Id, t => t.Id == request.ChannelTemplateId, cancellationToken);
foreach (ChannelTemplate template in maybeTemplate)
{
await configElementRepository.Upsert(
ConfigElementKey.ChannelTemplatesDefaultTemplateId,
template.Id,
cancellationToken);
return ChannelTemplateMapper.ProjectToResponseModel(template, template.Id);
}
return new NotFoundError($"ChannelTemplate {request.ChannelTemplateId} does not exist.");
}
}
@@ -0,0 +1,61 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Scheduling;
namespace ErsatzTV.Application.ChannelTemplates;
public record UpdateChannelTemplate(
int ChannelTemplateId,
string Name,
string Description,
int FFmpegProfileId,
int? WatermarkId,
int? FallbackFillerId,
int? PreRollFillerId,
int? MidRollFillerId,
int? PostRollFillerId,
ChannelStreamSelectorMode StreamSelectorMode,
string StreamSelector,
string PreferredAudioLanguageCode,
string PreferredAudioTitle,
ChannelPlayoutSource PlayoutSource,
ChannelPlayoutMode PlayoutMode,
StreamingMode StreamingMode,
string PreferredSubtitleLanguageCode,
ChannelSubtitleMode SubtitleMode,
ChannelMusicVideoCreditsMode MusicVideoCreditsMode,
string MusicVideoCreditsTemplate,
ChannelSongVideoMode SongVideoMode,
ChannelTranscodeMode TranscodeMode,
ChannelIdleBehavior IdleBehavior,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior)
: ChannelTemplateCommandBase(
Name,
Description,
FFmpegProfileId,
WatermarkId,
FallbackFillerId,
PreRollFillerId,
MidRollFillerId,
PostRollFillerId,
StreamSelectorMode,
StreamSelector,
PreferredAudioLanguageCode,
PreferredAudioTitle,
PlayoutSource,
PlayoutMode,
StreamingMode,
PreferredSubtitleLanguageCode,
SubtitleMode,
MusicVideoCreditsMode,
MusicVideoCreditsTemplate,
SongVideoMode,
TranscodeMode,
IdleBehavior,
ShuffleScheduleItems,
RandomStartPoint,
FixedStartTimeBehavior),
IRequest<Either<BaseError, ChannelTemplateResponseModel>>;
@@ -0,0 +1,51 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Errors;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.ChannelTemplates;
public class UpdateChannelTemplateHandler(
IDbContextFactory<TvContext> dbContextFactory,
IConfigElementRepository configElementRepository)
: IRequestHandler<UpdateChannelTemplate, Either<BaseError, ChannelTemplateResponseModel>>
{
public async Task<Either<BaseError, ChannelTemplateResponseModel>> Handle(
UpdateChannelTemplate request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
Option<ChannelTemplate> maybeTemplate = await dbContext.ChannelTemplates
.SelectOneAsync(t => t.Id, t => t.Id == request.ChannelTemplateId, cancellationToken);
foreach (ChannelTemplate template in maybeTemplate)
{
if (template.IsSystem)
{
return BaseError.New("System templates cannot be updated.");
}
Option<BaseError> maybeError =
await ChannelTemplateCommandBase.ValidateCommon(
dbContext,
request,
request.ChannelTemplateId,
cancellationToken);
foreach (BaseError error in maybeError)
{
return error;
}
request.ApplyTo(template);
await dbContext.SaveChangesAsync(cancellationToken);
int? defaultTemplateId =
await ChannelTemplateDefault.GetDefaultTemplateId(configElementRepository, cancellationToken);
return ChannelTemplateMapper.ProjectToResponseModel(template, defaultTemplateId);
}
return new NotFoundError($"ChannelTemplate {request.ChannelTemplateId} does not exist.");
}
}
@@ -0,0 +1,5 @@
using ErsatzTV.Core.Api.ChannelTemplates;
namespace ErsatzTV.Application.ChannelTemplates;
public record GetAllChannelTemplates : IRequest<List<ChannelTemplateResponseModel>>;
@@ -0,0 +1,28 @@
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.ChannelTemplates;
public class GetAllChannelTemplatesHandler(
IDbContextFactory<TvContext> dbContextFactory,
IConfigElementRepository configElementRepository)
: IRequestHandler<GetAllChannelTemplates, List<ChannelTemplateResponseModel>>
{
public async Task<List<ChannelTemplateResponseModel>> Handle(
GetAllChannelTemplates request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
int? defaultTemplateId =
await ChannelTemplateDefault.GetDefaultTemplateId(configElementRepository, cancellationToken);
return await dbContext.ChannelTemplates
.AsNoTracking()
.OrderBy(t => t.IsSystem ? 0 : 1)
.ThenBy(t => t.Name)
.Select(t => ChannelTemplateMapper.ProjectToResponseModel(t, defaultTemplateId))
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,5 @@
using ErsatzTV.Core.Api.ChannelTemplates;
namespace ErsatzTV.Application.ChannelTemplates;
public record GetChannelTemplateById(int ChannelTemplateId) : IRequest<Option<ChannelTemplateResponseModel>>;
@@ -0,0 +1,27 @@
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.ChannelTemplates;
public class GetChannelTemplateByIdHandler(
IDbContextFactory<TvContext> dbContextFactory,
IConfigElementRepository configElementRepository)
: IRequestHandler<GetChannelTemplateById, Option<ChannelTemplateResponseModel>>
{
public async Task<Option<ChannelTemplateResponseModel>> Handle(
GetChannelTemplateById request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
int? defaultTemplateId =
await ChannelTemplateDefault.GetDefaultTemplateId(configElementRepository, cancellationToken);
Option<ChannelTemplate> maybeTemplate = await dbContext.ChannelTemplates
.AsNoTracking()
.SelectOneAsync(t => t.Id, t => t.Id == request.ChannelTemplateId, cancellationToken);
return maybeTemplate.Map(t => ChannelTemplateMapper.ProjectToResponseModel(t, defaultTemplateId));
}
}
@@ -0,0 +1,5 @@
using ErsatzTV.Core.Api.ChannelTemplates;
namespace ErsatzTV.Application.ChannelTemplates;
public record GetDefaultChannelTemplate : IRequest<Option<ChannelTemplateResponseModel>>;
@@ -0,0 +1,40 @@
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.ChannelTemplates;
public class GetDefaultChannelTemplateHandler(
IDbContextFactory<TvContext> dbContextFactory,
IConfigElementRepository configElementRepository)
: IRequestHandler<GetDefaultChannelTemplate, Option<ChannelTemplateResponseModel>>
{
public async Task<Option<ChannelTemplateResponseModel>> Handle(
GetDefaultChannelTemplate request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
int? defaultTemplateId =
await ChannelTemplateDefault.GetDefaultTemplateId(configElementRepository, cancellationToken);
foreach (int id in Optional(defaultTemplateId))
{
Option<ChannelTemplate> maybeConfigured = await dbContext.ChannelTemplates
.AsNoTracking()
.SelectOneAsync(t => t.Id, t => t.Id == id, cancellationToken);
foreach (ChannelTemplate template in maybeConfigured)
{
return ChannelTemplateMapper.ProjectToResponseModel(template, id);
}
}
ChannelTemplate fallback = await dbContext.ChannelTemplates
.AsNoTracking()
.Where(t => t.IsSystem)
.OrderBy(t => t.Name)
.FirstOrDefaultAsync(cancellationToken);
return Optional(fallback).Map(t => ChannelTemplateMapper.ProjectToResponseModel(t, t.Id));
}
}
@@ -0,0 +1,36 @@
#nullable enable
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Scheduling;
namespace ErsatzTV.Core.Api.ChannelTemplates;
public record ChannelTemplateResponseModel(
int Id,
string Name,
string Description,
bool IsSystem,
bool IsDefault,
int FFmpegProfileId,
int? WatermarkId,
int? FallbackFillerId,
int? PreRollFillerId,
int? MidRollFillerId,
int? PostRollFillerId,
ChannelStreamSelectorMode StreamSelectorMode,
string? StreamSelector,
string? PreferredAudioLanguageCode,
string? PreferredAudioTitle,
ChannelPlayoutSource PlayoutSource,
ChannelPlayoutMode PlayoutMode,
StreamingMode StreamingMode,
string? PreferredSubtitleLanguageCode,
ChannelSubtitleMode SubtitleMode,
ChannelMusicVideoCreditsMode MusicVideoCreditsMode,
string? MusicVideoCreditsTemplate,
ChannelSongVideoMode SongVideoMode,
ChannelTranscodeMode TranscodeMode,
ChannelIdleBehavior IdleBehavior,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior);
+41
View File
@@ -0,0 +1,41 @@
using ErsatzTV.Core.Domain.Filler;
using ErsatzTV.Core.Scheduling;
namespace ErsatzTV.Core.Domain;
public class ChannelTemplate
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsSystem { get; set; }
public int FFmpegProfileId { get; set; }
public FFmpegProfile FFmpegProfile { get; set; }
public int? WatermarkId { get; set; }
public ChannelWatermark Watermark { get; set; }
public int? FallbackFillerId { get; set; }
public FillerPreset FallbackFiller { get; set; }
public int? PreRollFillerId { get; set; }
public FillerPreset PreRollFiller { get; set; }
public int? MidRollFillerId { get; set; }
public FillerPreset MidRollFiller { get; set; }
public int? PostRollFillerId { get; set; }
public FillerPreset PostRollFiller { get; set; }
public ChannelStreamSelectorMode StreamSelectorMode { get; set; }
public string StreamSelector { get; set; }
public string PreferredAudioLanguageCode { get; set; }
public string PreferredAudioTitle { get; set; }
public ChannelPlayoutSource PlayoutSource { get; set; }
public ChannelPlayoutMode PlayoutMode { get; set; }
public StreamingMode StreamingMode { get; set; }
public string PreferredSubtitleLanguageCode { get; set; }
public ChannelSubtitleMode SubtitleMode { get; set; }
public ChannelMusicVideoCreditsMode MusicVideoCreditsMode { get; set; }
public string MusicVideoCreditsTemplate { get; set; }
public ChannelSongVideoMode SongVideoMode { get; set; }
public ChannelTranscodeMode TranscodeMode { get; set; }
public ChannelIdleBehavior IdleBehavior { get; set; }
public bool ShuffleScheduleItems { get; set; }
public bool RandomStartPoint { get; set; }
public FixedStartTimeBehavior FixedStartTimeBehavior { get; set; }
}
+1
View File
@@ -23,6 +23,7 @@ public class ConfigElementKey
public static ConfigElementKey FFmpegPreferredLanguageCode => new("ffmpeg.preferred_language_code");
public static ConfigElementKey FFmpegGlobalWatermarkId => new("ffmpeg.global_watermark_id");
public static ConfigElementKey FFmpegGlobalFallbackFillerId => new("ffmpeg.global_fallback_filler_id");
public static ConfigElementKey ChannelTemplatesDefaultTemplateId => new("channel_templates.default_template_id");
public static ConfigElementKey FFmpegSegmenterTimeout => new("ffmpeg.segmenter.timeout_seconds");
public static ConfigElementKey FFmpegWorkAheadSegmenters => new("ffmpeg.segmenter.work_ahead_limit");
public static ConfigElementKey FFmpegInitialSegmentCount => new("ffmpeg.segmenter.initial_segment_count");
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,140 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ErsatzTV.Infrastructure.MySql.Migrations
{
/// <inheritdoc />
public partial class AddChannelTemplates : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ChannelTemplate",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, collation: "utf8mb4_general_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
Description = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false, defaultValue: "")
.Annotation("MySql:CharSet", "utf8mb4"),
IsSystem = table.Column<bool>(type: "tinyint(1)", nullable: false),
FFmpegProfileId = table.Column<int>(type: "int", nullable: false),
WatermarkId = table.Column<int>(type: "int", nullable: true),
FallbackFillerId = table.Column<int>(type: "int", nullable: true),
PreRollFillerId = table.Column<int>(type: "int", nullable: true),
MidRollFillerId = table.Column<int>(type: "int", nullable: true),
PostRollFillerId = table.Column<int>(type: "int", nullable: true),
StreamSelectorMode = table.Column<int>(type: "int", nullable: false),
StreamSelector = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
PreferredAudioLanguageCode = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
PreferredAudioTitle = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
PlayoutSource = table.Column<int>(type: "int", nullable: false),
PlayoutMode = table.Column<int>(type: "int", nullable: false),
StreamingMode = table.Column<int>(type: "int", nullable: false),
PreferredSubtitleLanguageCode = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
SubtitleMode = table.Column<int>(type: "int", nullable: false),
MusicVideoCreditsMode = table.Column<int>(type: "int", nullable: false),
MusicVideoCreditsTemplate = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
SongVideoMode = table.Column<int>(type: "int", nullable: false),
TranscodeMode = table.Column<int>(type: "int", nullable: false),
IdleBehavior = table.Column<int>(type: "int", nullable: false),
ShuffleScheduleItems = table.Column<bool>(type: "tinyint(1)", nullable: false),
RandomStartPoint = table.Column<bool>(type: "tinyint(1)", nullable: false),
FixedStartTimeBehavior = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChannelTemplate", x => x.Id);
table.ForeignKey(
name: "FK_ChannelTemplate_ChannelWatermark_WatermarkId",
column: x => x.WatermarkId,
principalTable: "ChannelWatermark",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_ChannelTemplate_FFmpegProfile_FFmpegProfileId",
column: x => x.FFmpegProfileId,
principalTable: "FFmpegProfile",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_ChannelTemplate_FillerPreset_FallbackFillerId",
column: x => x.FallbackFillerId,
principalTable: "FillerPreset",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_ChannelTemplate_FillerPreset_MidRollFillerId",
column: x => x.MidRollFillerId,
principalTable: "FillerPreset",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_ChannelTemplate_FillerPreset_PostRollFillerId",
column: x => x.PostRollFillerId,
principalTable: "FillerPreset",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_ChannelTemplate_FillerPreset_PreRollFillerId",
column: x => x.PreRollFillerId,
principalTable: "FillerPreset",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_FallbackFillerId",
table: "ChannelTemplate",
column: "FallbackFillerId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_FFmpegProfileId",
table: "ChannelTemplate",
column: "FFmpegProfileId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_MidRollFillerId",
table: "ChannelTemplate",
column: "MidRollFillerId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_Name",
table: "ChannelTemplate",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_PostRollFillerId",
table: "ChannelTemplate",
column: "PostRollFillerId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_PreRollFillerId",
table: "ChannelTemplate",
column: "PreRollFillerId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_WatermarkId",
table: "ChannelTemplate",
column: "WatermarkId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ChannelTemplate");
}
}
}
@@ -403,6 +403,119 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations
b.ToTable("Channel", (string)null);
});
modelBuilder.Entity("ErsatzTV.Core.Domain.ChannelTemplate", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(500)
.HasColumnType("varchar(500)")
.HasDefaultValue("");
b.Property<int>("FFmpegProfileId")
.HasColumnType("int");
b.Property<int?>("FallbackFillerId")
.HasColumnType("int");
b.Property<int>("FixedStartTimeBehavior")
.HasColumnType("int");
b.Property<int>("IdleBehavior")
.HasColumnType("int");
b.Property<bool>("IsSystem")
.HasColumnType("tinyint(1)");
b.Property<int?>("MidRollFillerId")
.HasColumnType("int");
b.Property<int>("MusicVideoCreditsMode")
.HasColumnType("int");
b.Property<string>("MusicVideoCreditsTemplate")
.HasColumnType("longtext");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.UseCollation("utf8mb4_general_ci");
b.Property<int>("PlayoutMode")
.HasColumnType("int");
b.Property<int>("PlayoutSource")
.HasColumnType("int");
b.Property<int?>("PostRollFillerId")
.HasColumnType("int");
b.Property<int?>("PreRollFillerId")
.HasColumnType("int");
b.Property<string>("PreferredAudioLanguageCode")
.HasColumnType("longtext");
b.Property<string>("PreferredAudioTitle")
.HasColumnType("longtext");
b.Property<string>("PreferredSubtitleLanguageCode")
.HasColumnType("longtext");
b.Property<bool>("RandomStartPoint")
.HasColumnType("tinyint(1)");
b.Property<bool>("ShuffleScheduleItems")
.HasColumnType("tinyint(1)");
b.Property<int>("SongVideoMode")
.HasColumnType("int");
b.Property<string>("StreamSelector")
.HasColumnType("longtext");
b.Property<int>("StreamSelectorMode")
.HasColumnType("int");
b.Property<int>("StreamingMode")
.HasColumnType("int");
b.Property<int>("SubtitleMode")
.HasColumnType("int");
b.Property<int>("TranscodeMode")
.HasColumnType("int");
b.Property<int?>("WatermarkId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("FFmpegProfileId");
b.HasIndex("FallbackFillerId");
b.HasIndex("MidRollFillerId");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("PostRollFillerId");
b.HasIndex("PreRollFillerId");
b.HasIndex("WatermarkId");
b.ToTable("ChannelTemplate", (string)null);
});
modelBuilder.Entity("ErsatzTV.Core.Domain.ChannelWatermark", b =>
{
b.Property<int>("Id")
@@ -4559,6 +4672,52 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations
b.Navigation("Watermark");
});
modelBuilder.Entity("ErsatzTV.Core.Domain.ChannelTemplate", b =>
{
b.HasOne("ErsatzTV.Core.Domain.FFmpegProfile", "FFmpegProfile")
.WithMany()
.HasForeignKey("FFmpegProfileId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("ErsatzTV.Core.Domain.Filler.FillerPreset", "FallbackFiller")
.WithMany()
.HasForeignKey("FallbackFillerId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("ErsatzTV.Core.Domain.Filler.FillerPreset", "MidRollFiller")
.WithMany()
.HasForeignKey("MidRollFillerId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("ErsatzTV.Core.Domain.Filler.FillerPreset", "PostRollFiller")
.WithMany()
.HasForeignKey("PostRollFillerId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("ErsatzTV.Core.Domain.Filler.FillerPreset", "PreRollFiller")
.WithMany()
.HasForeignKey("PreRollFillerId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("ErsatzTV.Core.Domain.ChannelWatermark", "Watermark")
.WithMany()
.HasForeignKey("WatermarkId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("FFmpegProfile");
b.Navigation("FallbackFiller");
b.Navigation("MidRollFiller");
b.Navigation("PostRollFiller");
b.Navigation("PreRollFiller");
b.Navigation("Watermark");
});
modelBuilder.Entity("ErsatzTV.Core.Domain.CollectionItem", b =>
{
b.HasOne("ErsatzTV.Core.Domain.Collection", "Collection")
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,131 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ErsatzTV.Infrastructure.Sqlite.Migrations
{
/// <inheritdoc />
public partial class AddChannelTemplates : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ChannelTemplate",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, collation: "NOCASE"),
Description = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false, defaultValue: ""),
IsSystem = table.Column<bool>(type: "INTEGER", nullable: false),
FFmpegProfileId = table.Column<int>(type: "INTEGER", nullable: false),
WatermarkId = table.Column<int>(type: "INTEGER", nullable: true),
FallbackFillerId = table.Column<int>(type: "INTEGER", nullable: true),
PreRollFillerId = table.Column<int>(type: "INTEGER", nullable: true),
MidRollFillerId = table.Column<int>(type: "INTEGER", nullable: true),
PostRollFillerId = table.Column<int>(type: "INTEGER", nullable: true),
StreamSelectorMode = table.Column<int>(type: "INTEGER", nullable: false),
StreamSelector = table.Column<string>(type: "TEXT", nullable: true),
PreferredAudioLanguageCode = table.Column<string>(type: "TEXT", nullable: true),
PreferredAudioTitle = table.Column<string>(type: "TEXT", nullable: true),
PlayoutSource = table.Column<int>(type: "INTEGER", nullable: false),
PlayoutMode = table.Column<int>(type: "INTEGER", nullable: false),
StreamingMode = table.Column<int>(type: "INTEGER", nullable: false),
PreferredSubtitleLanguageCode = table.Column<string>(type: "TEXT", nullable: true),
SubtitleMode = table.Column<int>(type: "INTEGER", nullable: false),
MusicVideoCreditsMode = table.Column<int>(type: "INTEGER", nullable: false),
MusicVideoCreditsTemplate = table.Column<string>(type: "TEXT", nullable: true),
SongVideoMode = table.Column<int>(type: "INTEGER", nullable: false),
TranscodeMode = table.Column<int>(type: "INTEGER", nullable: false),
IdleBehavior = table.Column<int>(type: "INTEGER", nullable: false),
ShuffleScheduleItems = table.Column<bool>(type: "INTEGER", nullable: false),
RandomStartPoint = table.Column<bool>(type: "INTEGER", nullable: false),
FixedStartTimeBehavior = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChannelTemplate", x => x.Id);
table.ForeignKey(
name: "FK_ChannelTemplate_ChannelWatermark_WatermarkId",
column: x => x.WatermarkId,
principalTable: "ChannelWatermark",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_ChannelTemplate_FFmpegProfile_FFmpegProfileId",
column: x => x.FFmpegProfileId,
principalTable: "FFmpegProfile",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_ChannelTemplate_FillerPreset_FallbackFillerId",
column: x => x.FallbackFillerId,
principalTable: "FillerPreset",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_ChannelTemplate_FillerPreset_MidRollFillerId",
column: x => x.MidRollFillerId,
principalTable: "FillerPreset",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_ChannelTemplate_FillerPreset_PostRollFillerId",
column: x => x.PostRollFillerId,
principalTable: "FillerPreset",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_ChannelTemplate_FillerPreset_PreRollFillerId",
column: x => x.PreRollFillerId,
principalTable: "FillerPreset",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_FallbackFillerId",
table: "ChannelTemplate",
column: "FallbackFillerId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_FFmpegProfileId",
table: "ChannelTemplate",
column: "FFmpegProfileId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_MidRollFillerId",
table: "ChannelTemplate",
column: "MidRollFillerId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_Name",
table: "ChannelTemplate",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_PostRollFillerId",
table: "ChannelTemplate",
column: "PostRollFillerId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_PreRollFillerId",
table: "ChannelTemplate",
column: "PreRollFillerId");
migrationBuilder.CreateIndex(
name: "IX_ChannelTemplate_WatermarkId",
table: "ChannelTemplate",
column: "WatermarkId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ChannelTemplate");
}
}
}
@@ -390,6 +390,117 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations
b.ToTable("Channel", (string)null);
});
modelBuilder.Entity("ErsatzTV.Core.Domain.ChannelTemplate", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(500)
.HasColumnType("varchar(500)")
.HasDefaultValue("");
b.Property<int>("FFmpegProfileId")
.HasColumnType("INTEGER");
b.Property<int?>("FallbackFillerId")
.HasColumnType("INTEGER");
b.Property<int>("FixedStartTimeBehavior")
.HasColumnType("INTEGER");
b.Property<int>("IdleBehavior")
.HasColumnType("INTEGER");
b.Property<bool>("IsSystem")
.HasColumnType("INTEGER");
b.Property<int?>("MidRollFillerId")
.HasColumnType("INTEGER");
b.Property<int>("MusicVideoCreditsMode")
.HasColumnType("INTEGER");
b.Property<string>("MusicVideoCreditsTemplate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.UseCollation("NOCASE");
b.Property<int>("PlayoutMode")
.HasColumnType("INTEGER");
b.Property<int>("PlayoutSource")
.HasColumnType("INTEGER");
b.Property<int?>("PostRollFillerId")
.HasColumnType("INTEGER");
b.Property<int?>("PreRollFillerId")
.HasColumnType("INTEGER");
b.Property<string>("PreferredAudioLanguageCode")
.HasColumnType("TEXT");
b.Property<string>("PreferredAudioTitle")
.HasColumnType("TEXT");
b.Property<string>("PreferredSubtitleLanguageCode")
.HasColumnType("TEXT");
b.Property<bool>("RandomStartPoint")
.HasColumnType("INTEGER");
b.Property<bool>("ShuffleScheduleItems")
.HasColumnType("INTEGER");
b.Property<int>("SongVideoMode")
.HasColumnType("INTEGER");
b.Property<string>("StreamSelector")
.HasColumnType("TEXT");
b.Property<int>("StreamSelectorMode")
.HasColumnType("INTEGER");
b.Property<int>("StreamingMode")
.HasColumnType("INTEGER");
b.Property<int>("SubtitleMode")
.HasColumnType("INTEGER");
b.Property<int>("TranscodeMode")
.HasColumnType("INTEGER");
b.Property<int?>("WatermarkId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("FFmpegProfileId");
b.HasIndex("FallbackFillerId");
b.HasIndex("MidRollFillerId");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("PostRollFillerId");
b.HasIndex("PreRollFillerId");
b.HasIndex("WatermarkId");
b.ToTable("ChannelTemplate", (string)null);
});
modelBuilder.Entity("ErsatzTV.Core.Domain.ChannelWatermark", b =>
{
b.Property<int>("Id")
@@ -4386,6 +4497,52 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations
b.Navigation("Watermark");
});
modelBuilder.Entity("ErsatzTV.Core.Domain.ChannelTemplate", b =>
{
b.HasOne("ErsatzTV.Core.Domain.FFmpegProfile", "FFmpegProfile")
.WithMany()
.HasForeignKey("FFmpegProfileId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("ErsatzTV.Core.Domain.Filler.FillerPreset", "FallbackFiller")
.WithMany()
.HasForeignKey("FallbackFillerId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("ErsatzTV.Core.Domain.Filler.FillerPreset", "MidRollFiller")
.WithMany()
.HasForeignKey("MidRollFillerId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("ErsatzTV.Core.Domain.Filler.FillerPreset", "PostRollFiller")
.WithMany()
.HasForeignKey("PostRollFillerId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("ErsatzTV.Core.Domain.Filler.FillerPreset", "PreRollFiller")
.WithMany()
.HasForeignKey("PreRollFillerId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("ErsatzTV.Core.Domain.ChannelWatermark", "Watermark")
.WithMany()
.HasForeignKey("WatermarkId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("FFmpegProfile");
b.Navigation("FallbackFiller");
b.Navigation("MidRollFiller");
b.Navigation("PostRollFiller");
b.Navigation("PreRollFiller");
b.Navigation("Watermark");
});
modelBuilder.Entity("ErsatzTV.Core.Domain.CollectionItem", b =>
{
b.HasOne("ErsatzTV.Core.Domain.Collection", "Collection")
@@ -0,0 +1,62 @@
using ErsatzTV.Core.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace ErsatzTV.Infrastructure.Data.Configurations;
public class ChannelTemplateConfiguration : IEntityTypeConfiguration<ChannelTemplate>
{
public void Configure(EntityTypeBuilder<ChannelTemplate> builder)
{
builder.ToTable("ChannelTemplate");
builder.HasIndex(t => t.Name)
.IsUnique();
builder.Property(t => t.Name)
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.IsRequired();
builder.Property(t => t.Description)
.HasMaxLength(500)
.HasColumnType("varchar(500)")
.HasDefaultValue(string.Empty)
.IsRequired();
builder.HasOne(t => t.FFmpegProfile)
.WithMany()
.HasForeignKey(t => t.FFmpegProfileId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne(t => t.Watermark)
.WithMany()
.HasForeignKey(t => t.WatermarkId)
.OnDelete(DeleteBehavior.SetNull)
.IsRequired(false);
builder.HasOne(t => t.FallbackFiller)
.WithMany()
.HasForeignKey(t => t.FallbackFillerId)
.OnDelete(DeleteBehavior.SetNull)
.IsRequired(false);
builder.HasOne(t => t.PreRollFiller)
.WithMany()
.HasForeignKey(t => t.PreRollFillerId)
.OnDelete(DeleteBehavior.SetNull)
.IsRequired(false);
builder.HasOne(t => t.MidRollFiller)
.WithMany()
.HasForeignKey(t => t.MidRollFillerId)
.OnDelete(DeleteBehavior.SetNull)
.IsRequired(false);
builder.HasOne(t => t.PostRollFiller)
.WithMany()
.HasForeignKey(t => t.PostRollFillerId)
.OnDelete(DeleteBehavior.SetNull)
.IsRequired(false);
}
}
+171 -43
View File
@@ -2,6 +2,8 @@
using System.Reflection;
using Dapper;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Scheduling;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Infrastructure.Data;
@@ -84,54 +86,180 @@ public static class DbInitializer
await context.SaveChangesAsync(cancellationToken);
}
if (context.Resolutions.Any(x => x.Width == 1920))
if (!context.Resolutions.Any(x => x.Width == 1920))
{
return Unit.Default;
var resolutions = new List<Resolution>
{
new() { Id = 1, Name = "720x480", Width = 720, Height = 480 },
new() { Id = 2, Name = "1280x720", Width = 1280, Height = 720 },
new() { Id = 3, Name = "1920x1080", Width = 1920, Height = 1080 },
new() { Id = 4, Name = "3840x2160", Width = 3840, Height = 2160 }
};
await context.Resolutions.AddRangeAsync(resolutions, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var resolutionConfig = new ConfigElement
{
Key = ConfigElementKey.FFmpegDefaultResolutionId.Key,
Value = "3" // 1920x1080
};
await context.ConfigElements.AddAsync(resolutionConfig, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var defaultProfile = FFmpegProfile.New("1920x1080 x264 aac", resolutions[2]);
await context.FFmpegProfiles.AddAsync(defaultProfile, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var profileConfig = new ConfigElement
{
Key = ConfigElementKey.FFmpegDefaultProfileId.Key,
Value = defaultProfile.Id.ToString(CultureInfo.InvariantCulture)
};
await context.ConfigElements.AddAsync(profileConfig, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var defaultChannel = new Channel(Guid.NewGuid())
{
Number = "1",
Name = "ErsatzTV",
FFmpegProfile = defaultProfile,
StreamingMode = StreamingMode.TransportStreamHybrid,
IsEnabled = true,
ShowInEpg = true
};
await context.Channels.AddAsync(defaultChannel, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
}
var resolutions = new List<Resolution>
{
new() { Id = 1, Name = "720x480", Width = 720, Height = 480 },
new() { Id = 2, Name = "1280x720", Width = 1280, Height = 720 },
new() { Id = 3, Name = "1920x1080", Width = 1920, Height = 1080 },
new() { Id = 4, Name = "3840x2160", Width = 3840, Height = 2160 }
};
await context.Resolutions.AddRangeAsync(resolutions, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var resolutionConfig = new ConfigElement
{
Key = ConfigElementKey.FFmpegDefaultResolutionId.Key,
Value = "3" // 1920x1080
};
await context.ConfigElements.AddAsync(resolutionConfig, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var defaultProfile = FFmpegProfile.New("1920x1080 x264 aac", resolutions[2]);
await context.FFmpegProfiles.AddAsync(defaultProfile, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var profileConfig = new ConfigElement
{
Key = ConfigElementKey.FFmpegDefaultProfileId.Key,
Value = defaultProfile.Id.ToString(CultureInfo.InvariantCulture)
};
await context.ConfigElements.AddAsync(profileConfig, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var defaultChannel = new Channel(Guid.NewGuid())
{
Number = "1",
Name = "ErsatzTV",
FFmpegProfile = defaultProfile,
StreamingMode = StreamingMode.TransportStreamHybrid,
IsEnabled = true,
ShowInEpg = true
};
await context.Channels.AddAsync(defaultChannel, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
await SeedChannelTemplates(context, cancellationToken);
// TODO: create looping static image that mentions configuring via web
return Unit.Default;
}
private static async Task SeedChannelTemplates(TvContext context, CancellationToken cancellationToken)
{
if (await context.ChannelTemplates.AnyAsync(t => t.Name == "Standard", cancellationToken) &&
await context.ChannelTemplates.AnyAsync(t => t.Name == "Music videos", cancellationToken))
{
await EnsureDefaultChannelTemplateConfig(context, cancellationToken);
return;
}
FFmpegProfile defaultProfile = await GetDefaultFFmpegProfile(context, cancellationToken);
if (defaultProfile is null)
{
return;
}
if (!await context.ChannelTemplates.AnyAsync(t => t.Name == "Standard", cancellationToken))
{
await context.ChannelTemplates.AddAsync(
NewSystemTemplate(
"Standard",
"Balanced defaults for generated channels.",
defaultProfile.Id,
ChannelMusicVideoCreditsMode.None,
ChannelSongVideoMode.Default,
shuffleScheduleItems: false,
randomStartPoint: false),
cancellationToken);
await context.SaveChangesAsync(cancellationToken);
}
if (!await context.ChannelTemplates.AnyAsync(t => t.Name == "Music videos", cancellationToken))
{
await context.ChannelTemplates.AddAsync(
NewSystemTemplate(
"Music videos",
"Defaults for shuffled music-video channels with generated credit subtitles.",
defaultProfile.Id,
ChannelMusicVideoCreditsMode.GenerateSubtitles,
ChannelSongVideoMode.WithProgress,
shuffleScheduleItems: true,
randomStartPoint: true),
cancellationToken);
await context.SaveChangesAsync(cancellationToken);
}
await EnsureDefaultChannelTemplateConfig(context, cancellationToken);
}
private static async Task<FFmpegProfile> GetDefaultFFmpegProfile(
TvContext context,
CancellationToken cancellationToken)
{
string defaultProfileConfigKey = ConfigElementKey.FFmpegDefaultProfileId.Key;
ConfigElement profileConfig = await context.ConfigElements
.AsNoTracking()
.FirstOrDefaultAsync(c => c.Key == defaultProfileConfigKey, cancellationToken);
if (profileConfig is not null &&
int.TryParse(profileConfig.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int profileId))
{
FFmpegProfile configuredProfile = await context.FFmpegProfiles
.FirstOrDefaultAsync(p => p.Id == profileId, cancellationToken);
if (configuredProfile is not null)
{
return configuredProfile;
}
}
return await context.FFmpegProfiles.OrderBy(p => p.Id).FirstOrDefaultAsync(cancellationToken);
}
private static async Task EnsureDefaultChannelTemplateConfig(TvContext context, CancellationToken cancellationToken)
{
string defaultTemplateConfigKey = ConfigElementKey.ChannelTemplatesDefaultTemplateId.Key;
bool configExists = await context.ConfigElements
.AnyAsync(c => c.Key == defaultTemplateConfigKey, cancellationToken);
if (configExists)
{
return;
}
ChannelTemplate standard = await context.ChannelTemplates
.AsNoTracking()
.FirstAsync(t => t.Name == "Standard", cancellationToken);
await context.ConfigElements.AddAsync(
new ConfigElement
{
Key = defaultTemplateConfigKey,
Value = standard.Id.ToString(CultureInfo.InvariantCulture)
},
cancellationToken);
await context.SaveChangesAsync(cancellationToken);
}
private static ChannelTemplate NewSystemTemplate(
string name,
string description,
int ffmpegProfileId,
ChannelMusicVideoCreditsMode musicVideoCreditsMode,
ChannelSongVideoMode songVideoMode,
bool shuffleScheduleItems,
bool randomStartPoint) =>
new()
{
Name = name,
Description = description,
IsSystem = true,
FFmpegProfileId = ffmpegProfileId,
StreamSelectorMode = ChannelStreamSelectorMode.Default,
StreamSelector = string.Empty,
PreferredAudioLanguageCode = string.Empty,
PreferredAudioTitle = string.Empty,
PlayoutSource = ChannelPlayoutSource.Generated,
PlayoutMode = ChannelPlayoutMode.Continuous,
StreamingMode = StreamingMode.TransportStreamHybrid,
PreferredSubtitleLanguageCode = string.Empty,
SubtitleMode = ChannelSubtitleMode.None,
MusicVideoCreditsMode = musicVideoCreditsMode,
MusicVideoCreditsTemplate = string.Empty,
SongVideoMode = songVideoMode,
TranscodeMode = ChannelTranscodeMode.OnDemand,
IdleBehavior = ChannelIdleBehavior.StopOnDisconnect,
ShuffleScheduleItems = shuffleScheduleItems,
RandomStartPoint = randomStartPoint,
FixedStartTimeBehavior = FixedStartTimeBehavior.Flexible
};
}
@@ -30,6 +30,7 @@ public class TvContext : DbContext
public DbSet<ConfigElement> ConfigElements { get; set; }
public DbSet<Channel> Channels { get; set; }
public DbSet<ChannelTemplate> ChannelTemplates { get; set; }
public DbSet<ChannelWatermark> ChannelWatermarks { get; set; }
public DbSet<MediaSource> MediaSources { get; set; }
public DbSet<LocalMediaSource> LocalMediaSources { get; set; }
@@ -160,6 +161,7 @@ public class TvContext : DbContext
modelBuilder.Entity<Block>().Property(b => b.Name).UseCollation(collation);
modelBuilder.Entity<BlockGroup>().Property(b => b.Name).UseCollation(collation);
modelBuilder.Entity<Channel>().Property(c => c.Name).UseCollation(collation);
modelBuilder.Entity<ChannelTemplate>().Property(c => c.Name).UseCollation(collation);
modelBuilder.Entity<ChannelWatermark>().Property(c => c.Name).UseCollation(collation);
modelBuilder.Entity<Collection>().Property(c => c.Name).UseCollation(collation);
modelBuilder.Entity<Deco>().Property(d => d.Name).UseCollation(collation);
@@ -0,0 +1,288 @@
using ErsatzTV.Application.ChannelTemplates;
using ErsatzTV.Core;
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Domain.Filler;
using ErsatzTV.Core.Errors;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Core.Scheduling;
using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Data.Repositories;
using ErsatzTV.Tests.Support;
using LanguageExt;
using NUnit.Framework;
using Shouldly;
using Unit = LanguageExt.Unit;
namespace ErsatzTV.Tests.Application.ChannelTemplates;
[TestFixture]
public class ChannelTemplateHandlerTests
{
private InMemoryTvContext _db = null!;
private IConfigElementRepository _config = null!;
[SetUp]
public async Task SetUp()
{
_db = await InMemoryTvContext.CreateAsync();
_config = new ConfigElementRepository(_db.Factory);
}
[TearDown]
public async Task TearDown() => await _db.DisposeAsync();
[Test]
public async Task Create_Should_Persist_Template_With_Reference_Ids()
{
await SeedProfile(1);
await SeedFiller(2, FillerKind.PreRoll);
await SeedFiller(3, FillerKind.MidRoll);
await SeedFiller(4, FillerKind.PostRoll);
var handler = new CreateChannelTemplateHandler(_db.Factory, _config);
Either<BaseError, ChannelTemplateResponseModel> result =
await handler.Handle(MakeCreate("Custom"), CancellationToken.None);
ChannelTemplateResponseModel vm = RightOf(result);
vm.Id.ShouldBeGreaterThan(0);
vm.Name.ShouldBe("Custom");
vm.IsSystem.ShouldBeFalse();
vm.PreRollFillerId.ShouldBe(2);
vm.MidRollFillerId.ShouldBe(3);
vm.PostRollFillerId.ShouldBe(4);
await using TvContext context = _db.CreateContext();
context.ChannelTemplates.Single().Name.ShouldBe("Custom");
}
[Test]
public async Task Create_Should_Return_NotFoundError_When_Profile_Missing()
{
var handler = new CreateChannelTemplateHandler(_db.Factory, _config);
Either<BaseError, ChannelTemplateResponseModel> result =
await handler.Handle(MakeCreate("Missing", ffmpegProfileId: 99), CancellationToken.None);
LeftOf(result).ShouldBeOfType<NotFoundError>();
}
[Test]
public async Task Create_Should_Return_Error_When_Trimmed_Name_Already_Exists()
{
await SeedProfile(1);
await SeedTemplate(7, "Standard");
var handler = new CreateChannelTemplateHandler(_db.Factory, _config);
Either<BaseError, ChannelTemplateResponseModel> result =
await handler.Handle(MakeCreate("Standard "), CancellationToken.None);
LeftOf(result).Value.ShouldBe("Channel template name must be unique.");
}
[Test]
public async Task Create_Should_Validate_Filler_Kind()
{
await SeedProfile(1);
await SeedFiller(2, FillerKind.PostRoll);
var handler = new CreateChannelTemplateHandler(_db.Factory, _config);
Either<BaseError, ChannelTemplateResponseModel> result =
await handler.Handle(MakeCreate("Bad", preRollFillerId: 2), CancellationToken.None);
LeftOf(result).ShouldBeOfType<NotFoundError>();
}
[Test]
public async Task Update_Should_Reject_System_Template()
{
await SeedProfile(1);
await SeedTemplate(7, "Standard", isSystem: true);
var handler = new UpdateChannelTemplateHandler(_db.Factory, _config);
Either<BaseError, ChannelTemplateResponseModel> result =
await handler.Handle(MakeUpdate(7, "Changed"), CancellationToken.None);
LeftOf(result).Value.ShouldBe("System templates cannot be updated.");
}
[Test]
public async Task Delete_Should_Reject_Default_Template()
{
await SeedProfile(1);
await SeedTemplate(7, "Default");
await _config.Upsert(ConfigElementKey.ChannelTemplatesDefaultTemplateId, 7, CancellationToken.None);
var handler = new DeleteChannelTemplateHandler(_db.Factory, _config);
Either<BaseError, Unit> result = await handler.Handle(new DeleteChannelTemplate(7), CancellationToken.None);
LeftOf(result).Value.ShouldBe("Default channel template cannot be deleted.");
}
[Test]
public async Task SetDefault_Should_Update_Config_And_Return_Template()
{
await SeedProfile(1);
await SeedTemplate(7, "Default");
var handler = new SetDefaultChannelTemplateHandler(_db.Factory, _config);
Either<BaseError, ChannelTemplateResponseModel> result =
await handler.Handle(new SetDefaultChannelTemplate(7), CancellationToken.None);
ChannelTemplateResponseModel vm = RightOf(result);
vm.IsDefault.ShouldBeTrue();
Option<int> defaultId =
await _config.GetValue<int>(ConfigElementKey.ChannelTemplatesDefaultTemplateId, CancellationToken.None);
defaultId.IfNone(0).ShouldBe(7);
}
[Test]
public async Task GetAll_Should_Flag_Configured_Default()
{
await SeedProfile(1);
await SeedTemplate(7, "Standard");
await SeedTemplate(8, "Music videos");
await _config.Upsert(ConfigElementKey.ChannelTemplatesDefaultTemplateId, 8, CancellationToken.None);
var handler = new GetAllChannelTemplatesHandler(_db.Factory, _config);
List<ChannelTemplateResponseModel> result =
await handler.Handle(new GetAllChannelTemplates(), CancellationToken.None);
result.Single(t => t.Id == 7).IsDefault.ShouldBeFalse();
result.Single(t => t.Id == 8).IsDefault.ShouldBeTrue();
}
[Test]
public async Task GetDefault_Should_Fall_Back_To_First_System_Template_By_Name()
{
await SeedProfile(1);
await SeedTemplate(1, "Zulu", isSystem: true);
await SeedTemplate(99, "Alpha", isSystem: true);
var handler = new GetDefaultChannelTemplateHandler(_db.Factory, _config);
Option<ChannelTemplateResponseModel> result =
await handler.Handle(new GetDefaultChannelTemplate(), CancellationToken.None);
ChannelTemplateResponseModel vm = result.IfNone(() => throw new AssertionException("Expected a template"));
vm.Id.ShouldBe(99);
vm.Name.ShouldBe("Alpha");
vm.IsDefault.ShouldBeTrue();
}
private async Task SeedProfile(int id)
{
await using TvContext context = _db.CreateContext();
context.FFmpegProfiles.Add(new FFmpegProfile { Id = id, Name = $"profile-{id}" });
await context.SaveChangesAsync();
}
private async Task SeedFiller(int id, FillerKind fillerKind)
{
await using TvContext context = _db.CreateContext();
context.FillerPresets.Add(new FillerPreset
{
Id = id,
Name = $"filler-{id}",
FillerKind = fillerKind,
FillerMode = FillerMode.Count,
Count = 1,
CollectionType = CollectionType.Collection
});
await context.SaveChangesAsync();
}
private async Task SeedTemplate(int id, string name, bool isSystem = false)
{
await using TvContext context = _db.CreateContext();
context.ChannelTemplates.Add(new ChannelTemplate
{
Id = id,
Name = name,
Description = string.Empty,
IsSystem = isSystem,
FFmpegProfileId = 1,
StreamSelectorMode = ChannelStreamSelectorMode.Default,
StreamSelector = string.Empty,
PreferredAudioLanguageCode = string.Empty,
PreferredAudioTitle = string.Empty,
PlayoutSource = ChannelPlayoutSource.Generated,
PlayoutMode = ChannelPlayoutMode.Continuous,
StreamingMode = StreamingMode.TransportStreamHybrid,
PreferredSubtitleLanguageCode = string.Empty,
SubtitleMode = ChannelSubtitleMode.None,
MusicVideoCreditsMode = ChannelMusicVideoCreditsMode.None,
MusicVideoCreditsTemplate = string.Empty,
SongVideoMode = ChannelSongVideoMode.Default,
TranscodeMode = ChannelTranscodeMode.OnDemand,
IdleBehavior = ChannelIdleBehavior.StopOnDisconnect,
FixedStartTimeBehavior = FixedStartTimeBehavior.Flexible
});
await context.SaveChangesAsync();
}
private static CreateChannelTemplate MakeCreate(
string name,
int ffmpegProfileId = 1,
int? preRollFillerId = 2) =>
new(
name,
"Description",
ffmpegProfileId,
null,
null,
preRollFillerId,
3,
4,
ChannelStreamSelectorMode.Default,
string.Empty,
string.Empty,
string.Empty,
ChannelPlayoutSource.Generated,
ChannelPlayoutMode.Continuous,
StreamingMode.TransportStreamHybrid,
string.Empty,
ChannelSubtitleMode.None,
ChannelMusicVideoCreditsMode.None,
string.Empty,
ChannelSongVideoMode.Default,
ChannelTranscodeMode.OnDemand,
ChannelIdleBehavior.StopOnDisconnect,
true,
false,
FixedStartTimeBehavior.Flexible);
private static UpdateChannelTemplate MakeUpdate(int id, string name) =>
new(
id,
name,
"Description",
1,
null,
null,
null,
null,
null,
ChannelStreamSelectorMode.Default,
string.Empty,
string.Empty,
string.Empty,
ChannelPlayoutSource.Generated,
ChannelPlayoutMode.Continuous,
StreamingMode.TransportStreamHybrid,
string.Empty,
ChannelSubtitleMode.None,
ChannelMusicVideoCreditsMode.None,
string.Empty,
ChannelSongVideoMode.Default,
ChannelTranscodeMode.OnDemand,
ChannelIdleBehavior.StopOnDisconnect,
false,
false,
FixedStartTimeBehavior.Flexible);
private static BaseError LeftOf<TR>(Either<BaseError, TR> either) =>
either.Match(Left: e => e, Right: _ => throw new AssertionException("Expected a Left result"));
private static TR RightOf<TR>(Either<BaseError, TR> either) =>
either.Match(Left: e => throw new AssertionException($"Expected a Right result but got {e.Value}"), Right: r => r);
}
@@ -24,6 +24,16 @@ public class ApiErrorResponseMetadataTests
[TestCase(typeof(ChannelController), nameof(ChannelController.BulkDelete), StatusCodes.Status404NotFound)]
[TestCase(typeof(ChannelController), nameof(ChannelController.BulkDelete), StatusCodes.Status422UnprocessableEntity)]
[TestCase(typeof(ChannelController), nameof(ChannelController.ResetPlayout), StatusCodes.Status404NotFound)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.GetDefault), StatusCodes.Status404NotFound)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.SetDefault), StatusCodes.Status404NotFound)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.SetDefault), StatusCodes.Status422UnprocessableEntity)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.GetById), StatusCodes.Status404NotFound)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.Create), StatusCodes.Status404NotFound)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.Create), StatusCodes.Status422UnprocessableEntity)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.Update), StatusCodes.Status404NotFound)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.Update), StatusCodes.Status422UnprocessableEntity)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.Delete), StatusCodes.Status404NotFound)]
[TestCase(typeof(ChannelTemplateController), nameof(ChannelTemplateController.Delete), StatusCodes.Status422UnprocessableEntity)]
[TestCase(typeof(CollectionController), nameof(CollectionController.GetById), StatusCodes.Status404NotFound)]
[TestCase(typeof(CollectionController), nameof(CollectionController.Create), StatusCodes.Status404NotFound)]
[TestCase(typeof(CollectionController), nameof(CollectionController.Create), StatusCodes.Status422UnprocessableEntity)]
@@ -0,0 +1,276 @@
using System.Reflection;
using ErsatzTV.Application.ChannelTemplates;
using ErsatzTV.Controllers.Api;
using ErsatzTV.Controllers.Api.Requests;
using ErsatzTV.Core;
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Errors;
using ErsatzTV.Core.Scheduling;
using LanguageExt;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;
using NSubstitute;
using NUnit.Framework;
using Shouldly;
using static LanguageExt.Prelude;
using Unit = LanguageExt.Unit;
namespace ErsatzTV.Tests.Controllers;
[TestFixture]
public class ChannelTemplateControllerTests
{
private ChannelTemplateController _controller = null!;
private IMediator _mediator = null!;
[SetUp]
public void SetUp()
{
_mediator = Substitute.For<IMediator>();
_controller = new ChannelTemplateController(_mediator);
}
[Test]
public void Controller_Should_Expose_Named_Rest_Routes()
{
ShouldHaveActionRoute(
nameof(ChannelTemplateController.GetAll),
"GET",
"/api/channel-templates",
"GetChannelTemplates");
ShouldHaveActionRoute(
nameof(ChannelTemplateController.GetDefault),
"GET",
"/api/channel-templates/default",
"GetDefaultChannelTemplate");
ShouldHaveActionRoute(
nameof(ChannelTemplateController.SetDefault),
"PUT",
"/api/channel-templates/default/{id:int}",
"SetDefaultChannelTemplate");
ShouldHaveActionRoute(
nameof(ChannelTemplateController.GetById),
"GET",
"/api/channel-templates/{id:int}",
"GetChannelTemplateById");
ShouldHaveActionRoute(
nameof(ChannelTemplateController.Create),
"POST",
"/api/channel-templates",
"CreateChannelTemplate");
ShouldHaveActionRoute(
nameof(ChannelTemplateController.Update),
"PUT",
"/api/channel-templates/{id:int}",
"UpdateChannelTemplate");
ShouldHaveActionRoute(
nameof(ChannelTemplateController.Delete),
"DELETE",
"/api/channel-templates/{id:int}",
"DeleteChannelTemplate");
}
[Test]
public async Task GetAll_Should_Return_ChannelTemplates()
{
List<ChannelTemplateResponseModel> models = [MakeResponse(1, "Standard", isDefault: true)];
_mediator.Send(Arg.Any<GetAllChannelTemplates>(), Arg.Any<CancellationToken>())
.Returns(models);
List<ChannelTemplateResponseModel> result = await _controller.GetAll(CancellationToken.None);
result.ShouldBe(models);
}
[Test]
public async Task GetDefault_Should_Return_404_When_Default_Missing()
{
_mediator.Send(Arg.Any<GetDefaultChannelTemplate>(), Arg.Any<CancellationToken>())
.Returns(Option<ChannelTemplateResponseModel>.None);
IActionResult result = await _controller.GetDefault(CancellationToken.None);
result.ShouldBeOfType<NotFoundObjectResult>();
}
[Test]
public async Task Create_Should_Return_201_With_Location_And_Body()
{
ChannelTemplateResponseModel vm = MakeResponse(7, "Custom");
_mediator.Send(Arg.Any<CreateChannelTemplate>(), Arg.Any<CancellationToken>())
.Returns(Right<BaseError, ChannelTemplateResponseModel>(vm));
IActionResult result = await _controller.Create(MakeCreateRequest("Custom"), CancellationToken.None);
var created = result.ShouldBeOfType<CreatedResult>();
created.Location.ShouldBe("/api/channel-templates/7");
created.Value.ShouldBe(vm);
}
[Test]
public async Task Create_Should_Map_Request_To_Command()
{
_mediator.Send(Arg.Any<CreateChannelTemplate>(), Arg.Any<CancellationToken>())
.Returns(Right<BaseError, ChannelTemplateResponseModel>(MakeResponse(7, "Custom")));
await _controller.Create(MakeCreateRequest("Custom"), CancellationToken.None);
await _mediator.Received(1).Send(
Arg.Is<CreateChannelTemplate>(c =>
c.Name == "Custom" &&
c.FFmpegProfileId == 1 &&
c.PreRollFillerId == 2 &&
c.MidRollFillerId == 3 &&
c.PostRollFillerId == 4 &&
c.ShuffleScheduleItems),
Arg.Any<CancellationToken>());
}
[Test]
public async Task Update_Should_Return_404_For_NotFoundError()
{
_mediator.Send(Arg.Any<UpdateChannelTemplate>(), Arg.Any<CancellationToken>())
.Returns(Left<BaseError, ChannelTemplateResponseModel>(new NotFoundError("missing")));
IActionResult result = await _controller.Update(99, MakeUpdateRequest("Missing"), CancellationToken.None);
result.ShouldBeOfType<NotFoundObjectResult>();
}
[Test]
public async Task SetDefault_Should_Return_200_With_Default_Template()
{
ChannelTemplateResponseModel vm = MakeResponse(8, "Default", isDefault: true);
_mediator.Send(Arg.Any<SetDefaultChannelTemplate>(), Arg.Any<CancellationToken>())
.Returns(Right<BaseError, ChannelTemplateResponseModel>(vm));
IActionResult result = await _controller.SetDefault(8, CancellationToken.None);
result.ShouldBeOfType<OkObjectResult>().Value.ShouldBe(vm);
await _mediator.Received(1).Send(
Arg.Is<SetDefaultChannelTemplate>(c => c.ChannelTemplateId == 8),
Arg.Any<CancellationToken>());
}
[Test]
public async Task Delete_Should_Return_204_On_Success()
{
_mediator.Send(Arg.Any<DeleteChannelTemplate>(), Arg.Any<CancellationToken>())
.Returns(Right<BaseError, Unit>(Unit.Default));
IActionResult result = await _controller.Delete(9, CancellationToken.None);
result.ShouldBeOfType<NoContentResult>();
}
[Test]
public async Task Delete_Should_Return_422_When_System_Template()
{
_mediator.Send(Arg.Any<DeleteChannelTemplate>(), Arg.Any<CancellationToken>())
.Returns(Left<BaseError, Unit>(BaseError.New("System templates cannot be deleted.")));
IActionResult result = await _controller.Delete(9, CancellationToken.None);
result.ShouldBeOfType<UnprocessableEntityObjectResult>();
}
private static void ShouldHaveActionRoute(string actionName, string httpMethod, string route, string name)
{
MethodInfo action = typeof(ChannelTemplateController).GetMethod(actionName)
?? throw new AssertionException($"Missing action {actionName}");
HttpMethodAttribute attribute = action.GetCustomAttributes<HttpMethodAttribute>(inherit: true).Single();
attribute.HttpMethods.ShouldContain(httpMethod);
attribute.Template.ShouldBe(route);
attribute.Name.ShouldBe(name);
}
private static CreateChannelTemplateRequest MakeCreateRequest(string name) =>
new(
name,
"Description",
1,
null,
null,
2,
3,
4,
ChannelStreamSelectorMode.Default,
string.Empty,
string.Empty,
string.Empty,
ChannelPlayoutSource.Generated,
ChannelPlayoutMode.Continuous,
StreamingMode.TransportStreamHybrid,
string.Empty,
ChannelSubtitleMode.None,
ChannelMusicVideoCreditsMode.None,
string.Empty,
ChannelSongVideoMode.Default,
ChannelTranscodeMode.OnDemand,
ChannelIdleBehavior.StopOnDisconnect,
true,
false,
FixedStartTimeBehavior.Flexible);
private static UpdateChannelTemplateRequest MakeUpdateRequest(string name) =>
new(
name,
"Description",
1,
null,
null,
null,
null,
null,
ChannelStreamSelectorMode.Default,
string.Empty,
string.Empty,
string.Empty,
ChannelPlayoutSource.Generated,
ChannelPlayoutMode.Continuous,
StreamingMode.TransportStreamHybrid,
string.Empty,
ChannelSubtitleMode.None,
ChannelMusicVideoCreditsMode.None,
string.Empty,
ChannelSongVideoMode.Default,
ChannelTranscodeMode.OnDemand,
ChannelIdleBehavior.StopOnDisconnect,
false,
false,
FixedStartTimeBehavior.Flexible);
private static ChannelTemplateResponseModel MakeResponse(int id, string name, bool isDefault = false) =>
new(
id,
name,
"Description",
false,
isDefault,
1,
null,
null,
null,
null,
null,
ChannelStreamSelectorMode.Default,
string.Empty,
string.Empty,
string.Empty,
ChannelPlayoutSource.Generated,
ChannelPlayoutMode.Continuous,
StreamingMode.TransportStreamHybrid,
string.Empty,
ChannelSubtitleMode.None,
ChannelMusicVideoCreditsMode.None,
string.Empty,
ChannelSongVideoMode.Default,
ChannelTranscodeMode.OnDemand,
ChannelIdleBehavior.StopOnDisconnect,
false,
false,
FixedStartTimeBehavior.Flexible);
}
@@ -113,6 +113,16 @@ public class OpenApiErrorResponseContractTests
[TestCase("/api/channels/bulk/delete", "post", "404")]
[TestCase("/api/channels/bulk/delete", "post", "422")]
[TestCase("/api/channels/{channelNumber}/playout/reset", "post", "404")]
[TestCase("/api/channel-templates/default", "get", "404")]
[TestCase("/api/channel-templates/default/{id}", "put", "404")]
[TestCase("/api/channel-templates/default/{id}", "put", "422")]
[TestCase("/api/channel-templates/{id}", "get", "404")]
[TestCase("/api/channel-templates", "post", "404")]
[TestCase("/api/channel-templates", "post", "422")]
[TestCase("/api/channel-templates/{id}", "put", "404")]
[TestCase("/api/channel-templates/{id}", "put", "422")]
[TestCase("/api/channel-templates/{id}", "delete", "404")]
[TestCase("/api/channel-templates/{id}", "delete", "422")]
[TestCase("/api/collections/{id}", "get", "404")]
[TestCase("/api/collections", "post", "404")]
[TestCase("/api/collections", "post", "422")]
@@ -0,0 +1,51 @@
using ErsatzTV.Core.Domain;
using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Tests.Support;
using NUnit.Framework;
using Shouldly;
namespace ErsatzTV.Tests.Infrastructure;
[TestFixture]
public class DbInitializerChannelTemplateTests
{
private InMemoryTvContext _db = null!;
[SetUp]
public async Task SetUp() => _db = await InMemoryTvContext.CreateAsync();
[TearDown]
public async Task TearDown() => await _db.DisposeAsync();
[Test]
public async Task Initialize_Should_Seed_System_Channel_Templates_And_Default_Config()
{
await using TvContext context = _db.CreateContext();
await DbInitializer.Initialize(context, CancellationToken.None);
List<ChannelTemplate> templates = context.ChannelTemplates.OrderBy(t => t.Name).ToList();
templates.Count.ShouldBe(2);
templates.ShouldContain(t => t.Name == "Music videos" && t.IsSystem);
ChannelTemplate standard = templates.Single(t => t.Name == "Standard");
standard.IsSystem.ShouldBeTrue();
ConfigElement config = context.ConfigElements.Single(
c => c.Key == ConfigElementKey.ChannelTemplatesDefaultTemplateId.Key);
config.Value.ShouldBe(standard.Id.ToString());
}
[Test]
public async Task Initialize_Should_Not_Clobber_Existing_System_Template()
{
await using TvContext context = _db.CreateContext();
await DbInitializer.Initialize(context, CancellationToken.None);
ChannelTemplate standard = context.ChannelTemplates.Single(t => t.Name == "Standard");
standard.Description = "User adjusted description";
await context.SaveChangesAsync();
await DbInitializer.Initialize(context, CancellationToken.None);
context.ChannelTemplates.Single(t => t.Name == "Standard").Description.ShouldBe("User adjusted description");
}
}
@@ -0,0 +1,109 @@
using System.ComponentModel.DataAnnotations;
using ErsatzTV.Application.ChannelTemplates;
using ErsatzTV.Controllers.Api.Requests;
using ErsatzTV.Core;
using ErsatzTV.Core.Api.ChannelTemplates;
using ErsatzTV.Extensions;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ErsatzTV.Controllers.Api;
[ApiController]
public class ChannelTemplateController(IMediator mediator) : ControllerBase
{
[HttpGet("/api/channel-templates", Name = "GetChannelTemplates")]
[Tags("Channel Templates")]
[EndpointSummary("Get all channel templates")]
[EndpointGroupName("general")]
[ProducesResponseType(typeof(List<ChannelTemplateResponseModel>), StatusCodes.Status200OK)]
public async Task<List<ChannelTemplateResponseModel>> GetAll(CancellationToken cancellationToken) =>
await mediator.Send(new GetAllChannelTemplates(), cancellationToken);
[HttpGet("/api/channel-templates/default", Name = "GetDefaultChannelTemplate")]
[Tags("Channel Templates")]
[EndpointSummary("Get the default channel template")]
[EndpointGroupName("general")]
[ProducesResponseType(typeof(ChannelTemplateResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetDefault(CancellationToken cancellationToken)
{
Option<ChannelTemplateResponseModel> result =
await mediator.Send(new GetDefaultChannelTemplate(), cancellationToken);
return result.ToGetResult();
}
[HttpPut("/api/channel-templates/default/{id:int}", Name = "SetDefaultChannelTemplate")]
[Tags("Channel Templates")]
[EndpointSummary("Set the default channel template")]
[EndpointGroupName("general")]
[ProducesResponseType(typeof(ChannelTemplateResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<IActionResult> SetDefault(int id, CancellationToken cancellationToken)
{
Either<BaseError, ChannelTemplateResponseModel> result =
await mediator.Send(new SetDefaultChannelTemplate(id), cancellationToken);
return result.ToUpdatedResult();
}
[HttpGet("/api/channel-templates/{id:int}", Name = "GetChannelTemplateById")]
[Tags("Channel Templates")]
[EndpointSummary("Get a channel template by id")]
[EndpointGroupName("general")]
[ProducesResponseType(typeof(ChannelTemplateResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetById(int id, CancellationToken cancellationToken)
{
Option<ChannelTemplateResponseModel> result =
await mediator.Send(new GetChannelTemplateById(id), cancellationToken);
return result.ToGetResult();
}
[HttpPost("/api/channel-templates", Name = "CreateChannelTemplate")]
[Tags("Channel Templates")]
[EndpointSummary("Create a channel template")]
[EndpointGroupName("general")]
[ProducesResponseType(typeof(ChannelTemplateResponseModel), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<IActionResult> Create(
[Required] [FromBody] CreateChannelTemplateRequest request,
CancellationToken cancellationToken)
{
Either<BaseError, ChannelTemplateResponseModel> result =
await mediator.Send(request.ToCommand(), cancellationToken);
return result.ToCreatedResult(vm => $"/api/channel-templates/{vm.Id}", vm => vm);
}
[HttpPut("/api/channel-templates/{id:int}", Name = "UpdateChannelTemplate")]
[Tags("Channel Templates")]
[EndpointSummary("Update a channel template")]
[EndpointGroupName("general")]
[ProducesResponseType(typeof(ChannelTemplateResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<IActionResult> Update(
int id,
[Required] [FromBody] UpdateChannelTemplateRequest request,
CancellationToken cancellationToken)
{
Either<BaseError, ChannelTemplateResponseModel> result =
await mediator.Send(request.ToCommand(id), cancellationToken);
return result.ToUpdatedResult();
}
[HttpDelete("/api/channel-templates/{id:int}", Name = "DeleteChannelTemplate")]
[Tags("Channel Templates")]
[EndpointSummary("Delete a channel template")]
[EndpointGroupName("general")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<IActionResult> Delete(int id, CancellationToken cancellationToken)
{
Either<BaseError, Unit> result = await mediator.Send(new DeleteChannelTemplate(id), cancellationToken);
return result.ToDeletedResult();
}
}
@@ -0,0 +1,63 @@
#nullable enable
using ErsatzTV.Application.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Scheduling;
namespace ErsatzTV.Controllers.Api.Requests;
public record CreateChannelTemplateRequest(
string Name,
string Description,
int FFmpegProfileId,
int? WatermarkId,
int? FallbackFillerId,
int? PreRollFillerId,
int? MidRollFillerId,
int? PostRollFillerId,
ChannelStreamSelectorMode StreamSelectorMode,
string? StreamSelector,
string? PreferredAudioLanguageCode,
string? PreferredAudioTitle,
ChannelPlayoutSource PlayoutSource,
ChannelPlayoutMode PlayoutMode,
StreamingMode StreamingMode,
string? PreferredSubtitleLanguageCode,
ChannelSubtitleMode SubtitleMode,
ChannelMusicVideoCreditsMode MusicVideoCreditsMode,
string? MusicVideoCreditsTemplate,
ChannelSongVideoMode SongVideoMode,
ChannelTranscodeMode TranscodeMode,
ChannelIdleBehavior IdleBehavior,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior)
{
public CreateChannelTemplate ToCommand() =>
new(
Name,
Description,
FFmpegProfileId,
WatermarkId,
FallbackFillerId,
PreRollFillerId,
MidRollFillerId,
PostRollFillerId,
StreamSelectorMode,
StreamSelector,
PreferredAudioLanguageCode,
PreferredAudioTitle,
PlayoutSource,
PlayoutMode,
StreamingMode,
PreferredSubtitleLanguageCode,
SubtitleMode,
MusicVideoCreditsMode,
MusicVideoCreditsTemplate,
SongVideoMode,
TranscodeMode,
IdleBehavior,
ShuffleScheduleItems,
RandomStartPoint,
FixedStartTimeBehavior);
}
@@ -0,0 +1,64 @@
#nullable enable
using ErsatzTV.Application.ChannelTemplates;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Scheduling;
namespace ErsatzTV.Controllers.Api.Requests;
public record UpdateChannelTemplateRequest(
string Name,
string Description,
int FFmpegProfileId,
int? WatermarkId,
int? FallbackFillerId,
int? PreRollFillerId,
int? MidRollFillerId,
int? PostRollFillerId,
ChannelStreamSelectorMode StreamSelectorMode,
string? StreamSelector,
string? PreferredAudioLanguageCode,
string? PreferredAudioTitle,
ChannelPlayoutSource PlayoutSource,
ChannelPlayoutMode PlayoutMode,
StreamingMode StreamingMode,
string? PreferredSubtitleLanguageCode,
ChannelSubtitleMode SubtitleMode,
ChannelMusicVideoCreditsMode MusicVideoCreditsMode,
string? MusicVideoCreditsTemplate,
ChannelSongVideoMode SongVideoMode,
ChannelTranscodeMode TranscodeMode,
ChannelIdleBehavior IdleBehavior,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior)
{
public UpdateChannelTemplate ToCommand(int id) =>
new(
id,
Name,
Description,
FFmpegProfileId,
WatermarkId,
FallbackFillerId,
PreRollFillerId,
MidRollFillerId,
PostRollFillerId,
StreamSelectorMode,
StreamSelector,
PreferredAudioLanguageCode,
PreferredAudioTitle,
PlayoutSource,
PlayoutMode,
StreamingMode,
PreferredSubtitleLanguageCode,
SubtitleMode,
MusicVideoCreditsMode,
MusicVideoCreditsTemplate,
SongVideoMode,
TranscodeMode,
IdleBehavior,
ShuffleScheduleItems,
RandomStartPoint,
FixedStartTimeBehavior);
}
+61
View File
@@ -0,0 +1,61 @@
using ErsatzTV.Infrastructure;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Logging.Abstractions;
namespace ErsatzTV;
public class TvContextDesignTimeFactory : IDesignTimeDbContextFactory<TvContext>
{
public TvContext CreateDbContext(string[] args)
{
string provider = GetProvider(args);
var optionsBuilder = new DbContextOptionsBuilder<TvContext>();
if (provider.Equals("MySql", StringComparison.OrdinalIgnoreCase))
{
TvContext.IsSqlite = false;
TvContext.LastInsertedRowId = "last_insert_id()";
TvContext.CaseInsensitiveCollation = "utf8mb4_general_ci";
string connectionString =
Environment.GetEnvironmentVariable("MySql__ConnectionString") ??
"Server=localhost;Database=ersatztv_design_time;User=root;Password=ersatztv;";
optionsBuilder.UseMySql(
connectionString,
new MySqlServerVersion(new Version(8, 0, 36)),
builder => builder.MigrationsAssembly("ErsatzTV.Infrastructure.MySql"));
}
else
{
TvContext.IsSqlite = true;
TvContext.LastInsertedRowId = "last_insert_rowid()";
TvContext.CaseInsensitiveCollation = "NOCASE";
string configFolder = Environment.GetEnvironmentVariable("ETV_CONFIG_FOLDER");
string databasePath = string.IsNullOrWhiteSpace(configFolder)
? Path.Combine(Path.GetTempPath(), "ersatztv-design-time.sqlite3")
: Path.Combine(configFolder, "ersatztv.sqlite3");
optionsBuilder.UseSqlite(
$"Data Source={databasePath}",
builder => builder.MigrationsAssembly("ErsatzTV.Infrastructure.Sqlite"));
}
return new TvContext(
optionsBuilder.Options,
NullLoggerFactory.Instance,
new SlowQueryInterceptor(NullLogger<SlowQueryInterceptor>.Instance));
}
private static string GetProvider(string[] args)
{
for (int index = 0; index < args.Length - 1; index++)
{
if (args[index].Equals("--provider", StringComparison.OrdinalIgnoreCase))
{
return args[index + 1];
}
}
return "Sqlite";
}
}
+942
View File
@@ -816,6 +816,503 @@
}
}
},
"/api/channel-templates": {
"get": {
"tags": [
"Channel Templates"
],
"summary": "Get all channel templates",
"operationId": "GetChannelTemplates",
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
}
},
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
}
},
"text/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
}
}
}
}
}
},
"post": {
"tags": [
"Channel Templates"
],
"summary": "Create a channel template",
"operationId": "CreateChannelTemplate",
"requestBody": {
"content": {
"application/json-patch+json": {
"schema": {
"$ref": "#/components/schemas/CreateChannelTemplateRequest"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateChannelTemplateRequest"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/CreateChannelTemplateRequest"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/CreateChannelTemplateRequest"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "Created",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
},
"422": {
"description": "Unprocessable Entity",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
}
},
"/api/channel-templates/default": {
"get": {
"tags": [
"Channel Templates"
],
"summary": "Get the default channel template",
"operationId": "GetDefaultChannelTemplate",
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
}
},
"/api/channel-templates/default/{id}": {
"put": {
"tags": [
"Channel Templates"
],
"summary": "Set the default channel template",
"operationId": "SetDefaultChannelTemplate",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
},
"422": {
"description": "Unprocessable Entity",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
}
},
"/api/channel-templates/{id}": {
"get": {
"tags": [
"Channel Templates"
],
"summary": "Get a channel template by id",
"operationId": "GetChannelTemplateById",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
},
"put": {
"tags": [
"Channel Templates"
],
"summary": "Update a channel template",
"operationId": "UpdateChannelTemplate",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"requestBody": {
"content": {
"application/json-patch+json": {
"schema": {
"$ref": "#/components/schemas/UpdateChannelTemplateRequest"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateChannelTemplateRequest"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/UpdateChannelTemplateRequest"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/UpdateChannelTemplateRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ChannelTemplateResponseModel"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
},
"422": {
"description": "Unprocessable Entity",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
},
"delete": {
"tags": [
"Channel Templates"
],
"summary": "Delete a channel template",
"operationId": "DeleteChannelTemplate",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"204": {
"description": "No Content"
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
},
"422": {
"description": "Unprocessable Entity",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
}
},
"/api/collections": {
"get": {
"tags": [
@@ -4289,6 +4786,162 @@
],
"type": "string"
},
"ChannelTemplateResponseModel": {
"required": [
"id",
"name",
"description",
"isSystem",
"isDefault",
"fFmpegProfileId",
"watermarkId",
"fallbackFillerId",
"preRollFillerId",
"midRollFillerId",
"postRollFillerId",
"streamSelectorMode",
"streamSelector",
"preferredAudioLanguageCode",
"preferredAudioTitle",
"playoutSource",
"playoutMode",
"streamingMode",
"preferredSubtitleLanguageCode",
"subtitleMode",
"musicVideoCreditsMode",
"musicVideoCreditsTemplate",
"songVideoMode",
"transcodeMode",
"idleBehavior",
"shuffleScheduleItems",
"randomStartPoint",
"fixedStartTimeBehavior"
],
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"isSystem": {
"type": "boolean"
},
"isDefault": {
"type": "boolean"
},
"fFmpegProfileId": {
"type": "integer",
"format": "int32"
},
"watermarkId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"fallbackFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"preRollFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"midRollFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"postRollFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"streamSelectorMode": {
"$ref": "#/components/schemas/ChannelStreamSelectorMode"
},
"streamSelector": {
"type": [
"null",
"string"
]
},
"preferredAudioLanguageCode": {
"type": [
"null",
"string"
]
},
"preferredAudioTitle": {
"type": [
"null",
"string"
]
},
"playoutSource": {
"$ref": "#/components/schemas/ChannelPlayoutSource"
},
"playoutMode": {
"$ref": "#/components/schemas/ChannelPlayoutMode"
},
"streamingMode": {
"$ref": "#/components/schemas/StreamingMode"
},
"preferredSubtitleLanguageCode": {
"type": [
"null",
"string"
]
},
"subtitleMode": {
"$ref": "#/components/schemas/ChannelSubtitleMode"
},
"musicVideoCreditsMode": {
"$ref": "#/components/schemas/ChannelMusicVideoCreditsMode"
},
"musicVideoCreditsTemplate": {
"type": [
"null",
"string"
]
},
"songVideoMode": {
"$ref": "#/components/schemas/ChannelSongVideoMode"
},
"transcodeMode": {
"$ref": "#/components/schemas/ChannelTranscodeMode"
},
"idleBehavior": {
"$ref": "#/components/schemas/ChannelIdleBehavior"
},
"shuffleScheduleItems": {
"type": "boolean"
},
"randomStartPoint": {
"type": "boolean"
},
"fixedStartTimeBehavior": {
"$ref": "#/components/schemas/FixedStartTimeBehavior"
}
}
},
"ChannelTranscodeMode": {
"enum": [
"OnDemand"
@@ -4697,6 +5350,149 @@
}
}
},
"CreateChannelTemplateRequest": {
"required": [
"name",
"description",
"fFmpegProfileId",
"watermarkId",
"fallbackFillerId",
"preRollFillerId",
"midRollFillerId",
"postRollFillerId",
"streamSelectorMode",
"streamSelector",
"preferredAudioLanguageCode",
"preferredAudioTitle",
"playoutSource",
"playoutMode",
"streamingMode",
"preferredSubtitleLanguageCode",
"subtitleMode",
"musicVideoCreditsMode",
"musicVideoCreditsTemplate",
"songVideoMode",
"transcodeMode",
"idleBehavior",
"shuffleScheduleItems",
"randomStartPoint",
"fixedStartTimeBehavior"
],
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"fFmpegProfileId": {
"type": "integer",
"format": "int32"
},
"watermarkId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"fallbackFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"preRollFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"midRollFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"postRollFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"streamSelectorMode": {
"$ref": "#/components/schemas/ChannelStreamSelectorMode"
},
"streamSelector": {
"type": [
"null",
"string"
]
},
"preferredAudioLanguageCode": {
"type": [
"null",
"string"
]
},
"preferredAudioTitle": {
"type": [
"null",
"string"
]
},
"playoutSource": {
"$ref": "#/components/schemas/ChannelPlayoutSource"
},
"playoutMode": {
"$ref": "#/components/schemas/ChannelPlayoutMode"
},
"streamingMode": {
"$ref": "#/components/schemas/StreamingMode"
},
"preferredSubtitleLanguageCode": {
"type": [
"null",
"string"
]
},
"subtitleMode": {
"$ref": "#/components/schemas/ChannelSubtitleMode"
},
"musicVideoCreditsMode": {
"$ref": "#/components/schemas/ChannelMusicVideoCreditsMode"
},
"musicVideoCreditsTemplate": {
"type": [
"null",
"string"
]
},
"songVideoMode": {
"$ref": "#/components/schemas/ChannelSongVideoMode"
},
"transcodeMode": {
"$ref": "#/components/schemas/ChannelTranscodeMode"
},
"idleBehavior": {
"$ref": "#/components/schemas/ChannelIdleBehavior"
},
"shuffleScheduleItems": {
"type": "boolean"
},
"randomStartPoint": {
"type": "boolean"
},
"fixedStartTimeBehavior": {
"$ref": "#/components/schemas/FixedStartTimeBehavior"
}
}
},
"CreateCollectionRequest": {
"required": [
"name"
@@ -7052,6 +7848,149 @@
}
}
},
"UpdateChannelTemplateRequest": {
"required": [
"name",
"description",
"fFmpegProfileId",
"watermarkId",
"fallbackFillerId",
"preRollFillerId",
"midRollFillerId",
"postRollFillerId",
"streamSelectorMode",
"streamSelector",
"preferredAudioLanguageCode",
"preferredAudioTitle",
"playoutSource",
"playoutMode",
"streamingMode",
"preferredSubtitleLanguageCode",
"subtitleMode",
"musicVideoCreditsMode",
"musicVideoCreditsTemplate",
"songVideoMode",
"transcodeMode",
"idleBehavior",
"shuffleScheduleItems",
"randomStartPoint",
"fixedStartTimeBehavior"
],
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"fFmpegProfileId": {
"type": "integer",
"format": "int32"
},
"watermarkId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"fallbackFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"preRollFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"midRollFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"postRollFillerId": {
"type": [
"null",
"integer"
],
"format": "int32"
},
"streamSelectorMode": {
"$ref": "#/components/schemas/ChannelStreamSelectorMode"
},
"streamSelector": {
"type": [
"null",
"string"
]
},
"preferredAudioLanguageCode": {
"type": [
"null",
"string"
]
},
"preferredAudioTitle": {
"type": [
"null",
"string"
]
},
"playoutSource": {
"$ref": "#/components/schemas/ChannelPlayoutSource"
},
"playoutMode": {
"$ref": "#/components/schemas/ChannelPlayoutMode"
},
"streamingMode": {
"$ref": "#/components/schemas/StreamingMode"
},
"preferredSubtitleLanguageCode": {
"type": [
"null",
"string"
]
},
"subtitleMode": {
"$ref": "#/components/schemas/ChannelSubtitleMode"
},
"musicVideoCreditsMode": {
"$ref": "#/components/schemas/ChannelMusicVideoCreditsMode"
},
"musicVideoCreditsTemplate": {
"type": [
"null",
"string"
]
},
"songVideoMode": {
"$ref": "#/components/schemas/ChannelSongVideoMode"
},
"transcodeMode": {
"$ref": "#/components/schemas/ChannelTranscodeMode"
},
"idleBehavior": {
"$ref": "#/components/schemas/ChannelIdleBehavior"
},
"shuffleScheduleItems": {
"type": "boolean"
},
"randomStartPoint": {
"type": "boolean"
},
"fixedStartTimeBehavior": {
"$ref": "#/components/schemas/FixedStartTimeBehavior"
}
}
},
"UpdateCollectionRequest": {
"required": [
"name",
@@ -7418,6 +8357,9 @@
{
"name": "Channels"
},
{
"name": "Channel Templates"
},
{
"name": "Collections"
},
+84
View File
@@ -89,6 +89,36 @@ export interface components {
};
"ChannelStreamSelectorMode": "Default" | "Custom" | "Troubleshooting";
"ChannelSubtitleMode": "None" | "Forced" | "Default" | "Any";
"ChannelTemplateResponseModel": {
"id": number;
"name": string;
"description": string;
"isSystem": boolean;
"isDefault": boolean;
"fFmpegProfileId": number;
"watermarkId": null | number;
"fallbackFillerId": null | number;
"preRollFillerId": null | number;
"midRollFillerId": null | number;
"postRollFillerId": null | number;
"streamSelectorMode": components["schemas"]["ChannelStreamSelectorMode"];
"streamSelector": null | string;
"preferredAudioLanguageCode": null | string;
"preferredAudioTitle": null | string;
"playoutSource": components["schemas"]["ChannelPlayoutSource"];
"playoutMode": components["schemas"]["ChannelPlayoutMode"];
"streamingMode": components["schemas"]["StreamingMode"];
"preferredSubtitleLanguageCode": null | string;
"subtitleMode": components["schemas"]["ChannelSubtitleMode"];
"musicVideoCreditsMode": components["schemas"]["ChannelMusicVideoCreditsMode"];
"musicVideoCreditsTemplate": null | string;
"songVideoMode": components["schemas"]["ChannelSongVideoMode"];
"transcodeMode": components["schemas"]["ChannelTranscodeMode"];
"idleBehavior": components["schemas"]["ChannelIdleBehavior"];
"shuffleScheduleItems": boolean;
"randomStartPoint": boolean;
"fixedStartTimeBehavior": components["schemas"]["FixedStartTimeBehavior"];
};
"ChannelTranscodeMode": "OnDemand";
"ChannelViewModel": {
"id": number;
@@ -157,6 +187,33 @@ export interface components {
"idleBehavior": components["schemas"]["ChannelIdleBehavior"];
"isEnabled": boolean;
"showInEpg": boolean;
};
"CreateChannelTemplateRequest": {
"name": string;
"description": string;
"fFmpegProfileId": number;
"watermarkId": null | number;
"fallbackFillerId": null | number;
"preRollFillerId": null | number;
"midRollFillerId": null | number;
"postRollFillerId": null | number;
"streamSelectorMode": components["schemas"]["ChannelStreamSelectorMode"];
"streamSelector": null | string;
"preferredAudioLanguageCode": null | string;
"preferredAudioTitle": null | string;
"playoutSource": components["schemas"]["ChannelPlayoutSource"];
"playoutMode": components["schemas"]["ChannelPlayoutMode"];
"streamingMode": components["schemas"]["StreamingMode"];
"preferredSubtitleLanguageCode": null | string;
"subtitleMode": components["schemas"]["ChannelSubtitleMode"];
"musicVideoCreditsMode": components["schemas"]["ChannelMusicVideoCreditsMode"];
"musicVideoCreditsTemplate": null | string;
"songVideoMode": components["schemas"]["ChannelSongVideoMode"];
"transcodeMode": components["schemas"]["ChannelTranscodeMode"];
"idleBehavior": components["schemas"]["ChannelIdleBehavior"];
"shuffleScheduleItems": boolean;
"randomStartPoint": boolean;
"fixedStartTimeBehavior": components["schemas"]["FixedStartTimeBehavior"];
};
"CreateCollectionRequest": {
"name": null | string;
@@ -587,6 +644,33 @@ export interface components {
"idleBehavior": components["schemas"]["ChannelIdleBehavior"];
"isEnabled": boolean;
"showInEpg": boolean;
};
"UpdateChannelTemplateRequest": {
"name": string;
"description": string;
"fFmpegProfileId": number;
"watermarkId": null | number;
"fallbackFillerId": null | number;
"preRollFillerId": null | number;
"midRollFillerId": null | number;
"postRollFillerId": null | number;
"streamSelectorMode": components["schemas"]["ChannelStreamSelectorMode"];
"streamSelector": null | string;
"preferredAudioLanguageCode": null | string;
"preferredAudioTitle": null | string;
"playoutSource": components["schemas"]["ChannelPlayoutSource"];
"playoutMode": components["schemas"]["ChannelPlayoutMode"];
"streamingMode": components["schemas"]["StreamingMode"];
"preferredSubtitleLanguageCode": null | string;
"subtitleMode": components["schemas"]["ChannelSubtitleMode"];
"musicVideoCreditsMode": components["schemas"]["ChannelMusicVideoCreditsMode"];
"musicVideoCreditsTemplate": null | string;
"songVideoMode": components["schemas"]["ChannelSongVideoMode"];
"transcodeMode": components["schemas"]["ChannelTranscodeMode"];
"idleBehavior": components["schemas"]["ChannelIdleBehavior"];
"shuffleScheduleItems": boolean;
"randomStartPoint": boolean;
"fixedStartTimeBehavior": components["schemas"]["FixedStartTimeBehavior"];
};
"UpdateCollectionRequest": {
"name": null | string;