@ -7,24 +7,24 @@ using Microsoft.Extensions.Logging;
using YamlDotNet.Serialization ;
using YamlDotNet.Serialization ;
using YamlDotNet.Serialization.NamingConventions ;
using YamlDotNet.Serialization.NamingConventions ;
namespace ErsatzTV.Core.Scheduling.Template Scheduling ;
namespace ErsatzTV.Core.Scheduling.Yaml Scheduling ;
public class Template PlayoutBuilder(
public class Yaml PlayoutBuilder(
ILocalFileSystem localFileSystem ,
ILocalFileSystem localFileSystem ,
IConfigElementRepository configElementRepository ,
IConfigElementRepository configElementRepository ,
IMediaCollectionRepository mediaCollectionRepository ,
IMediaCollectionRepository mediaCollectionRepository ,
ILogger < Template PlayoutBuilder> logger )
ILogger < Yaml PlayoutBuilder> logger )
: ITemplate PlayoutBuilder
: IYaml PlayoutBuilder
{
{
public async Task < Playout > Build ( Playout playout , PlayoutBuildMode mode , CancellationToken cancellationToken )
public async Task < Playout > Build ( Playout playout , PlayoutBuildMode mode , CancellationToken cancellationToken )
{
{
if ( ! localFileSystem . FileExists ( playout . TemplateFile ) )
if ( ! localFileSystem . FileExists ( playout . TemplateFile ) )
{
{
logger . LogWarning ( "Playout template file {File} does not exist; aborting." , playout . TemplateFile ) ;
logger . LogWarning ( "YAML playout file {File} does not exist; aborting." , playout . TemplateFile ) ;
return playout ;
return playout ;
}
}
PlayoutTemplate playoutTemplate = await LoadTemplate ( playout , cancellationToken ) ;
YamlPlayoutDefinition playoutDefinition = await LoadYamlDefinition ( playout , cancellationToken ) ;
DateTimeOffset start = DateTimeOffset . Now ;
DateTimeOffset start = DateTimeOffset . Now ;
int daysToBuild = await GetDaysToBuild ( ) ;
int daysToBuild = await GetDaysToBuild ( ) ;
@ -32,7 +32,7 @@ public class TemplatePlayoutBuilder(
if ( mode is not PlayoutBuildMode . Reset )
if ( mode is not PlayoutBuildMode . Reset )
{
{
logger . LogWarning ( "Template playouts can only be reset; ignoring build mode {Mode}" , mode . ToString ( ) ) ;
logger . LogWarning ( "YAML playouts can only be reset; ignoring build mode {Mode}" , mode . ToString ( ) ) ;
return playout ;
return playout ;
}
}
@ -50,16 +50,16 @@ public class TemplatePlayoutBuilder(
var index = 0 ;
var index = 0 ;
while ( currentTime < finish )
while ( currentTime < finish )
{
{
if ( index > = playoutTemplate . Playout . Count )
if ( index > = playoutDefinition . Playout . Count )
{
{
logger . LogInformation ( "Reached the end of the playout template ; stopping" ) ;
logger . LogInformation ( "Reached the end of the YAML playout definition ; stopping" ) ;
break ;
break ;
}
}
PlayoutTemplateItem playoutItem = playoutTemplate . Playout [ index ] ;
YamlPlayoutInstruction playoutItem = playoutDefinition . Playout [ index ] ;
// repeat resets index into template playout
// repeat resets index into YAML playout
if ( playoutItem is PlayoutTemplateRepeatItem )
if ( playoutItem is YamlPlayoutRepeatInstruction )
{
{
index = 0 ;
index = 0 ;
if ( playout . Items . Count = = itemsAfterRepeat )
if ( playout . Items . Count = = itemsAfterRepeat )
@ -74,7 +74,7 @@ public class TemplatePlayoutBuilder(
Option < IMediaCollectionEnumerator > maybeEnumerator = await GetCachedEnumeratorForContent (
Option < IMediaCollectionEnumerator > maybeEnumerator = await GetCachedEnumeratorForContent (
playout ,
playout ,
playoutTemplate ,
playoutDefinition ,
enumerators ,
enumerators ,
playoutItem . Content ,
playoutItem . Content ,
cancellationToken ) ;
cancellationToken ) ;
@ -92,31 +92,31 @@ public class TemplatePlayoutBuilder(
{
{
switch ( playoutItem )
switch ( playoutItem )
{
{
case PlayoutTemplateCountItem count :
case YamlPlayoutCountInstruction count :
currentTime = PlayoutTemplate SchedulerCount . Schedule ( playout , currentTime , count , enumerator ) ;
currentTime = Yaml PlayoutSchedulerCount. Schedule ( playout , currentTime , count , enumerator ) ;
break ;
break ;
case PlayoutTemplateDurationItem duration :
case YamlPlayoutDurationInstruction duration :
Option < IMediaCollectionEnumerator > durationFallbackEnumerator = await GetCachedEnumeratorForContent (
Option < IMediaCollectionEnumerator > durationFallbackEnumerator = await GetCachedEnumeratorForContent (
playout ,
playout ,
playoutTemplate ,
playoutDefinition ,
enumerators ,
enumerators ,
duration . Fallback ,
duration . Fallback ,
cancellationToken ) ;
cancellationToken ) ;
currentTime = PlayoutTemplate SchedulerDuration . Schedule (
currentTime = Yaml PlayoutSchedulerDuration. Schedule (
playout ,
playout ,
currentTime ,
currentTime ,
duration ,
duration ,
enumerator ,
enumerator ,
durationFallbackEnumerator ) ;
durationFallbackEnumerator ) ;
break ;
break ;
case PlayoutTemplatePadToNextItem padToNext :
case YamlPlayoutPadToNextInstruction padToNext :
Option < IMediaCollectionEnumerator > fallbackEnumerator = await GetCachedEnumeratorForContent (
Option < IMediaCollectionEnumerator > fallbackEnumerator = await GetCachedEnumeratorForContent (
playout ,
playout ,
playoutTemplate ,
playoutDefinition ,
enumerators ,
enumerators ,
padToNext . Fallback ,
padToNext . Fallback ,
cancellationToken ) ;
cancellationToken ) ;
currentTime = PlayoutTemplate SchedulerPadToNext . Schedule (
currentTime = Yaml PlayoutSchedulerPadToNext. Schedule (
playout ,
playout ,
currentTime ,
currentTime ,
padToNext ,
padToNext ,
@ -139,7 +139,7 @@ public class TemplatePlayoutBuilder(
private async Task < Option < IMediaCollectionEnumerator > > GetCachedEnumeratorForContent (
private async Task < Option < IMediaCollectionEnumerator > > GetCachedEnumeratorForContent (
Playout playout ,
Playout playout ,
PlayoutTemplate playoutTemplate ,
YamlPlayoutDefinition playoutDefinition ,
Dictionary < string , IMediaCollectionEnumerator > enumerators ,
Dictionary < string , IMediaCollectionEnumerator > enumerators ,
string contentKey ,
string contentKey ,
CancellationToken cancellationToken )
CancellationToken cancellationToken )
@ -152,7 +152,7 @@ public class TemplatePlayoutBuilder(
if ( ! enumerators . TryGetValue ( contentKey , out IMediaCollectionEnumerator enumerator ) )
if ( ! enumerators . TryGetValue ( contentKey , out IMediaCollectionEnumerator enumerator ) )
{
{
Option < IMediaCollectionEnumerator > maybeEnumerator =
Option < IMediaCollectionEnumerator > maybeEnumerator =
await GetEnumeratorForContent ( playout , contentKey , playoutTemplate , cancellationToken ) ;
await GetEnumeratorForContent ( playout , contentKey , playoutDefinition , cancellationToken ) ;
if ( maybeEnumerator . IsNone )
if ( maybeEnumerator . IsNone )
{
{
@ -172,10 +172,10 @@ public class TemplatePlayoutBuilder(
private async Task < Option < IMediaCollectionEnumerator > > GetEnumeratorForContent (
private async Task < Option < IMediaCollectionEnumerator > > GetEnumeratorForContent (
Playout playout ,
Playout playout ,
string contentKey ,
string contentKey ,
PlayoutTemplate playoutTemplate ,
YamlPlayoutDefinition playoutDefinition ,
CancellationToken cancellationToken )
CancellationToken cancellationToken )
{
{
int index = playoutTemplate . Content . FindIndex ( c = > c . Key = = contentKey ) ;
int index = playoutDefinition . Content . FindIndex ( c = > c . Key = = contentKey ) ;
if ( index < 0 )
if ( index < 0 )
{
{
return Option < IMediaCollectionEnumerator > . None ;
return Option < IMediaCollectionEnumerator > . None ;
@ -183,13 +183,13 @@ public class TemplatePlayoutBuilder(
List < MediaItem > items = [ ] ;
List < MediaItem > items = [ ] ;
PlayoutTemplate ContentItem content = playoutTemplate . Content [ index ] ;
Yaml PlayoutContentItem content = playoutDefinition . Content [ index ] ;
switch ( content )
switch ( content )
{
{
case PlayoutTemplate ContentSearchItem search :
case Yaml PlayoutContentSearchItem search :
items = await mediaCollectionRepository . GetSmartCollectionItems ( search . Query ) ;
items = await mediaCollectionRepository . GetSmartCollectionItems ( search . Query ) ;
break ;
break ;
case PlayoutTemplate ContentShowItem show :
case Yaml PlayoutContentShowItem show :
items = await mediaCollectionRepository . GetShowItemsByShowGuids (
items = await mediaCollectionRepository . GetShowItemsByShowGuids (
show . Guids . Map ( g = > $"{g.Source}://{g.Value}" ) . ToList ( ) ) ;
show . Guids . Map ( g = > $"{g.Source}://{g.Value}" ) . ToList ( ) ) ;
break ;
break ;
@ -209,7 +209,7 @@ public class TemplatePlayoutBuilder(
return Option < IMediaCollectionEnumerator > . None ;
return Option < IMediaCollectionEnumerator > . None ;
}
}
private static async Task < PlayoutTemplate > LoadTemplate ( Playout playout , CancellationToken cancellationToken )
private static async Task < YamlPlayoutDefinition > LoadYamlDefinition ( Playout playout , CancellationToken cancellationToken )
{
{
string yaml = await File . ReadAllTextAsync ( playout . TemplateFile , cancellationToken ) ;
string yaml = await File . ReadAllTextAsync ( playout . TemplateFile , cancellationToken ) ;
@ -220,24 +220,24 @@ public class TemplatePlayoutBuilder(
{
{
var contentKeyMappings = new Dictionary < string , Type >
var contentKeyMappings = new Dictionary < string , Type >
{
{
{ "search" , typeof ( PlayoutTemplate ContentSearchItem ) } ,
{ "search" , typeof ( Yaml PlayoutContentSearchItem) } ,
{ "show" , typeof ( PlayoutTemplate ContentShowItem ) }
{ "show" , typeof ( Yaml PlayoutContentShowItem) }
} ;
} ;
o . AddUniqueKeyTypeDiscriminator < PlayoutTemplate ContentItem > ( contentKeyMappings ) ;
o . AddUniqueKeyTypeDiscriminator < Yaml PlayoutContentItem> ( contentKeyMappings ) ;
var instructionKeyMappings = new Dictionary < string , Type >
var instructionKeyMappings = new Dictionary < string , Type >
{
{
{ "count" , typeof ( PlayoutTemplateCountItem ) } ,
{ "count" , typeof ( YamlPlayoutCountInstruction ) } ,
{ "duration" , typeof ( PlayoutTemplateDurationItem ) } ,
{ "duration" , typeof ( YamlPlayoutDurationInstruction ) } ,
{ "pad_to_next" , typeof ( PlayoutTemplatePadToNextItem ) } ,
{ "pad_to_next" , typeof ( YamlPlayoutPadToNextInstruction ) } ,
{ "repeat" , typeof ( PlayoutTemplateRepeatItem ) }
{ "repeat" , typeof ( YamlPlayoutRepeatInstruction ) }
} ;
} ;
o . AddUniqueKeyTypeDiscriminator < PlayoutTemplateItem > ( instructionKeyMappings ) ;
o . AddUniqueKeyTypeDiscriminator < YamlPlayoutInstruction > ( instructionKeyMappings ) ;
} )
} )
. Build ( ) ;
. Build ( ) ;
return deserializer . Deserialize < PlayoutTemplate > ( yaml ) ;
return deserializer . Deserialize < YamlPlayoutDefinition > ( yaml ) ;
}
}
}
}