From 27984fe0832a024b567a57e8703b459beca7349c Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Wed, 24 Apr 2024 11:53:03 -0400 Subject: [PATCH 1/2] Fix shuffling for shows --- src/components/playback/playbackmanager.js | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/playback/playbackmanager.js b/src/components/playback/playbackmanager.js index eb9d40a83b..67083788c5 100644 --- a/src/components/playback/playbackmanager.js +++ b/src/components/playback/playbackmanager.js @@ -1872,6 +1872,7 @@ class PlaybackManager { promise = apiClient.getEpisodes(firstItem.SeriesId || firstItem.Id, { IsVirtualUnaired: false, IsMissing: false, + SortBy: options.shuffle ? 'Random' : undefined, UserId: apiClient.getCurrentUserId(), Fields: ['Chapters', 'Trickplay'] }).then(function (episodesResult) { @@ -1880,18 +1881,20 @@ class PlaybackManager { let foundItem = false; - episodesResult.Items = episodesResult.Items.filter(function (e) { - if (foundItem) { - return true; - } + if (!options.shuffle) { + episodesResult.Items = episodesResult.Items.filter(function (e) { + if (foundItem) { + return true; + } - if (!e.UserData.Played && (isSeries || e.SeasonId === firstItem.Id)) { - foundItem = true; - return true; - } + if (!e.UserData.Played && (isSeries || e.SeasonId === firstItem.Id)) { + foundItem = true; + return true; + } - return false; - }); + return false; + }); + } if (episodesResult.Items.length === 0) { if (isSeries) { From f71cc8026a04b5c75e635d3a4ff2477c65fea4b3 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Wed, 24 Apr 2024 13:09:33 -0400 Subject: [PATCH 2/2] Include season id in request when retrieving episodes This also fixes shuffling an individual season (broken since at least 10.8.13, probably earlier) --- src/components/playback/playbackmanager.js | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/components/playback/playbackmanager.js b/src/components/playback/playbackmanager.js index 67083788c5..a3e86ac4da 100644 --- a/src/components/playback/playbackmanager.js +++ b/src/components/playback/playbackmanager.js @@ -1868,16 +1868,17 @@ class PlaybackManager { }, queryOptions)); } else if (firstItem.Type === 'Series' || firstItem.Type === 'Season') { const apiClient = ServerConnections.getApiClient(firstItem.ServerId); + const isSeason = firstItem.Type === 'Season'; promise = apiClient.getEpisodes(firstItem.SeriesId || firstItem.Id, { IsVirtualUnaired: false, IsMissing: false, + SeasonId: isSeason ? firstItem.Id : undefined, SortBy: options.shuffle ? 'Random' : undefined, UserId: apiClient.getCurrentUserId(), Fields: ['Chapters', 'Trickplay'] }).then(function (episodesResult) { const originalResults = episodesResult.Items; - const isSeries = firstItem.Type === 'Series'; let foundItem = false; @@ -1887,7 +1888,7 @@ class PlaybackManager { return true; } - if (!e.UserData.Played && (isSeries || e.SeasonId === firstItem.Id)) { + if (!e.UserData.Played) { foundItem = true; return true; } @@ -1897,22 +1898,7 @@ class PlaybackManager { } if (episodesResult.Items.length === 0) { - if (isSeries) { - episodesResult.Items = originalResults; - } else { - episodesResult.Items = originalResults.filter(function (e) { - if (foundItem) { - return true; - } - - if (e.SeasonId === firstItem.Id) { - foundItem = true; - return true; - } - - return false; - }); - } + episodesResult.Items = originalResults; } episodesResult.TotalRecordCount = episodesResult.Items.length;