Repository: xbmc/xbmc
File: xbmc/filesystem/DiscDirectoryHelper.cpp (C++)

Code before:
                                                 .clips = {},
                                                 .languages = {}};
      if (!m_groups.empty() && m_groups.back().back().playlist == playlist - 1)
        m_groups.back().emplace_back(groupPlaylist);
      else
        m_groups.emplace_back(std::vector{groupPlaylist}); // New group
    }
    m_allGroups = m_groups;

    // See if any groups have at least numEpisode playlists and there are exactly
    // numEpisode playlists remaining and no specials, in which case make a group.
    // Assumption has to be playlists match episodes in ascending order
    std::erase_if(m_groups, [this](const std::vector<CandidatePlaylistInformation>& group)
                  { return group.size() < m_numEpisodes; });
    if (m_groups.empty() && m_numSpecials == 0 && longPlaylists.size() == m_numEpisodes)
    {
      m_groups.clear();
      for (const auto& PlaylistInformation : longPlaylists)
      {
        const auto& [playlist, playlistInformation] = PlaylistInformation;
        CandidatePlaylistInformation groupPlaylist{.playlist = playlist,
                                                   .duration = playlistInformation.duration,
                                                   .clips = {},
                                                   .languages = {}};
        m_groups.emplace_back(1, groupPlaylist);
      }
    }

    if (m_groups.empty())
      CLog::LogF(LOGDEBUG, "No playlist groups found");
    else
      for (const auto& group : m_groups)
        CLog::LogF(LOGDEBUG, "Playlist group found from {} to {}", group.front().playlist,
                   group.back().playlist);
  }
  else
  {
    CLog::LogF(LOGDEBUG, "No group search as single episode or specials only");
  }
}

void CDiscDirectoryHelper::UsePlayAllPlaylistMethod(unsigned int episodeIndex,
                                                    const PlaylistMap& playlists)
{
  CLog::LogF(LOGDEBUG, "Using Play All playlist method");

  // Get the playlist
  const auto& playlistInformation{*m_playAllPlaylists.begin()};
  const unsigned int playAllPlaylist{playlistInformation.playlist};
  CLog::LogF(LOGDEBUG, "Using candidate play all playlist {} duration {}", playAllPlaylist,
             static_cast<int>(playlistInformation.duration.count() / 1000));

Review comment (suggestion):
You can consider using a transform instead of a loop:
```cpp
      std::ranges::transform(
          longPlaylists, std::back_inserter(m_groups),
          [](const auto& PlaylistInformation) -> std::vector<CandidatePlaylistInformation>
          {
            const auto& [playlist, playlistInformation] = PlaylistInformation;
            return {{.playlist = playlist,
                     .duration = playlistInformation.duration,
                     .clips = {},
                     .languages = {}}};
          });
```
But there is definitely not a requirement to do that.

Code after:
                                                 .clips = {},
                                                 .languages = {}};
      if (!m_groups.empty() && m_groups.back().back().playlist == playlist - 1)
        m_groups.back().emplace_back(groupPlaylist);
      else
        m_groups.emplace_back(std::vector{groupPlaylist}); // New group
    }
    m_allGroups = m_groups;

    // See if any groups have at least numEpisode playlists and there are exactly
    // numEpisode playlists remaining and no specials, in which case make a group.
    // Assumption has to be playlists match episodes in ascending order
    std::erase_if(m_groups, [this](const std::vector<CandidatePlaylistInformation>& group)
                  { return group.size() < m_numEpisodes; });
    if (m_groups.empty() && m_numSpecials == 0 && longPlaylists.size() == m_numEpisodes)
    {
      std::ranges::transform(
          longPlaylists, std::back_inserter(m_groups),
          [](const auto& PlaylistInformation) -> std::vector<CandidatePlaylistInformation>
          {
            const auto& [playlist, playlistInformation] = PlaylistInformation;
            return {{.playlist = playlist,
                     .duration = playlistInformation.duration,
                     .clips = {},
                     .languages = {}}};
          });
    }

    if (m_groups.empty())
      CLog::LogF(LOGDEBUG, "No playlist groups found");
    else
      for (const auto& group : m_groups)
        CLog::LogF(LOGDEBUG, "Playlist group found from {} to {}", group.front().playlist,
                   group.back().playlist);
  }
  else
  {
    CLog::LogF(LOGDEBUG, "No group search as single episode or specials only");
  }
}

void CDiscDirectoryHelper::UsePlayAllPlaylistMethod(unsigned int episodeIndex,
                                                    const PlaylistMap& playlists)
{
  CLog::LogF(LOGDEBUG, "Using Play All playlist method");

  // Get the playlist
  const auto& playlistInformation{*m_playAllPlaylists.begin()};
  const unsigned int playAllPlaylist{playlistInformation.playlist};
  CLog::LogF(LOGDEBUG, "Using candidate play all playlist {} duration {}", playAllPlaylist,
             static_cast<int>(playlistInformation.duration.count() / 1000));