Browse Source

add playout template show content (#1812)

pull/1813/head
Jason Dove 1 year ago committed by GitHub
parent
commit
53bd745678
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      ErsatzTV.Core.Tests/Fakes/FakeMediaCollectionRepository.cs
  2. 1
      ErsatzTV.Core/Interfaces/Repositories/IMediaCollectionRepository.cs
  3. 2
      ErsatzTV.Core/Scheduling/TemplateScheduling/PlayoutTemplate.cs
  4. 6
      ErsatzTV.Core/Scheduling/TemplateScheduling/PlayoutTemplateContent.cs
  5. 7
      ErsatzTV.Core/Scheduling/TemplateScheduling/PlayoutTemplateContentGuid.cs
  6. 7
      ErsatzTV.Core/Scheduling/TemplateScheduling/PlayoutTemplateContentShowItem.cs
  7. 28
      ErsatzTV.Core/Scheduling/TemplateScheduling/TemplatePlayoutBuilder.cs
  8. 37
      ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs

1
ErsatzTV.Core.Tests/Fakes/FakeMediaCollectionRepository.cs

@ -23,6 +23,7 @@ public class FakeMediaCollectionRepository : IMediaCollectionRepository @@ -23,6 +23,7 @@ public class FakeMediaCollectionRepository : IMediaCollectionRepository
public Task<List<MediaItem>> GetMultiCollectionItems(int id) => throw new NotSupportedException();
public Task<List<MediaItem>> GetSmartCollectionItems(int id) => _data[id].ToList().AsTask();
public Task<List<MediaItem>> GetSmartCollectionItems(string query) => throw new NotSupportedException();
public Task<List<MediaItem>> GetShowItemsByShowGuids(List<string> guids) => throw new NotSupportedException();
public Task<List<MediaItem>> GetPlaylistItems(int id) => throw new NotSupportedException();
public Task<List<Movie>> GetMovie(int id) => throw new NotSupportedException();
public Task<List<Episode>> GetEpisode(int id) => throw new NotSupportedException();

1
ErsatzTV.Core/Interfaces/Repositories/IMediaCollectionRepository.cs

@ -12,6 +12,7 @@ public interface IMediaCollectionRepository @@ -12,6 +12,7 @@ public interface IMediaCollectionRepository
Task<List<MediaItem>> GetMultiCollectionItems(int id);
Task<List<MediaItem>> GetSmartCollectionItems(int id);
Task<List<MediaItem>> GetSmartCollectionItems(string query);
Task<List<MediaItem>> GetShowItemsByShowGuids(List<string> guids);
Task<List<MediaItem>> GetPlaylistItems(int id);
Task<List<Movie>> GetMovie(int id);
Task<List<Episode>> GetEpisode(int id);

2
ErsatzTV.Core/Scheduling/TemplateScheduling/PlayoutTemplate.cs

@ -2,6 +2,6 @@ namespace ErsatzTV.Core.Scheduling.TemplateScheduling; @@ -2,6 +2,6 @@ namespace ErsatzTV.Core.Scheduling.TemplateScheduling;
public class PlayoutTemplate
{
public List<PlayoutTemplateContentSearchItem> Content { get; set; } = [];
public List<PlayoutTemplateContentItem> Content { get; set; } = [];
public List<PlayoutTemplateItem> Playout { get; set; } = [];
}

6
ErsatzTV.Core/Scheduling/TemplateScheduling/PlayoutTemplateContent.cs

@ -1,6 +0,0 @@ @@ -1,6 +0,0 @@
namespace ErsatzTV.Core.Scheduling.TemplateScheduling;
public class PlayoutTemplateContent
{
}

7
ErsatzTV.Core/Scheduling/TemplateScheduling/PlayoutTemplateContentGuid.cs

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
namespace ErsatzTV.Core.Scheduling.TemplateScheduling;
public class PlayoutTemplateContentGuid
{
public string Source { get; set; }
public string Value { get; set; }
}

7
ErsatzTV.Core/Scheduling/TemplateScheduling/PlayoutTemplateContentShowItem.cs

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
namespace ErsatzTV.Core.Scheduling.TemplateScheduling;
public class PlayoutTemplateContentShowItem : PlayoutTemplateContentItem
{
public string Show { get; set; }
public List<PlayoutTemplateContentGuid> Guids { get; set; } = [];
}

28
ErsatzTV.Core/Scheduling/TemplateScheduling/TemplatePlayoutBuilder.cs

@ -181,8 +181,20 @@ public class TemplatePlayoutBuilder( @@ -181,8 +181,20 @@ public class TemplatePlayoutBuilder(
return Option<IMediaCollectionEnumerator>.None;
}
PlayoutTemplateContentSearchItem content = playoutTemplate.Content[index];
List<MediaItem> items = await mediaCollectionRepository.GetSmartCollectionItems(content.Query);
List<MediaItem> items = [];
PlayoutTemplateContentItem content = playoutTemplate.Content[index];
switch (content)
{
case PlayoutTemplateContentSearchItem search:
items = await mediaCollectionRepository.GetSmartCollectionItems(search.Query);
break;
case PlayoutTemplateContentShowItem show:
items = await mediaCollectionRepository.GetShowItemsByShowGuids(
show.Guids.Map(g => $"{g.Source}://{g.Value}").ToList());
break;
}
var state = new CollectionEnumeratorState { Seed = playout.Seed + index, Index = 0 };
switch (Enum.Parse<PlaybackOrder>(content.Order, true))
{
@ -206,7 +218,15 @@ public class TemplatePlayoutBuilder( @@ -206,7 +218,15 @@ public class TemplatePlayoutBuilder(
.WithTypeDiscriminatingNodeDeserializer(
o =>
{
var keyMappings = new Dictionary<string, Type>
var contentKeyMappings = new Dictionary<string, Type>
{
{ "search", typeof(PlayoutTemplateContentSearchItem) },
{ "show", typeof(PlayoutTemplateContentShowItem) }
};
o.AddUniqueKeyTypeDiscriminator<PlayoutTemplateContentItem>(contentKeyMappings);
var instructionKeyMappings = new Dictionary<string, Type>
{
{ "count", typeof(PlayoutTemplateCountItem) },
{ "duration", typeof(PlayoutTemplateDurationItem) },
@ -214,7 +234,7 @@ public class TemplatePlayoutBuilder( @@ -214,7 +234,7 @@ public class TemplatePlayoutBuilder(
{ "repeat", typeof(PlayoutTemplateRepeatItem) }
};
o.AddUniqueKeyTypeDiscriminator<PlayoutTemplateItem>(keyMappings);
o.AddUniqueKeyTypeDiscriminator<PlayoutTemplateItem>(instructionKeyMappings);
})
.Build();

37
ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs

@ -422,6 +422,43 @@ public class MediaCollectionRepository : IMediaCollectionRepository @@ -422,6 +422,43 @@ public class MediaCollectionRepository : IMediaCollectionRepository
return result.DistinctBy(x => x.Id).ToList();
}
public async Task<List<MediaItem>> GetShowItemsByShowGuids(List<string> guids)
{
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
var result = new List<MediaItem>();
System.Collections.Generic.HashSet<int> showIds = [];
foreach (string guid in guids)
{
// don't search any more once we have a matching show
if (showIds.Count > 0)
{
break;
}
List<int> nextIds = await dbContext.ShowMetadata
.Filter(
sm => sm.Guids.Any(g => EF.Functions.Collate(g.Guid, TvContext.CaseInsensitiveCollation) == guid))
.Map(sm => sm.ShowId)
.ToListAsync();
foreach (int showId in nextIds)
{
showIds.Add(showId);
}
}
// multiple shows are not supported here, just use the first match
foreach (int showId in showIds.HeadOrNone())
{
result.AddRange(await GetShowItemsFromShowId(dbContext, showId));
}
return result;
}
public async Task<List<CollectionWithItems>> GetMultiCollectionCollections(int id)
{
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();

Loading…
Cancel
Save