|
|
|
@ -121,6 +121,7 @@ public class PlaylistEnumerator : IMediaCollectionEnumerator |
|
|
|
CollectionEnumeratorState state, |
|
|
|
CollectionEnumeratorState state, |
|
|
|
bool shufflePlaylistItems, |
|
|
|
bool shufflePlaylistItems, |
|
|
|
Option<int> batchSize, |
|
|
|
Option<int> batchSize, |
|
|
|
|
|
|
|
bool randomStartPoint, |
|
|
|
CancellationToken cancellationToken) |
|
|
|
CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var result = new PlaylistEnumerator |
|
|
|
var result = new PlaylistEnumerator |
|
|
|
@ -131,6 +132,10 @@ public class PlaylistEnumerator : IMediaCollectionEnumerator |
|
|
|
_batchSize = batchSize |
|
|
|
_batchSize = batchSize |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// random start points only apply to a fresh build with no saved state
|
|
|
|
|
|
|
|
var random = new Random(state.Seed); |
|
|
|
|
|
|
|
randomStartPoint = randomStartPoint && state.Index == 0; |
|
|
|
|
|
|
|
|
|
|
|
// collections should share enumerators
|
|
|
|
// collections should share enumerators
|
|
|
|
var enumeratorMap = new Dictionary<CollectionKey, IMediaCollectionEnumerator>(); |
|
|
|
var enumeratorMap = new Dictionary<CollectionKey, IMediaCollectionEnumerator>(); |
|
|
|
result._allMediaItemIds = []; |
|
|
|
result._allMediaItemIds = []; |
|
|
|
@ -166,6 +171,11 @@ public class PlaylistEnumerator : IMediaCollectionEnumerator |
|
|
|
switch (playlistItem.PlaybackOrder) |
|
|
|
switch (playlistItem.PlaybackOrder) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case PlaybackOrder.Chronological: |
|
|
|
case PlaybackOrder.Chronological: |
|
|
|
|
|
|
|
if (randomStartPoint) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
initState.Index = random.Next(0, items.Count - 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enumerator = new ChronologicalMediaCollectionEnumerator(items, initState); |
|
|
|
enumerator = new ChronologicalMediaCollectionEnumerator(items, initState); |
|
|
|
break; |
|
|
|
break; |
|
|
|
// TODO: fix multi episode shuffle?
|
|
|
|
// TODO: fix multi episode shuffle?
|
|
|
|
@ -187,18 +197,22 @@ public class PlaylistEnumerator : IMediaCollectionEnumerator |
|
|
|
CollectionKey.ForPlaylistItem(playlistItem), |
|
|
|
CollectionKey.ForPlaylistItem(playlistItem), |
|
|
|
cancellationToken), |
|
|
|
cancellationToken), |
|
|
|
initState, |
|
|
|
initState, |
|
|
|
// TODO: fix this
|
|
|
|
randomStartPoint, |
|
|
|
false, |
|
|
|
|
|
|
|
cancellationToken); |
|
|
|
cancellationToken); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case PlaybackOrder.SeasonEpisode: |
|
|
|
case PlaybackOrder.SeasonEpisode: |
|
|
|
// TODO: check random start point?
|
|
|
|
if (randomStartPoint) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
initState.Index = random.Next(0, items.Count - 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enumerator = new SeasonEpisodeMediaCollectionEnumerator(items, initState); |
|
|
|
enumerator = new SeasonEpisodeMediaCollectionEnumerator(items, initState); |
|
|
|
// season, episode will filter out season 0, so we may get an empty enumerator back
|
|
|
|
// season, episode will filter out season 0, so we may get an empty enumerator back
|
|
|
|
if (enumerator.Count == 0) |
|
|
|
if (enumerator.Count == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
enumerator = null; |
|
|
|
enumerator = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case PlaybackOrder.Random: |
|
|
|
case PlaybackOrder.Random: |
|
|
|
enumerator = new RandomizedMediaCollectionEnumerator(items, initState); |
|
|
|
enumerator = new RandomizedMediaCollectionEnumerator(items, initState); |
|
|
|
|