diff --git a/src/components/playback/playbackmanager.js b/src/components/playback/playbackmanager.js index 05117fd08d90..05c9147af309 100644 --- a/src/components/playback/playbackmanager.js +++ b/src/components/playback/playbackmanager.js @@ -1848,6 +1848,48 @@ class PlaybackManager { SortBy: options.shuffle ? 'Random' : 'SortName', MediaTypes: 'Audio' }); + } else if (firstItem.Type === 'Series' || firstItem.Type === 'Season') { + const apiClient = ServerConnections.getApiClient(firstItem.ServerId); + promise = apiClient.getEpisodes(firstItem.SeriesId || firstItem.Id, { + IsVirtualUnaired: false, + IsMissing: false, + UserId: apiClient.getCurrentUserId(), + Fields: 'Chapters' + }).then(function (episodesResult) { + let foundItem = false; + const isSeries = firstItem.Type === 'Series'; + const originalResults = episodesResult.Items; + episodesResult.Items = episodesResult.Items.filter(function (e) { + if (foundItem) { + return true; + } + if (!e.UserData.Played && (isSeries || e.SeasonId == firstItem.Id)) { + foundItem = true; + return true; + } + + return false; + }); + + 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.TotalRecordCount = episodesResult.Items.length; + return episodesResult; + }); } else if (firstItem.IsFolder && firstItem.CollectionType === 'homevideos') { promise = getItemsForPlayback(serverId, mergePlaybackQueries({ ParentId: firstItem.Id,