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

Code before:
  else if (commonPlaylist != playlistsView.end())
  {
    // Found a common playlist, so assume it's that
    const auto& playlistInformation{playlists.at(*commonPlaylist)};
    CLog::LogF(LOGDEBUG, "Single Episode - found using common playlist method");
    CLog::LogF(LOGDEBUG, "Candidate playlist {}", *commonPlaylist);
    m_candidatePlaylists.emplace(
        *commonPlaylist, CandidatePlaylistInformation{.playlist = *commonPlaylist,
                                                      .index = episodeIndex,
                                                      .duration = playlistInformation.duration,
                                                      .clips = playlistInformation.clips,
                                                      .languages = playlistInformation.languages});
  }
}

std::vector<std::vector<CDiscDirectoryHelper::CandidatePlaylistInformation>> CDiscDirectoryHelper::
    GetGroupsWithoutDuplicates(const std::vector<std::vector<CandidatePlaylistInformation>>& groups)
{
  std::vector<std::vector<CandidatePlaylistInformation>> uniqueGroups;
  for (const auto& playlistGroup : groups)
  {
    std::set<int64_t> seenDurations;
    std::vector<CandidatePlaylistInformation> uniqueGroup;
    std::ranges::copy_if(playlistGroup, std::back_inserter(uniqueGroup),
                         CandidatePlaylistInformationNotDuplicate(seenDurations));
    uniqueGroups.emplace_back(std::move(uniqueGroup));
  }
  return uniqueGroups;
}

void CDiscDirectoryHelper::GetPlaylistsFromGroup(
    unsigned int episodeIndex, const std::vector<CandidatePlaylistInformation>& group)
{
  for (unsigned int i = 0; i < m_numEpisodes; ++i)
  {
    if (m_allEpisodes != AllEpisodes::ALL &&
        i != episodeIndex - m_numSpecials) // Specials before episodes in episodesOnDisc
      continue;

    m_candidatePlaylists.emplace(group[i].playlist,
                                 CandidatePlaylistInformation{.playlist = group[i].playlist,
                                                              .index = i + m_numSpecials,
                                                              .duration = group[i].duration,
                                                              .clips = group[i].clips,
                                                              .languages = group[i].languages});
    CLog::LogF(LOGDEBUG, "Candidate playlist {}", group[i].playlist);
  }
}

void CDiscDirectoryHelper::UseGroupMethod(unsigned int episodeIndex,
                                          const std::vector<CVideoInfoTag>& episodesOnDisc)

Review comment (refactor):
```suggestion
    std::ranges::copy_if(playlistGroup, std::back_inserter(uniqueGroups.emplace_back()),
                         CandidatePlaylistInformationNotDuplicate(seenDurations));
```

Code after:
  else if (commonPlaylist != playlistsView.end())
  {
    // Found a common playlist, so assume it's that
    const auto& playlistInformation{playlists.at(*commonPlaylist)};
    CLog::LogF(LOGDEBUG, "Single Episode - found using common playlist method");
    CLog::LogF(LOGDEBUG, "Candidate playlist {}", *commonPlaylist);
    m_candidatePlaylists.emplace(
        *commonPlaylist, CandidatePlaylistInformation{.playlist = *commonPlaylist,
                                                      .index = episodeIndex,
                                                      .duration = playlistInformation.duration,
                                                      .clips = playlistInformation.clips,
                                                      .languages = playlistInformation.languages});
  }
}

std::vector<std::vector<CDiscDirectoryHelper::CandidatePlaylistInformation>> CDiscDirectoryHelper::
    GetGroupsWithoutDuplicates(const std::vector<std::vector<CandidatePlaylistInformation>>& groups)
{
  std::vector<std::vector<CandidatePlaylistInformation>> uniqueGroups;
  for (const auto& playlistGroup : groups)
  {
    std::set<int64_t> seenDurations;
    std::ranges::copy_if(playlistGroup, std::back_inserter(uniqueGroups.emplace_back()),
                         CandidatePlaylistInformationNotDuplicate(seenDurations));
  }
  return uniqueGroups;
}

void CDiscDirectoryHelper::GetPlaylistsFromGroup(
    unsigned int episodeIndex, const std::vector<CandidatePlaylistInformation>& group)
{
  for (unsigned int i = 0; i < m_numEpisodes; ++i)
  {
    if (m_allEpisodes != AllEpisodes::ALL &&
        i != episodeIndex - m_numSpecials) // Specials before episodes in episodesOnDisc
      continue;

    m_candidatePlaylists.emplace(group[i].playlist,
                                 CandidatePlaylistInformation{.playlist = group[i].playlist,
                                                              .index = i + m_numSpecials,
                                                              .duration = group[i].duration,
                                                              .clips = group[i].clips,
                                                              .languages = group[i].languages});
    CLog::LogF(LOGDEBUG, "Candidate playlist {}", group[i].playlist);
  }
}

void CDiscDirectoryHelper::UseGroupMethod(unsigned int episodeIndex,
                                          const std::vector<CVideoInfoTag>& episodesOnDisc)
{
  // Method 2a - More than one episode on disc