update dependencies; code cleanup (#1357)
* update dependencies * code cleanup
This commit is contained in:
@@ -6,8 +6,8 @@ namespace ErsatzTV.Core.Scheduling;
|
||||
|
||||
public sealed class ChronologicalMediaCollectionEnumerator : IMediaCollectionEnumerator
|
||||
{
|
||||
private readonly IList<MediaItem> _sortedMediaItems;
|
||||
private readonly Lazy<Option<TimeSpan>> _lazyMinimumDuration;
|
||||
private readonly IList<MediaItem> _sortedMediaItems;
|
||||
|
||||
public ChronologicalMediaCollectionEnumerator(
|
||||
IEnumerable<MediaItem> mediaItems,
|
||||
@@ -31,11 +31,9 @@ public sealed class ChronologicalMediaCollectionEnumerator : IMediaCollectionEnu
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetState(CollectionEnumeratorState state)
|
||||
{
|
||||
public void ResetState(CollectionEnumeratorState state) =>
|
||||
// seed doesn't matter in chronological
|
||||
State.Index = state.Index;
|
||||
}
|
||||
|
||||
public CollectionEnumeratorState State { get; }
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ namespace ErsatzTV.Core.Scheduling;
|
||||
public class CustomOrderCollectionEnumerator : IMediaCollectionEnumerator
|
||||
{
|
||||
private readonly Collection _collection;
|
||||
private readonly Lazy<Option<TimeSpan>> _lazyMinimumDuration;
|
||||
private readonly IList<MediaItem> _mediaItems;
|
||||
|
||||
private readonly IList<MediaItem> _sortedMediaItems;
|
||||
private readonly Lazy<Option<TimeSpan>> _lazyMinimumDuration;
|
||||
|
||||
public CustomOrderCollectionEnumerator(
|
||||
Collection collection,
|
||||
@@ -35,11 +35,9 @@ public class CustomOrderCollectionEnumerator : IMediaCollectionEnumerator
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetState(CollectionEnumeratorState state)
|
||||
{
|
||||
public void ResetState(CollectionEnumeratorState state) =>
|
||||
// seed doesn't matter here
|
||||
State.Index = state.Index;
|
||||
}
|
||||
|
||||
public CollectionEnumeratorState State { get; }
|
||||
|
||||
@@ -48,6 +46,6 @@ public class CustomOrderCollectionEnumerator : IMediaCollectionEnumerator
|
||||
public void MoveNext() => State.Index = (State.Index + 1) % _sortedMediaItems.Count;
|
||||
|
||||
public Option<TimeSpan> MinimumDuration => _lazyMinimumDuration.Value;
|
||||
|
||||
|
||||
public int Count => _sortedMediaItems.Count;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ using ErsatzTV.Core.Extensions;
|
||||
using ErsatzTV.Core.Interfaces.Scheduling;
|
||||
using LanguageExt.UnsafeValueAccess;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace ErsatzTV.Core.Scheduling;
|
||||
|
||||
@@ -606,7 +604,7 @@ public abstract class PlayoutModeSchedulerBase<T> : IPlayoutModeScheduler<T> whe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PlayoutModeSchedulerDuration : PlayoutModeSchedulerBase<ProgramSche
|
||||
|
||||
var willFinishInTime = true;
|
||||
Option<DateTimeOffset> durationUntil = None;
|
||||
int discardAttempts = 0;
|
||||
var discardAttempts = 0;
|
||||
|
||||
IMediaCollectionEnumerator contentEnumerator =
|
||||
collectionEnumerators[CollectionKey.ForScheduleItem(scheduleItem)];
|
||||
@@ -121,7 +121,7 @@ public class PlayoutModeSchedulerDuration : PlayoutModeSchedulerBase<ProgramSche
|
||||
durationUntil.Do(du => playoutItem.GuideFinish = du.UtcDateTime);
|
||||
|
||||
DateTimeOffset durationFinish = nextState.DurationFinish.IfNone(SystemTime.MaxValueUtc);
|
||||
|
||||
|
||||
var enumeratorStates = new Dictionary<CollectionKey, CollectionEnumeratorState>();
|
||||
foreach ((CollectionKey key, IMediaCollectionEnumerator enumerator) in collectionEnumerators)
|
||||
{
|
||||
@@ -134,9 +134,9 @@ public class PlayoutModeSchedulerDuration : PlayoutModeSchedulerBase<ProgramSche
|
||||
scheduleItem,
|
||||
playoutItem,
|
||||
itemChapters,
|
||||
log: false,
|
||||
false,
|
||||
cancellationToken);
|
||||
|
||||
|
||||
DateTimeOffset itemEndTimeWithFiller = maybePlayoutItems.Max(pi => pi.FinishOffset);
|
||||
|
||||
willFinishInTime = itemStartTime > durationFinish ||
|
||||
@@ -165,7 +165,7 @@ public class PlayoutModeSchedulerDuration : PlayoutModeSchedulerBase<ProgramSche
|
||||
{
|
||||
enumerator.ResetState(enumeratorStates[key]);
|
||||
}
|
||||
|
||||
|
||||
TimeSpan durationBlock = itemEndTimeWithFiller - itemStartTime;
|
||||
if (itemEndTimeWithFiller - itemStartTime > scheduleItem.PlayoutDuration)
|
||||
{
|
||||
|
||||
@@ -86,7 +86,7 @@ public class PlayoutModeSchedulerFlood : PlayoutModeSchedulerBase<ProgramSchedul
|
||||
scheduleItem,
|
||||
playoutItem,
|
||||
itemChapters,
|
||||
log: false,
|
||||
false,
|
||||
cancellationToken);
|
||||
|
||||
DateTimeOffset itemEndTimeWithFiller = maybePlayoutItems.Max(pi => pi.FinishOffset);
|
||||
|
||||
@@ -85,7 +85,7 @@ public class PlayoutModeSchedulerMultiple : PlayoutModeSchedulerBase<ProgramSche
|
||||
scheduleItem,
|
||||
playoutItem,
|
||||
itemChapters,
|
||||
log: true,
|
||||
true,
|
||||
cancellationToken));
|
||||
|
||||
nextState = nextState with
|
||||
|
||||
@@ -59,7 +59,7 @@ public class PlayoutModeSchedulerOne : PlayoutModeSchedulerBase<ProgramScheduleI
|
||||
scheduleItem,
|
||||
playoutItem,
|
||||
itemChapters,
|
||||
log: true,
|
||||
true,
|
||||
cancellationToken);
|
||||
|
||||
PlayoutBuilderState nextState = playoutBuilderState with
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace ErsatzTV.Core.Scheduling;
|
||||
|
||||
public class RandomizedMediaCollectionEnumerator : IMediaCollectionEnumerator
|
||||
{
|
||||
private readonly IList<MediaItem> _mediaItems;
|
||||
private readonly Lazy<Option<TimeSpan>> _lazyMinimumDuration;
|
||||
private readonly IList<MediaItem> _mediaItems;
|
||||
private readonly Random _random;
|
||||
private int _index;
|
||||
|
||||
@@ -27,11 +27,9 @@ public class RandomizedMediaCollectionEnumerator : IMediaCollectionEnumerator
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetState(CollectionEnumeratorState state)
|
||||
{
|
||||
public void ResetState(CollectionEnumeratorState state) =>
|
||||
// seed never changes here, no need to reset
|
||||
State.Index = state.Index;
|
||||
}
|
||||
|
||||
public CollectionEnumeratorState State { get; }
|
||||
|
||||
@@ -44,6 +42,6 @@ public class RandomizedMediaCollectionEnumerator : IMediaCollectionEnumerator
|
||||
}
|
||||
|
||||
public Option<TimeSpan> MinimumDuration => _lazyMinimumDuration.Value;
|
||||
|
||||
|
||||
public int Count => _mediaItems.Count;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace ErsatzTV.Core.Scheduling;
|
||||
|
||||
public sealed class SeasonEpisodeMediaCollectionEnumerator : IMediaCollectionEnumerator
|
||||
{
|
||||
private readonly IList<MediaItem> _sortedMediaItems;
|
||||
private readonly Lazy<Option<TimeSpan>> _lazyMinimumDuration;
|
||||
private readonly IList<MediaItem> _sortedMediaItems;
|
||||
|
||||
public SeasonEpisodeMediaCollectionEnumerator(
|
||||
IEnumerable<MediaItem> mediaItems,
|
||||
@@ -31,11 +31,9 @@ public sealed class SeasonEpisodeMediaCollectionEnumerator : IMediaCollectionEnu
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetState(CollectionEnumeratorState state)
|
||||
{
|
||||
public void ResetState(CollectionEnumeratorState state) =>
|
||||
// seed doesn't matter here
|
||||
State.Index = state.Index;
|
||||
}
|
||||
|
||||
public CollectionEnumeratorState State { get; }
|
||||
|
||||
@@ -44,6 +42,6 @@ public sealed class SeasonEpisodeMediaCollectionEnumerator : IMediaCollectionEnu
|
||||
public void MoveNext() => State.Index = (State.Index + 1) % _sortedMediaItems.Count;
|
||||
|
||||
public Option<TimeSpan> MinimumDuration => _lazyMinimumDuration.Value;
|
||||
|
||||
|
||||
public int Count => _sortedMediaItems.Count;
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ public class ShuffleInOrderCollectionEnumerator : IMediaCollectionEnumerator
|
||||
{
|
||||
private readonly CancellationToken _cancellationToken;
|
||||
private readonly IList<CollectionWithItems> _collections;
|
||||
private readonly Lazy<Option<TimeSpan>> _lazyMinimumDuration;
|
||||
private readonly int _mediaItemCount;
|
||||
private readonly bool _randomStartPoint;
|
||||
private Random _random;
|
||||
private IList<MediaItem> _shuffled;
|
||||
private readonly Lazy<Option<TimeSpan>> _lazyMinimumDuration;
|
||||
|
||||
public ShuffleInOrderCollectionEnumerator(
|
||||
IList<CollectionWithItems> collections,
|
||||
@@ -82,6 +82,10 @@ public class ShuffleInOrderCollectionEnumerator : IMediaCollectionEnumerator
|
||||
State.Index %= _shuffled.Count;
|
||||
}
|
||||
|
||||
public Option<TimeSpan> MinimumDuration => _lazyMinimumDuration.Value;
|
||||
|
||||
public int Count => _shuffled.Count;
|
||||
|
||||
private IList<MediaItem> Shuffle(IList<CollectionWithItems> collections, Random random)
|
||||
{
|
||||
// based on https://keyj.emphy.de/balanced-shuffle/
|
||||
@@ -217,8 +221,4 @@ public class ShuffleInOrderCollectionEnumerator : IMediaCollectionEnumerator
|
||||
public int Index { get; set; }
|
||||
public IList<Option<MediaItem>> Items { get; set; }
|
||||
}
|
||||
|
||||
public Option<TimeSpan> MinimumDuration => _lazyMinimumDuration.Value;
|
||||
|
||||
public int Count => _shuffled.Count;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace ErsatzTV.Core.Scheduling;
|
||||
public class ShuffledMediaCollectionEnumerator : IMediaCollectionEnumerator
|
||||
{
|
||||
private readonly CancellationToken _cancellationToken;
|
||||
private readonly Lazy<Option<TimeSpan>> _lazyMinimumDuration;
|
||||
private readonly int _mediaItemCount;
|
||||
private readonly IList<GroupedMediaItem> _mediaItems;
|
||||
private readonly Lazy<Option<TimeSpan>> _lazyMinimumDuration;
|
||||
private CloneableRandom _random;
|
||||
private IList<MediaItem> _shuffled;
|
||||
|
||||
@@ -79,6 +79,10 @@ public class ShuffledMediaCollectionEnumerator : IMediaCollectionEnumerator
|
||||
State.Index %= _mediaItemCount;
|
||||
}
|
||||
|
||||
public Option<TimeSpan> MinimumDuration => _lazyMinimumDuration.Value;
|
||||
|
||||
public int Count => _shuffled.Count;
|
||||
|
||||
private IList<MediaItem> Shuffle(IEnumerable<GroupedMediaItem> list, CloneableRandom random)
|
||||
{
|
||||
GroupedMediaItem[] copy = list.ToArray();
|
||||
@@ -93,8 +97,4 @@ public class ShuffledMediaCollectionEnumerator : IMediaCollectionEnumerator
|
||||
|
||||
return GroupedMediaItem.FlattenGroups(copy, _mediaItemCount);
|
||||
}
|
||||
|
||||
public Option<TimeSpan> MinimumDuration => _lazyMinimumDuration.Value;
|
||||
|
||||
public int Count => _shuffled.Count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user