Browse Source

add yaml skip to item instruction (#1830)

* work around MSB3374 error

* add skip to item instruction
pull/1831/head
Jason Dove 9 months ago committed by GitHub
parent
commit
b737775f9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      Directory.Build.props
  2. 68
      ErsatzTV.Core/Scheduling/YamlScheduling/Handlers/YamlPlayoutSkipToItemHandler.cs
  3. 12
      ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutSkipToItemInstruction.cs
  4. 2
      ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutBuilder.cs
  5. 3
      ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj
  6. 3
      ErsatzTV/ErsatzTV.csproj

5
Directory.Build.props

@ -3,9 +3,4 @@ @@ -3,9 +3,4 @@
<InformationalVersion>develop</InformationalVersion>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
<!-- Remove when https://github.com/dotnet/sdk/issues/13808 is resolved -->
<PropertyGroup>
<IntermediateOutputPath>/tmp/$(USER)/project/obj/</IntermediateOutputPath>
</PropertyGroup>
</Project>

68
ErsatzTV.Core/Scheduling/YamlScheduling/Handlers/YamlPlayoutSkipToItemHandler.cs

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Scheduling;
using ErsatzTV.Core.Scheduling.YamlScheduling.Models;
using Microsoft.Extensions.Logging;
namespace ErsatzTV.Core.Scheduling.YamlScheduling.Handlers;
public class YamlPlayoutSkipToItemHandler(EnumeratorCache enumeratorCache) : IYamlPlayoutHandler
{
public bool Reset => true;
public async Task<bool> Handle(
YamlPlayoutContext context,
YamlPlayoutInstruction instruction,
ILogger<YamlPlayoutBuilder> logger,
CancellationToken cancellationToken)
{
if (instruction is not YamlPlayoutSkipToItemInstruction skipToItem)
{
return false;
}
if (skipToItem.Season < 0 || skipToItem.Episode < 1)
{
logger.LogWarning(
"Unable to skip to invalid season/episode: {Season}/{Episode}",
skipToItem.Season,
skipToItem.Episode);
return false;
}
Option<IMediaCollectionEnumerator> maybeEnumerator = await enumeratorCache.GetCachedEnumeratorForContent(
context,
skipToItem.Content,
cancellationToken);
foreach (IMediaCollectionEnumerator enumerator in maybeEnumerator)
{
var done = false;
for (var index = 0; index < enumerator.Count; index++)
{
if (done)
{
break;
}
foreach (MediaItem mediaItem in enumerator.Current)
{
if (mediaItem is Episode episode)
{
if (episode.Season?.SeasonNumber == skipToItem.Season
&& episode.EpisodeMetadata.HeadOrNone().Map(em => em.EpisodeNumber) == skipToItem.Episode)
{
context.ContentIndex[skipToItem.Content] = index;
done = true;
break;
}
}
enumerator.MoveNext();
}
}
}
return true;
}
}

12
ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutSkipToItemInstruction.cs

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
using YamlDotNet.Serialization;
namespace ErsatzTV.Core.Scheduling.YamlScheduling.Models;
public class YamlPlayoutSkipToItemInstruction : YamlPlayoutInstruction
{
[YamlMember(Alias = "skip_to_item", ApplyNamingConventions = false)]
public string SkipToItem { get; set; }
public int Season { get; set; }
public int Episode { get; set; }
}

2
ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutBuilder.cs

@ -167,6 +167,7 @@ public class YamlPlayoutBuilder( @@ -167,6 +167,7 @@ public class YamlPlayoutBuilder(
YamlPlayoutNewEpgGroupInstruction => new YamlPlayoutNewEpgGroupHandler(),
YamlPlayoutShuffleSequenceInstruction => new YamlPlayoutShuffleSequenceHandler(),
YamlPlayoutSkipItemsInstruction => new YamlPlayoutSkipItemsHandler(),
YamlPlayoutSkipToItemInstruction => new YamlPlayoutSkipToItemHandler(enumeratorCache),
// content handlers
YamlPlayoutAllInstruction => new YamlPlayoutAllHandler(enumeratorCache),
@ -213,6 +214,7 @@ public class YamlPlayoutBuilder( @@ -213,6 +214,7 @@ public class YamlPlayoutBuilder(
{ "sequence", typeof(YamlPlayoutSequenceInstruction) },
{ "shuffle_sequence", typeof(YamlPlayoutShuffleSequenceInstruction) },
{ "skip_items", typeof(YamlPlayoutSkipItemsInstruction) },
{ "skip_to_item", typeof(YamlPlayoutSkipToItemInstruction) },
{ "wait_until", typeof(YamlPlayoutWaitUntilInstruction) }
};

3
ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj

@ -6,6 +6,9 @@ @@ -6,6 +6,9 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<!-- works around MSB3374 error -->
<DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>
</PropertyGroup>
<ItemGroup>

3
ErsatzTV/ErsatzTV.csproj

@ -13,6 +13,9 @@ @@ -13,6 +13,9 @@
<UserSecretsId>bf31217d-f4ec-4520-8cc3-138059044ede</UserSecretsId>
<AnalysisLevel>latest-Recommended</AnalysisLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- works around MSB3374 error -->
<DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>
</PropertyGroup>
<ItemGroup>

Loading…
Cancel
Save